本文整理汇总了Java中org.eclipse.jdt.core.IJavaElement.getParent方法的典型用法代码示例。如果您正苦于以下问题:Java IJavaElement.getParent方法的具体用法?Java IJavaElement.getParent怎么用?Java IJavaElement.getParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.IJavaElement
的用法示例。
在下文中一共展示了IJavaElement.getParent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setActiveEditor
import org.eclipse.jdt.core.IJavaElement; //导入方法依赖的package包/类
@Override
public void setActiveEditor(IAction action, IEditorPart part) {
if (part != null && part.getEditorInput() instanceof IClassFileEditorInput) {
Set<IPackageFragmentRoot> queue = new LinkedHashSet<>();
try {
IClassFileEditorInput input = (IClassFileEditorInput) part.getEditorInput();
IJavaElement element = input.getClassFile();
while (element.getParent() != null) {
element = element.getParent();
if (element instanceof IPackageFragmentRoot) {
IPackageFragmentRoot fragment = (IPackageFragmentRoot) element;
if (canProcess(fragment)) {
queue.add(fragment);
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
findSources(queue);
}
}
示例2: getNameRange
import org.eclipse.jdt.core.IJavaElement; //导入方法依赖的package包/类
private static ISourceRange getNameRange(IJavaElement element) throws JavaModelException {
ISourceRange nameRange = null;
if (element instanceof IMember) {
IMember member = (IMember) element;
nameRange = member.getNameRange();
if ( (!SourceRange.isAvailable(nameRange))) {
nameRange = member.getSourceRange();
}
} else if (element instanceof ITypeParameter || element instanceof ILocalVariable) {
nameRange = ((ISourceReference) element).getNameRange();
} else if (element instanceof ISourceReference) {
nameRange = ((ISourceReference) element).getSourceRange();
}
if (!SourceRange.isAvailable(nameRange) && element.getParent() != null) {
nameRange = getNameRange(element.getParent());
}
return nameRange;
}
示例3: collectChildren
import org.eclipse.jdt.core.IJavaElement; //导入方法依赖的package包/类
private void collectChildren(ITypeRoot unit, IJavaElement[] elements, ArrayList<SymbolInformation> symbols,
IProgressMonitor monitor)
throws JavaModelException {
for(IJavaElement element : elements ){
if (monitor.isCanceled()) {
return;
}
if(element instanceof IParent){
collectChildren(unit, filter(((IParent) element).getChildren()), symbols, monitor);
}
int type = element.getElementType();
if (type != IJavaElement.TYPE && type != IJavaElement.FIELD && type != IJavaElement.METHOD) {
continue;
}
Location location = JDTUtils.toLocation(element);
if (location != null) {
SymbolInformation si = new SymbolInformation();
String name = JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT);
si.setName(name == null ? element.getElementName() : name);
si.setKind(mapKind(element));
if (element.getParent() != null) {
si.setContainerName(element.getParent().getElementName());
}
location.setUri(ResourceUtils.toClientUri(location.getUri()));
si.setLocation(location);
if (!symbols.contains(si)) {
symbols.add(si);
}
}
}
}