Java Code Examples for org.eclipse.jdt.core.IJavaElement#equals()
The following examples show how to use
org.eclipse.jdt.core.IJavaElement#equals() .
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: ReorgPolicyFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override protected RefactoringStatus verifyDestination(IJavaElement destination) throws JavaModelException { RefactoringStatus superStatus= super.verifyDestination(destination); if (superStatus.hasFatalError()) return superStatus; Object commonParent= new ParentChecker(getResources(), getJavaElements()).getCommonParent(); if (destination.equals(commonParent)) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent); IContainer destinationAsContainer= getDestinationAsContainer(); if (destinationAsContainer != null && (destinationAsContainer.equals(commonParent) || commonParent instanceof IPackageFragmentRoot && destinationAsContainer.equals(((IPackageFragmentRoot) commonParent).getResource()))) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent); IPackageFragment destinationAsPackage= getDestinationAsPackageFragment(); if (destinationAsPackage != null && (destinationAsPackage.equals(commonParent))) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent); if (cannotUpdateReferencesForDestination()) superStatus.addInfo(RefactoringCoreMessages.ReorgPolicyFactory_noJavaUpdates); return superStatus; }
Example 2
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 3
Source File: DefaultJavaFoldingStructureProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private IJavaElementDelta findElement(IJavaElement target, IJavaElementDelta delta) { if (delta == null || target == null) return null; IJavaElement element= delta.getElement(); if (element.getElementType() > IJavaElement.CLASS_FILE) return null; if (target.equals(element)) return delta; IJavaElementDelta[] children= delta.getAffectedChildren(); for (int i= 0; i < children.length; i++) { IJavaElementDelta d= findElement(target, children[i]); if (d != null) return d; } return null; }
Example 4
Source File: BugInfoView.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
private boolean matchInput(IEditorInput input) { if (file != null && (input instanceof IFileEditorInput)) { return file.equals(((IFileEditorInput) input).getFile()); } if (javaElt != null && input != null) { IJavaElement javaElement = JavaUI.getEditorInputJavaElement(input); if (javaElt.equals(javaElement)) { return true; } IJavaElement parent = javaElt.getParent(); while (parent != null && !parent.equals(javaElement)) { parent = parent.getParent(); } if (parent != null && parent.equals(javaElement)) { return true; } } return false; }
Example 5
Source File: ReorgPolicyFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override protected RefactoringStatus verifyDestination(IResource destination) throws JavaModelException { RefactoringStatus superStatus= super.verifyDestination(destination); if (superStatus.hasFatalError()) return superStatus; Object commonParent= getCommonParent(); if (destination.equals(commonParent)) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent); IContainer destinationAsContainer= getDestinationAsContainer(); if (destinationAsContainer != null && destinationAsContainer.equals(commonParent)) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent); IJavaElement destinationContainerAsPackage= getDestinationContainerAsJavaElement(); if (destinationContainerAsPackage != null && destinationContainerAsPackage.equals(commonParent)) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent); if (cannotUpdateReferencesForDestination()) superStatus.addInfo(RefactoringCoreMessages.ReorgPolicyFactory_noJavaUpdates); return superStatus; }
Example 6
Source File: JavaElementContainmentAdapter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean contains(IJavaElement workingSetElement, IJavaElement element, int flags) { if (checkContext(flags) && workingSetElement.equals(element)) { return true; } if (checkIfChild(flags) && workingSetElement.equals(element.getParent())) { return true; } if (checkIfDescendant(flags) && check(workingSetElement, element)) { return true; } if (checkIfAncestor(flags) && check(element, workingSetElement)) { return true; } return false; }
Example 7
Source File: JavaElementUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static boolean isAncestorOf(IJavaElement ancestor, IJavaElement child) { IJavaElement parent= child.getParent(); while (parent != null && !parent.equals(ancestor)) { parent= parent.getParent(); } return parent != null; }
Example 8
Source File: ReorgUtils.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static boolean isParentInWorkspaceOrOnDisk(IPackageFragmentRoot root, IJavaProject javaProject){ if (root == null) return false; IJavaElement rootParent= root.getParent(); if (rootParent == null) return false; if (rootParent.equals(root)) return true; IResource packageResource= ResourceUtil.getResource(root); IResource packageRootResource= ResourceUtil.getResource(javaProject); return isParentInWorkspaceOrOnDisk(packageResource, packageRootResource); }
Example 9
Source File: JavaElementContainmentAdapter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean check(IJavaElement ancestor, IJavaElement descendent) { descendent= descendent.getParent(); while (descendent != null) { if (ancestor.equals(descendent)) return true; descendent= descendent.getParent(); } return false; }
Example 10
Source File: JsniReferenceChangeHelper.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
public boolean resolvesToRefactoredElement(ICompilationUnit cu, IIndexedJavaRef ref) { IJavaElement refactoredElement = jsniReferenceChange.getRefactoringSupport().getNewElement(); if (refactoredElement == null) { return false; } // If we're refactoring a type, then all refs have already been matched by // their fully-qualified type names so we can return now. if (refactoredElement.getElementType() == IJavaElement.TYPE) { return true; } // For method/field renamings, we refactor the Java reference and then try // to resolve the refactored Java reference against the refactored Java // member (this takes care of inherited members, overloaded methods, etc). JsniJavaRef refactoredRef = refactorJavaRef(ref); if (refactoredRef != null) { try { assert (refactoredElement instanceof IMethod || refactoredElement instanceof IField); IJavaProject javaProject = cu.getJavaProject(); IJavaElement refactoredRefElement = refactoredRef.resolveJavaElement(javaProject); return refactoredElement.equals(refactoredRefElement); } catch (UnresolvedJsniJavaRefException e) { // Ignore any unresolved references; it's entirely possible that some // of the name matches we got from the index don't resolve to any // element in the Java Model } } return false; }
Example 11
Source File: JavaElementLinks.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private String getElementName(IJavaElement element, String elementName) { if (element.equals(fElement)) { // linking to the member itself would be a no-op return elementName; } if (elementName.length() == 0) { // anonymous or lambda return elementName; } try { String uri= createURI(JAVADOC_SCHEME, element); return createHeaderLink(uri, elementName); } catch (URISyntaxException e) { JavaPlugin.log(e); return elementName; } }
Example 12
Source File: ParentChecker.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static boolean isDescendantOf(IJavaElement subElement, IJavaElement superElement) { if (subElement.equals(superElement)) { return false; } IJavaElement parent= subElement.getParent(); while(parent != null){ if (parent.equals(superElement)) { return true; } parent= parent.getParent(); } return false; }
Example 13
Source File: JavaStructureDiffViewer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected IJavaElementDelta findJavaElementDelta(IJavaElement unit, IJavaElementDelta delta) { if (delta == null || unit == null) return null; IJavaElement element= delta.getElement(); if (canIgnore(unit, delta.getAffectedChildren())) return null; if (unit.equals(element)) { if (isContentChange(delta)) { return delta; } return null; } if (element.getElementType() > IJavaElement.CLASS_FILE) return null; IJavaElementDelta[] children= delta.getAffectedChildren(); if (children == null || children.length == 0) return null; for (int i= 0; i < children.length; i++) { IJavaElementDelta d= findJavaElementDelta(unit, children[i]); if (d != null) return d; } return null; }
Example 14
Source File: ParentChecker.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private boolean javaElementsHaveCommonParent() { if (fJavaElements.length == 0) { return true; } IJavaElement firstParent= fJavaElements[0].getParent(); Assert.isNotNull(firstParent); //this should never happen for (int i= 1; i < fJavaElements.length; i++) { if (! firstParent.equals(fJavaElements[i].getParent())) { return false; } } return true; }
Example 15
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 16
Source File: ReorgUtils.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static boolean isParentInWorkspaceOrOnDisk(IPackageFragmentRoot root, IJavaProject javaProject){ if (root == null) { return false; } IJavaElement rootParent= root.getParent(); if (rootParent == null) { return false; } if (rootParent.equals(root)) { return true; } IResource packageResource= ResourceUtil.getResource(root); IResource packageRootResource= ResourceUtil.getResource(javaProject); return isParentInWorkspaceOrOnDisk(packageResource, packageRootResource); }
Example 17
Source File: ReorgUtils.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static boolean isParentInWorkspaceOrOnDisk(IPackageFragment pack, IPackageFragmentRoot root){ if (pack == null) { return false; } IJavaElement packParent= pack.getParent(); if (packParent == null) { return false; } if (packParent.equals(root)) { return true; } IResource packageResource= ResourceUtil.getResource(pack); IResource packageRootResource= ResourceUtil.getResource(root); return isParentInWorkspaceOrOnDisk(packageResource, packageRootResource); }
Example 18
Source File: RenameTypeProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override public IJavaElement getRefactoredJavaElement(IJavaElement element) { if (element instanceof ICompilationUnit) { if (Checks.isTopLevel(fType) && element.equals(fType.getCompilationUnit())) { return getNewCompilationUnit(); } } else if (element instanceof IMember) { final IType newType = (IType) getNewElement(); final RefactoringHandleTransplanter transplanter = new RefactoringHandleTransplanter(fType, newType, fFinalSimilarElementToName); return transplanter.transplantHandle((IMember) element); } return element; }
Example 19
Source File: ElementCache.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
protected void resetSpaceLimit(int defaultLimit, IJavaElement parent) { if (parent.equals(this.spaceLimitParent)) { setSpaceLimit(defaultLimit); this.spaceLimitParent = null; } }
Example 20
Source File: JavaQueryParticipant.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 4 votes |
private Set<IIndexedJavaRef> findMatches(ElementQuerySpecification query, boolean resolveMatches) { IJavaElement javaElement = query.getElement(); JavaRefIndex index = JavaRefIndex.getInstance(); int elementType = javaElement.getElementType(); // Type matches are easy: just compare the fully-qualified type name, and if // they are equal, then we have a match if (elementType == IJavaElement.TYPE) { String typeName = ((IType) javaElement).getFullyQualifiedName(); return index.findTypeReferences(typeName); } // Besides types, we only support searching for fields and methods if (elementType != IJavaElement.FIELD && elementType != IJavaElement.METHOD) { return Collections.emptySet(); } // Get the type that actually declares this member (could be a super type) IType declType = ((IMember) javaElement).getDeclaringType(); assert (declType != null && declType.exists()); // Search the index for matches based only on the member name and type Set<IIndexedJavaRef> nameMatches = (elementType == IJavaElement.METHOD) ? index.findMethodReferences(javaElement.getElementName()) : index.findFieldReferences(javaElement.getElementName()); // We optionally return the full set of "potential" matches (i.e., index // entries that match by name but may not resolve to the query element) if (!resolveMatches) { return nameMatches; } Set<IIndexedJavaRef> matches = new HashSet<IIndexedJavaRef>(); for (IIndexedJavaRef nameMatch : nameMatches) { /* * Try to resolve each potential match to see if it actually references * the target Java element. This takes care of matching the method * parameter lists, as well as correctly searching for a super type's * members from a reference to one of its subclasses. */ IJavaElement matchElement = nameMatch.resolve(); if (javaElement.equals(matchElement)) { matches.add(nameMatch); } } return matches; }