本文整理汇总了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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}