当前位置: 首页>>代码示例>>Java>>正文


Java IJavaElement.getAncestor方法代码示例

本文整理汇总了Java中org.eclipse.jdt.core.IJavaElement.getAncestor方法的典型用法代码示例。如果您正苦于以下问题:Java IJavaElement.getAncestor方法的具体用法?Java IJavaElement.getAncestor怎么用?Java IJavaElement.getAncestor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.core.IJavaElement的用法示例。


在下文中一共展示了IJavaElement.getAncestor方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resolveClassFile

import org.eclipse.jdt.core.IJavaElement; //导入方法依赖的package包/类
private static IClassFile resolveClassFile(String uriString) {
    if (uriString == null || uriString.isEmpty()) {
        return null;
    }
    try {
        URI uri = new URI(uriString);
        if (uri != null && JDT_SCHEME.equals(uri.getScheme()) && "contents".equals(uri.getAuthority())) {
            String handleId = uri.getQuery();
            IJavaElement element = JavaCore.create(handleId);
            IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE);
            return cf;
        }
    } catch (URISyntaxException e) {
        // ignore
    }
    return null;
}
 
开发者ID:Microsoft,项目名称:java-debug,代码行数:18,代码来源:JdtSourceLookUpProvider.java

示例2: acceptPotentialMethodDeclaration

import org.eclipse.jdt.core.IJavaElement; //导入方法依赖的package包/类
private void acceptPotentialMethodDeclaration(CompletionProposal proposal) {
	try {
		IJavaElement enclosingElement = null;
		if (response.getContext().isExtended()) {
			enclosingElement = response.getContext().getEnclosingElement();
		} else if (unit != null) {
			// kept for backward compatibility: CU is not reconciled at this moment, information is missing (bug 70005)
			enclosingElement = unit.getElementAt(proposal.getCompletionLocation() + 1);
		}
		if (enclosingElement == null) {
			return;
		}
		IType type = (IType) enclosingElement.getAncestor(IJavaElement.TYPE);
		if (type != null) {
			String prefix = String.valueOf(proposal.getName());
			int completionStart = proposal.getReplaceStart();
			int completionEnd = proposal.getReplaceEnd();
			int relevance = proposal.getRelevance() + 6;

			GetterSetterCompletionProposal.evaluateProposals(type, prefix, completionStart, completionEnd - completionStart, relevance, proposals);
		}
	} catch (CoreException e) {
		JavaLanguageServerPlugin.logException("Accept potential method declaration failed for completion ", e);
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:26,代码来源:CompletionProposalRequestor.java

示例3: toLocation

import org.eclipse.jdt.core.IJavaElement; //导入方法依赖的package包/类
/**
 * Creates a location for a given java element.
 * Element can be a {@link ICompilationUnit} or {@link IClassFile}
 *
 * @param element
 * @return location or null
 * @throws JavaModelException
 */
public static Location toLocation(IJavaElement element) throws JavaModelException{
	ICompilationUnit unit = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT);
	IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE);
	if (unit == null && cf == null) {
		return null;
	}
	if (element instanceof ISourceReference) {
		ISourceRange nameRange = getNameRange(element);
		if (SourceRange.isAvailable(nameRange)) {
			if (cf == null) {
				return toLocation(unit, nameRange.getOffset(), nameRange.getLength());
			} else {
				return toLocation(cf, nameRange.getOffset(), nameRange.getLength());
			}
		}
	}
	return null;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:27,代码来源:JDTUtils.java

示例4: computeDefinitionNavigation

import org.eclipse.jdt.core.IJavaElement; //导入方法依赖的package包/类
private Location computeDefinitionNavigation(ITypeRoot unit, int line, int column, IProgressMonitor monitor) {
	try {
		IJavaElement element = JDTUtils.findElementAtSelection(unit, line, column, this.preferenceManager, monitor);
		if (element == null) {
			return null;
		}
		ICompilationUnit compilationUnit = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT);
		IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE);
		if (compilationUnit != null || (cf != null && cf.getSourceRange() != null)  ) {
			return JDTUtils.toLocation(element);
		}
		if (element instanceof IMember && ((IMember) element).getClassFile() != null) {
			return JDTUtils.toLocation(((IMember) element).getClassFile());
		}
	} catch (JavaModelException e) {
		JavaLanguageServerPlugin.logException("Problem computing definition for" +  unit.getElementName(), e);
	}
	return null;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:20,代码来源:NavigateToDefinitionHandler.java

示例5: resolveClassFile

import org.eclipse.jdt.core.IJavaElement; //导入方法依赖的package包/类
/**
 * Given the uri returns a {@link IClassFile}.
 * May return null if it can not resolve the uri to a
 * library.
 *
 * @see #toLocation(IClassFile, int, int)
 * @param uri with 'jdt' scheme
 * @return class file
 */
public static IClassFile resolveClassFile(URI uri){
	if (uri != null && JDT_SCHEME.equals(uri.getScheme()) && "contents".equals(uri.getAuthority())) {
		String handleId = uri.getQuery();
		IJavaElement element = JavaCore.create(handleId);
		IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE);
		return cf;
	}
	return null;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:19,代码来源:JDTUtils.java


注:本文中的org.eclipse.jdt.core.IJavaElement.getAncestor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。