當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。