Java Code Examples for org.eclipse.jdt.core.IType#equals()
The following examples show how to use
org.eclipse.jdt.core.IType#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: JavaModelUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public static boolean isSuperType(ITypeHierarchy hierarchy, IType possibleSuperType, IType type) { // filed bug 112635 to add this method to ITypeHierarchy IType superClass= hierarchy.getSuperclass(type); if (superClass != null && (possibleSuperType.equals(superClass) || isSuperType(hierarchy, possibleSuperType, superClass))) { return true; } if (Flags.isInterface(hierarchy.getCachedFlags(possibleSuperType))) { IType[] superInterfaces= hierarchy.getSuperInterfaces(type); for (int i= 0; i < superInterfaces.length; i++) { IType curr= superInterfaces[i]; if (possibleSuperType.equals(curr) || isSuperType(hierarchy, possibleSuperType, curr)) { return true; } } } return false; }
Example 2
Source File: RenameMethodProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static IMethod[] classesDeclareMethodName(ITypeHierarchy hier, List<IType> classes, IMethod method, String newName) throws CoreException { Set<IMethod> result= new HashSet<IMethod>(); IType type= method.getDeclaringType(); List<IType> subtypes= Arrays.asList(hier.getAllSubtypes(type)); int parameterCount= method.getParameterTypes().length; boolean isMethodPrivate= JdtFlags.isPrivate(method); for (Iterator<IType> iter= classes.iterator(); iter.hasNext(); ){ IType clazz= iter.next(); IMethod[] methods= clazz.getMethods(); boolean isSubclass= subtypes.contains(clazz); for (int j= 0; j < methods.length; j++) { IMethod foundMethod= Checks.findMethod(newName, parameterCount, false, new IMethod[] {methods[j]}); if (foundMethod == null) continue; if (isSubclass || type.equals(clazz)) result.add(foundMethod); else if ((! isMethodPrivate) && (! JdtFlags.isPrivate(methods[j]))) result.add(foundMethod); } } return result.toArray(new IMethod[result.size()]); }
Example 3
Source File: LazyGenericTypeProposal.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Computes one inheritance path from <code>superType</code> to <code>subType</code> or * <code>null</code> if <code>subType</code> does not inherit from <code>superType</code>. Note * that there may be more than one inheritance path - this method simply returns one. * <p> * The returned array contains <code>superType</code> at its first index, and * <code>subType</code> at its last index. If <code>subType</code> equals <code>superType</code> * , an array of length 1 is returned containing that type. * </p> * * @param subType the sub type * @param superType the super type * @return an inheritance path from <code>superType</code> to <code>subType</code>, or * <code>null</code> if <code>subType</code> does not inherit from * <code>superType</code> * @throws JavaModelException if this element does not exist or if an exception occurs while * accessing its corresponding resource */ private IType[] computeInheritancePath(IType subType, IType superType) throws JavaModelException { if (superType == null) return null; // optimization: avoid building the type hierarchy for the identity case if (superType.equals(subType)) return new IType[] { subType }; ITypeHierarchy hierarchy= subType.newSupertypeHierarchy(getProgressMonitor()); if (!hierarchy.contains(superType)) return null; // no path List<IType> path= new LinkedList<IType>(); path.add(superType); do { // any sub type must be on a hierarchy chain from superType to subType superType= hierarchy.getSubtypes(superType)[0]; path.add(superType); } while (!superType.equals(subType)); // since the equality case is handled above, we can spare one check return path.toArray(new IType[path.size()]); }
Example 4
Source File: RippleMethodFinder2.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
public IType find(IType element) { IType root= element; IType rep= fElementToRepresentative.get(root); while (rep != null && ! rep.equals(root)) { root= rep; rep= fElementToRepresentative.get(root); } if (rep == null) { return null; } rep= fElementToRepresentative.get(element); while (! rep.equals(root)) { IType temp= element; element= rep; fElementToRepresentative.put(temp, root); rep= fElementToRepresentative.get(element); } return root; }
Example 5
Source File: RippleMethodFinder2.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public IType find(IType element) { IType root= element; IType rep= fElementToRepresentative.get(root); while (rep != null && ! rep.equals(root)) { root= rep; rep= fElementToRepresentative.get(root); } if (rep == null) return null; rep= fElementToRepresentative.get(element); while (! rep.equals(root)) { IType temp= element; element= rep; fElementToRepresentative.put(temp, root); rep= fElementToRepresentative.get(element); } return root; }
Example 6
Source File: TypeProposalUtils.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
static IType[] computeInheritancePath(IType subType, IType superType) throws JavaModelException { if (superType == null) { return null; } // optimization: avoid building the type hierarchy for the identity case if (superType.equals(subType)) { return new IType[] { subType }; } ITypeHierarchy hierarchy= subType.newSupertypeHierarchy(new NullProgressMonitor()); if (!hierarchy.contains(superType)) { return null; // no path } List<IType> path= new LinkedList<>(); path.add(superType); do { // any sub type must be on a hierarchy chain from superType to subType superType= hierarchy.getSubtypes(superType)[0]; path.add(superType); } while (!superType.equals(subType)); // since the equality case is handled above, we can spare one check return path.toArray(new IType[path.size()]); }
Example 7
Source File: RenameVirtualMethodProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private ITypeHierarchy getCachedHierarchy(IType declaring, IProgressMonitor monitor) throws JavaModelException { if (fCachedHierarchy != null && declaring.equals(fCachedHierarchy.getType())) { return fCachedHierarchy; } fCachedHierarchy= declaring.newTypeHierarchy(new SubProgressMonitor(monitor, 1)); return fCachedHierarchy; }
Example 8
Source File: RefactoringAvailabilityTester.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static boolean isCommonDeclaringType(final IMember[] members) { if (members.length == 0) return false; final IType type= members[0].getDeclaringType(); if (type == null) return false; for (int index= 0; index < members.length; index++) { if (!type.equals(members[index].getDeclaringType())) return false; } return true; }
Example 9
Source File: PullUpMethodPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void checkAllParents(final IType parent) { final ITypeHierarchy th= getTreeInput(); final IType root= getTreeInput().getType(); IType type= parent; while (!root.equals(type)) { fTreeViewer.setChecked(type, true); type= th.getSuperclass(type); } fTreeViewer.setChecked(root, true); }
Example 10
Source File: JavaOutlineInformationControl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} */ @Override public Object[] getChildren(Object element) { if (fShowOnlyMainType) { if (element instanceof ITypeRoot) { element= ((ITypeRoot)element).findPrimaryType(); } if (element == null) return NO_CHILDREN; } if (fShowInheritedMembers && element instanceof IType) { IType type= (IType)element; if (type.getDeclaringType() == null || type.equals(fInitiallySelectedType)) { ITypeHierarchy th= getSuperTypeHierarchy(type); if (th != null) { List<Object> children= new ArrayList<Object>(); IType[] superClasses= th.getAllSupertypes(type); children.addAll(Arrays.asList(super.getChildren(type))); for (int i= 0, scLength= superClasses.length; i < scLength; i++) children.addAll(Arrays.asList(super.getChildren(superClasses[i]))); return children.toArray(); } } } return super.getChildren(element); }
Example 11
Source File: TypeHierarchyContentProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean hasMemberFilterChildren(IType type) throws JavaModelException { for (int i= 0; i < fMemberFilter.length; i++) { IMember member= fMemberFilter[i]; if (type.equals(member.getDeclaringType())) { return true; } else if (member instanceof IMethod) { if (hasCompatibleMethod((IMethod) member, type)) { return true; } } } return false; }
Example 12
Source File: PullUpRefactoringProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override protected boolean canBeAccessedFrom(final IMember member, final IType target, final ITypeHierarchy hierarchy) throws JavaModelException { if (super.canBeAccessedFrom(member, target, hierarchy)) { if (target.isInterface()) return true; if (target.equals(member.getDeclaringType())) return true; if (target.equals(member)) return true; if (member instanceof IMethod) { final IMethod method= (IMethod) member; final IMethod stub= target.getMethod(method.getElementName(), method.getParameterTypes()); if (stub.exists()) return true; } if (member.getDeclaringType() == null) { if (!(member instanceof IType)) return false; if (JdtFlags.isPublic(member)) return true; if (!JdtFlags.isPackageVisible(member)) return false; if (JavaModelUtil.isSamePackage(((IType) member).getPackageFragment(), target.getPackageFragment())) return true; final IType type= member.getDeclaringType(); if (type != null) return hierarchy.contains(type); return false; } final IType declaringType= member.getDeclaringType(); if (!canBeAccessedFrom(declaringType, target, hierarchy)) return false; if (declaringType.equals(getDeclaringType())) return false; return true; } return false; }
Example 13
Source File: MemberVisibilityAdjustor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns the visibility threshold from a type to a method. * * @param referencing the referencing type * @param referenced the referenced method * @param monitor the progress monitor to use * @return the visibility keyword corresponding to the threshold, or <code>null</code> for default visibility * @throws JavaModelException if the java elements could not be accessed */ private ModifierKeyword thresholdTypeToMethod(final IType referencing, final IMethod referenced, final IProgressMonitor monitor) throws JavaModelException { final ICompilationUnit referencedUnit= referenced.getCompilationUnit(); ModifierKeyword keyword= ModifierKeyword.PUBLIC_KEYWORD; if (referenced.getDeclaringType().equals(referencing)) keyword= ModifierKeyword.PRIVATE_KEYWORD; else { final ITypeHierarchy hierarchy= getTypeHierarchy(referencing, new SubProgressMonitor(monitor, 1)); final IType[] types= hierarchy.getSupertypes(referencing); IType superType= null; for (int index= 0; index < types.length; index++) { superType= types[index]; if (superType.equals(referenced.getDeclaringType())) { keyword= ModifierKeyword.PROTECTED_KEYWORD; return keyword; } } } final ICompilationUnit typeUnit= referencing.getCompilationUnit(); if (referencedUnit != null && referencedUnit.equals(typeUnit)) { if (referenced.getDeclaringType().getDeclaringType() != null) keyword= null; else keyword= ModifierKeyword.PRIVATE_KEYWORD; } else if (referencedUnit != null && referencedUnit.getParent().equals(typeUnit.getParent())) keyword= null; return keyword; }
Example 14
Source File: MemberVisibilityAdjustor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns the visibility threshold from a type to another type. * * @param referencing the referencing type * @param referenced the referenced type * @param monitor the progress monitor to use * @return the visibility keyword corresponding to the threshold, or <code>null</code> for default visibility * @throws JavaModelException if the java elements could not be accessed */ private ModifierKeyword thresholdTypeToType(final IType referencing, final IType referenced, final IProgressMonitor monitor) throws JavaModelException { ModifierKeyword keyword= ModifierKeyword.PUBLIC_KEYWORD; final ICompilationUnit referencedUnit= referenced.getCompilationUnit(); if (referencing.equals(referenced.getDeclaringType())) keyword= ModifierKeyword.PRIVATE_KEYWORD; else { final ITypeHierarchy hierarchy= getTypeHierarchy(referencing, new SubProgressMonitor(monitor, 1)); final IType[] types= hierarchy.getSupertypes(referencing); IType superType= null; for (int index= 0; index < types.length; index++) { superType= types[index]; if (superType.equals(referenced)) { keyword= null; return keyword; } } } final ICompilationUnit typeUnit= referencing.getCompilationUnit(); if (referencedUnit != null && referencedUnit.equals(typeUnit)) { if (referenced.getDeclaringType() != null) keyword= null; else keyword= ModifierKeyword.PRIVATE_KEYWORD; } else if (referencedUnit != null && typeUnit != null && referencedUnit.getParent().equals(typeUnit.getParent())) keyword= null; return keyword; }
Example 15
Source File: JavaElementUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private static boolean isPrimaryType(IType type){ return type.equals(type.getCompilationUnit().findPrimaryType()); }
Example 16
Source File: PullUpRefactoringProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private boolean isRequiredPullableMember(final List<IMember> queue, final IMember member) throws JavaModelException { final IType declaring= member.getDeclaringType(); if (declaring == null) // not a member return false; return declaring.equals(getDeclaringType()) && !queue.contains(member) && RefactoringAvailabilityTester.isPullUpAvailable(member); }
Example 17
Source File: TypeVector.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public boolean contains(IType element) { for (int i = this.size; --i >= 0;) if (element.equals(this.elements[i])) return true; return false; }
Example 18
Source File: ChangeCollector.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private void addTypeChange(IType type, int newFlags, SimpleDelta existingDelta) throws JavaModelException { if (existingDelta != null) { switch (existingDelta.getKind()) { case IJavaElementDelta.CHANGED: // CHANGED then CHANGED int existingFlags = existingDelta.getFlags(); boolean hasChange = false; if ((existingFlags & IJavaElementDelta.F_SUPER_TYPES) != 0 && hasSuperTypeChange(type)) { existingDelta.superTypes(); hasChange = true; } if ((existingFlags & IJavaElementDelta.F_MODIFIERS) != 0 && hasVisibilityChange(type)) { existingDelta.modifiers(); hasChange = true; } if (!hasChange) { // super types and visibility are back to the ones in the existing hierarchy this.changes.remove(type); } break; // ADDED then CHANGED: leave it as ADDED // REMOVED then CHANGED: should not happen } } else { // check whether the type change affects the hierarchy SimpleDelta typeDelta = null; if ((newFlags & IJavaElementDelta.F_SUPER_TYPES) != 0 && this.hierarchy.includesTypeOrSupertype(type)) { typeDelta = new SimpleDelta(); typeDelta.superTypes(); } if ((newFlags & IJavaElementDelta.F_MODIFIERS) != 0 && (this.hierarchy.hasSupertype(type.getElementName()) || type.equals(this.hierarchy.focusType))) { if (typeDelta == null) { typeDelta = new SimpleDelta(); } typeDelta.modifiers(); } if (typeDelta != null) { this.changes.put(type, typeDelta); } } }
Example 19
Source File: RefactoringHandleTransplanter.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
private String resolveTypeName(IType type) { return type.equals(fOldType) ? fNewType.getElementName() : type.getElementName(); }
Example 20
Source File: JavaElementUtil.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
private static boolean isPrimaryType(IType type){ return type.equals(type.getCompilationUnit().findPrimaryType()); }