org.eclipse.jdt.core.IParent Java Examples
The following examples show how to use
org.eclipse.jdt.core.IParent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavaElementDeltaBuilder.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Fills the newPositions hashtable with the new position information */ private void recordNewPositions(IJavaElement newElement, int depth) { if (depth < this.maxDepth && newElement instanceof IParent) { JavaElementInfo info = null; try { info = (JavaElementInfo)((JavaElement)newElement).getElementInfo(); } catch (JavaModelException npe) { return; } IJavaElement[] children = info.getChildren(); if (children != null) { insertPositions(children, true); for(int i = 0, length = children.length; i < length; i++) { recordNewPositions(children[i], depth + 1); } } } }
Example #2
Source File: MarkerUtil.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
private static int findInnerClassSourceLine(IJavaElement type, String name) throws JavaModelException { String elemName = type.getElementName(); if (name.equals(elemName)) { if (type instanceof IType) { return getLineStart((IType) type); } } if (type instanceof IParent) { IJavaElement[] children = ((IParent) type).getChildren(); for (int i = 0; i < children.length; i++) { // recursive call int line = findInnerClassSourceLine(children[i], name); if (line > 0) { return line; } } } return DONT_KNOW_LINE; }
Example #3
Source File: NLSSearchResult.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void collectMatches(Set<Match> matches, IJavaElement element) { //TODO: copied from JavaSearchResult: Match[] m= getMatches(element); if (m.length != 0) { for (int i= 0; i < m.length; i++) { matches.add(m[i]); } } if (element instanceof IParent) { IParent parent= (IParent) element; try { IJavaElement[] children= parent.getChildren(); for (int i= 0; i < children.length; i++) { collectMatches(matches, children[i]); } } catch (JavaModelException e) { // we will not be tracking these results } } }
Example #4
Source File: JavaElementDeltaBuilder.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Looks for changed positioning of elements. */ private void findChangesInPositioning(IJavaElement element, int depth) { if (depth >= this.maxDepth || this.added.contains(element) || this.removed.contains(element)) return; if (!isPositionedCorrectly(element)) { this.delta.changed(element, IJavaElementDelta.F_REORDER); } if (element instanceof IParent) { JavaElementInfo info = null; try { info = (JavaElementInfo)((JavaElement)element).getElementInfo(); } catch (JavaModelException npe) { return; } IJavaElement[] children = info.getChildren(); if (children != null) { int length = children.length; for(int i = 0; i < length; i++) { findChangesInPositioning(children[i], depth + 1); } } } }
Example #5
Source File: Region.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Removes any children of this element that are contained within this * region as this parent is about to be added to the region. * * <p>Children are all children, not just direct children. */ protected void removeAllChildren(IJavaElement element) { if (element instanceof IParent) { ArrayList newRootElements = new ArrayList(); for (int i = 0, size = this.rootElements.size(); i < size; i++) { IJavaElement currentRoot = (IJavaElement)this.rootElements.get(i); //walk the current root hierarchy IJavaElement parent = currentRoot.getParent(); boolean isChild= false; while (parent != null) { if (parent.equals(element)) { isChild= true; break; } parent = parent.getParent(); } if (!isChild) { newRootElements.add(currentRoot); } } this.rootElements= newRootElements; } }
Example #6
Source File: JavaBrowsingContentProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private Object[] getChildren(IType type) throws JavaModelException{ IParent parent; if (type.isBinary()) parent= type.getClassFile(); else { parent= type.getCompilationUnit(); } if (type.getDeclaringType() != null) return type.getChildren(); // Add import declarations IJavaElement[] members= parent.getChildren(); ArrayList<IJavaElement> tempResult= new ArrayList<IJavaElement>(members.length); for (int i= 0; i < members.length; i++) if ((members[i] instanceof IImportContainer)) tempResult.add(members[i]); tempResult.addAll(Arrays.asList(type.getChildren())); return tempResult.toArray(); }
Example #7
Source File: AbstractJavaSearchResult.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void collectMatches(Set<Match> matches, IJavaElement element) { Match[] m= getMatches(element); if (m.length != 0) { for (int i= 0; i < m.length; i++) { matches.add(m[i]); } } if (element instanceof IParent) { IParent parent= (IParent) element; try { IJavaElement[] children= parent.getChildren(); for (int i= 0; i < children.length; i++) { collectMatches(matches, children[i]); } } catch (JavaModelException e) { // we will not be tracking these results } } }
Example #8
Source File: JavaOutlinePage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public Object[] getChildren(Object parent) { if (parent instanceof IParent) { IParent c= (IParent) parent; try { return filter(c.getChildren()); } catch (JavaModelException x) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=38341 // don't log NotExist exceptions as this is a valid case // since we might have been posted and the element // removed in the meantime. if (JavaPlugin.isDebug() || !x.isDoesNotExist()) JavaPlugin.log(x); } } return NO_CHILDREN; }
Example #9
Source File: JavaOutlinePage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public boolean hasChildren(Object parent) { if (parent instanceof IParent) { IParent c= (IParent) parent; try { IJavaElement[] children= filter(c.getChildren()); return (children != null && children.length > 0); } catch (JavaModelException x) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=38341 // don't log NotExist exceptions as this is a valid case // since we might have been posted and the element // removed in the meantime. if (JavaPlugin.isDebug() || !x.isDoesNotExist()) JavaPlugin.log(x); } } return false; }
Example #10
Source File: JavaWorkbenchAdapter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public Object[] getChildren(Object element) { IJavaElement je= getJavaElement(element); if (je instanceof IParent) { try { return ((IParent)je).getChildren(); } catch(JavaModelException e) { JavaPlugin.log(e); } } return NO_CHILDREN; }
Example #11
Source File: JavaElementDeltaBuilder.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Records this elements info, and attempts * to record the info for the children. */ private void recordElementInfo(IJavaElement element, JavaModel model, int depth) { if (depth >= this.maxDepth) { return; } JavaElementInfo info = (JavaElementInfo)JavaModelManager.getJavaModelManager().getInfo(element); if (info == null) // no longer in the java model. return; this.infos.put(element, info); if (element instanceof IParent) { IJavaElement[] children = info.getChildren(); if (children != null) { insertPositions(children, false); for(int i = 0, length = children.length; i < length; i++) recordElementInfo(children[i], model, depth + 1); } } IAnnotation[] annotations = null; if (info instanceof AnnotatableInfo) annotations = ((AnnotatableInfo) info).annotations; if (annotations != null) { if (this.annotationInfos == null) this.annotationInfos = new HashMap(); JavaModelManager manager = JavaModelManager.getJavaModelManager(); for (int i = 0, length = annotations.length; i < length; i++) { this.annotationInfos.put(annotations[i], manager.getInfo(annotations[i])); } } }
Example #12
Source File: JavaElementDeltaBuilder.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Finds elements which have been added or changed. */ private void findAdditions(IJavaElement newElement, int depth) { JavaElementInfo oldInfo = getElementInfo(newElement); if (oldInfo == null && depth < this.maxDepth) { this.delta.added(newElement); added(newElement); } else { removeElementInfo(newElement); } if (depth >= this.maxDepth) { // mark element as changed this.delta.changed(newElement, IJavaElementDelta.F_CONTENT); return; } JavaElementInfo newInfo = null; try { newInfo = (JavaElementInfo)((JavaElement)newElement).getElementInfo(); } catch (JavaModelException npe) { return; } findContentChange(oldInfo, newInfo, newElement); if (oldInfo != null && newElement instanceof IParent) { IJavaElement[] children = newInfo.getChildren(); if (children != null) { int length = children.length; for(int i = 0; i < length; i++) { findAdditions(children[i], depth + 1); } } } }
Example #13
Source File: CopyElementsOperation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns the anchor used for positioning in the destination for * the element being renamed. For renaming, if no anchor has * explicitly been provided, the element is anchored in the same position. */ private IJavaElement resolveRenameAnchor(IJavaElement element) throws JavaModelException { IParent parent = (IParent) element.getParent(); IJavaElement[] children = parent.getChildren(); for (int i = 0; i < children.length; i++) { IJavaElement child = children[i]; if (child.equals(element)) { return child; } } return null; }
Example #14
Source File: JavaBrowsingContentProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public Object[] getChildren(Object element) { if (!exists(element)) return NO_CHILDREN; startReadInDisplayThread(); try { if (element instanceof Collection) { Collection<?> elements= (Collection<?>)element; if (elements.isEmpty()) return NO_CHILDREN; Object[] result= new Object[0]; Iterator<?> iter= ((Collection<?>)element).iterator(); while (iter.hasNext()) { Object[] children= getChildren(iter.next()); if (children != NO_CHILDREN) result= concatenate(result, children); } return result; } if (element instanceof IPackageFragment) return getPackageContents((IPackageFragment)element); if (fProvideMembers && element instanceof IType) return getChildren((IType)element); if (fProvideMembers && element instanceof ISourceReference && element instanceof IParent) return removeImportAndPackageDeclarations(super.getChildren(element)); if (element instanceof IJavaProject) return getPackageFragmentRoots((IJavaProject)element); return super.getChildren(element); } catch (JavaModelException e) { return NO_CHILDREN; } finally { finishedReadInDisplayThread(); } }
Example #15
Source File: AbstractInformationControl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean hasUnfilteredChild(TreeViewer viewer, Object element) { if (element instanceof IParent) { Object[] children= ((ITreeContentProvider) viewer.getContentProvider()).getChildren(element); for (int i= 0; i < children.length; i++) if (select(viewer, element, children[i])) return true; } return false; }
Example #16
Source File: MultiSortMembersAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean hasMembersToSort(IJavaElement[] members) throws JavaModelException { if (members.length > 1) return true; if (members.length == 0) return false; IJavaElement elem= members[0]; if (!(elem instanceof IParent)) return false; return hasMembersToSort(((IParent)elem).getChildren()); }
Example #17
Source File: DocumentSymbolHandler.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private void collectChildren(ITypeRoot unit, IJavaElement[] elements, ArrayList<SymbolInformation> symbols, IProgressMonitor monitor) throws JavaModelException { for (IJavaElement element : elements) { if (monitor.isCanceled()) { throw new OperationCanceledException(); } 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); } } } }
Example #18
Source File: DefaultJavaFoldingStructureProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void computeFoldingStructure(IJavaElement[] elements, FoldingStructureComputationContext ctx) throws JavaModelException { for (int i= 0; i < elements.length; i++) { IJavaElement element= elements[i]; computeFoldingStructure(element, ctx); if (element instanceof IParent) { IParent parent= (IParent) element; computeFoldingStructure(parent.getChildren(), ctx); } } }
Example #19
Source File: DefaultJavaFoldingStructureProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void computeFoldingStructure(FoldingStructureComputationContext ctx) { IParent parent= (IParent) fInput; try { if (!(fInput instanceof ISourceReference)) return; String source= ((ISourceReference)fInput).getSource(); if (source == null) return; ctx.getScanner().setSource(source.toCharArray()); computeFoldingStructure(parent.getChildren(), ctx); } catch (JavaModelException x) { } }
Example #20
Source File: SortMembersAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean hasMembersToSort(IJavaElement[] members) throws JavaModelException { if (members.length > 1) { return true; } if (members.length == 1) { IJavaElement elem= members[0]; if (elem instanceof IParent) { return hasMembersToSort(((IParent) elem).getChildren()); } } return false; }
Example #21
Source File: StandardJavaElementContentProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public boolean hasChildren(Object element) { if (getProvideMembers()) { // assume CUs and class files are never empty if (element instanceof ICompilationUnit || element instanceof IClassFile) { return true; } } else { // don't allow to drill down into a compilation unit or class file if (element instanceof ICompilationUnit || element instanceof IClassFile || element instanceof IFile) return false; } if (element instanceof IJavaProject) { IJavaProject jp= (IJavaProject)element; if (!jp.getProject().isOpen()) { return false; } } if (element instanceof IParent) { try { // when we have Java children return true, else we fetch all the children if (((IParent)element).hasChildren()) return true; } catch(JavaModelException e) { return true; } } Object[] children= getChildren(element); return (children != null) && children.length > 0; }
Example #22
Source File: StandardJavaElementContentProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public Object[] getChildren(Object element) { if (!exists(element)) return NO_CHILDREN; try { if (element instanceof IJavaModel) return getJavaProjects((IJavaModel)element); if (element instanceof IJavaProject) return getPackageFragmentRoots((IJavaProject)element); if (element instanceof IPackageFragmentRoot) return getPackageFragmentRootContent((IPackageFragmentRoot)element); if (element instanceof IPackageFragment) return getPackageContent((IPackageFragment)element); if (element instanceof IFolder) return getFolderContent((IFolder)element); if (element instanceof IJarEntryResource) { return ((IJarEntryResource) element).getChildren(); } if (getProvideMembers() && element instanceof ISourceReference && element instanceof IParent) { return ((IParent)element).getChildren(); } } catch (CoreException e) { return NO_CHILDREN; } return NO_CHILDREN; }
Example #23
Source File: StubUtility.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns the element after the give element. * * @param member a Java element * @return the next sibling of the given element or <code>null</code> * @throws JavaModelException thrown if the element could not be accessed */ public static IJavaElement findNextSibling(IJavaElement member) throws JavaModelException { IJavaElement parent= member.getParent(); if (parent instanceof IParent) { IJavaElement[] elements= ((IParent)parent).getChildren(); for (int i= elements.length - 2; i >= 0; i--) { if (member.equals(elements[i])) { return elements[i + 1]; } } } return null; }
Example #24
Source File: JdtUtils.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
/** * Traverses down the children tree of this parent and collect all child * anon. classes * * @param list * @param parent * @param allowNested * true to search in IType child elements too * @throws JavaModelException */ private static void collectAllAnonymous(List<IType> list, IParent parent, boolean allowNested) throws JavaModelException { IJavaElement[] children = parent.getChildren(); for (int i = 0; i < children.length; i++) { IJavaElement childElem = children[i]; if (isAnonymousType(childElem)) { list.add((IType) childElem); } if (childElem instanceof IParent) { if (allowNested || !(childElem instanceof IType)) { collectAllAnonymous(list, (IParent) childElem, allowNested); } } } }
Example #25
Source File: DocumentSymbolHandler.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private DocumentSymbol toDocumentSymbol(IJavaElement unit, IProgressMonitor monitor) { int type = unit.getElementType(); if (type != TYPE && type != FIELD && type != METHOD && type != PACKAGE_DECLARATION && type != COMPILATION_UNIT) { return null; } if (monitor.isCanceled()) { throw new OperationCanceledException("User abort"); } DocumentSymbol symbol = new DocumentSymbol(); try { String name = getName(unit); symbol.setName(name); symbol.setRange(getRange(unit)); symbol.setSelectionRange(getSelectionRange(unit)); symbol.setKind(mapKind(unit)); symbol.setDeprecated(isDeprecated(unit)); symbol.setDetail(getDetail(unit, name)); if (unit instanceof IParent) { //@formatter:off IJavaElement[] children = filter(((IParent) unit).getChildren()); symbol.setChildren(Stream.of(children) .map(child -> toDocumentSymbol(child, monitor)) .filter(Objects::nonNull) .collect(Collectors.toList())); //@formatter:off } } catch (JavaModelException e) { Exceptions.sneakyThrow(e); } return symbol; }