@Override public boolean hasChildren(final Object element) { if (!(element instanceof IType)) return false; final IType type= (IType) element; return (fHierarchy.getAllSubtypes(type).length > 0) || fTypeToMemberArray.containsKey(type); }
private void processTypeDelta(IType type, ArrayList<IType> changedTypes) { if (getHierarchy().contains(type)) { changedTypes.add(type); } }
if (class1.equals("java.lang.Object") return true; ITypeHierarchy typeHierarchy = type.newTypeHierarchy(new NullProgressMonitor()); IType[] supertypes = typeHierarchy.getAllSupertypes(type); boolean isSuperType = Arrays.asList(supertypes).stream().anyMatch(supertype -> { return supertype.getFullyQualifiedName().equals(class1); });
private static IType findMostSpecific(Collection<IType> candidates) throws JavaModelException { ITypeHierarchy superHierarchy = null; for (IType t : candidates) { if (superHierarchy == null || !superHierarchy.contains(t)) { superHierarchy = t.newSupertypeHierarchy(null); } } if (superHierarchy == null) { return null; } return superHierarchy.getType(); }
private static Set<IType> computeShowableSubtypesOfMainType(final ITypeHierarchy hierarchy, final Map<IType, IMember[]> typeToMemberArray) { final Set<IType> result= new HashSet<>(); final IType[] subtypes= hierarchy.getAllSubtypes(hierarchy.getType()); for (int i= 0; i < subtypes.length; i++) { final IType subtype= subtypes[i]; if (canBeShown(subtype, typeToMemberArray, hierarchy)) result.add(subtype); } return result; }
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; }
private void checkOverridden(RefactoringStatus status, IProgressMonitor pm) throws JavaModelException { pm.beginTask("", 9); //$NON-NLS-1$ pm.setTaskName(RefactoringCoreMessages.InlineMethodRefactoring_checking_overridden); MethodDeclaration decl= fSourceProvider.getDeclaration(); IMethod method= (IMethod) decl.resolveBinding().getJavaElement(); if (method == null || Flags.isPrivate(method.getFlags())) { pm.worked(8); return; } IType type= method.getDeclaringType(); ITypeHierarchy hierarchy= type.newTypeHierarchy(new SubProgressMonitor(pm, 6)); checkSubTypes(status, method, hierarchy.getAllSubtypes(type), new SubProgressMonitor(pm, 1)); checkSuperClasses(status, method, hierarchy.getAllSuperclasses(type), new SubProgressMonitor(pm, 1)); checkSuperInterfaces(status, method, hierarchy.getAllSuperInterfaces(type), new SubProgressMonitor(pm, 1)); pm.setTaskName(""); //$NON-NLS-1$ }
IType[] types = null; if (this.subTypes != null) { types = this.hierarchy.getAllSubtypes(this.focusType); if (this.includeFocusType) { int len = types.length; types = this.hierarchy.getAllTypes();
return false; ITypeHierarchy hierarchy= sub.newSupertypeHierarchy(null); return hierarchy.contains(sup); } else { ITypeHierarchy hierarchy= sub.newSupertypeHierarchy(null); IType[] allTypes= hierarchy.getAllTypes(); for (int i= 0; i < allTypes.length; i++) { IType type= allTypes[i];
public static void findTestImplementorClasses(ITypeHierarchy typeHierarchy, IType testInterface, IRegion region, Set result) throws JavaModelException { IType[] subtypes= typeHierarchy.getAllSubtypes(testInterface); for (int i= 0; i < subtypes.length; i++) { IType type= subtypes[i]; int cachedFlags= typeHierarchy.getCachedFlags(type); if (!Flags.isInterface(cachedFlags) && !Flags.isAbstract(cachedFlags) // do the cheaper tests first && region.contains(type) && CoreTestSearchEngine.isAccessibleClass(type)) { result.add(type); } } }
public synchronized void doHierarchyRefresh(IJavaElement element, IProgressMonitor pm) throws JavaModelException { boolean hierachyCreationNeeded= (fHierarchy == null || !element.equals(fInputElement)); // to ensure the order of the two listeners always remove / add listeners on operations // on type hierarchies if (fHierarchy != null) { fHierarchy.removeTypeHierarchyChangedListener(this); JavaCore.removeElementChangedListener(this); } if (hierachyCreationNeeded) { fHierarchy= createTypeHierarchy(element, pm); if (pm != null && pm.isCanceled()) { throw new OperationCanceledException(); } fInputElement= element; } else { fHierarchy.refresh(pm); } fHierarchy.addTypeHierarchyChangedListener(this); JavaCore.addElementChangedListener(this); fHierarchyRefreshNeeded= false; }
final static IMethod[] hierarchyDeclaresMethodName(IProgressMonitor pm, ITypeHierarchy hierarchy, IMethod method, String newName) throws CoreException { Set result= new HashSet(); IType type= method.getDeclaringType(); IMethod foundMethod= Checks.findMethod(newName, method.getParameterTypes().length, false, type); if (foundMethod != null) result.add(foundMethod); IMethod[] foundInHierarchyClasses= classesDeclareMethodName(hierarchy, Arrays.asList(hierarchy.getAllClasses()), method, newName); if (foundInHierarchyClasses != null) result.addAll(Arrays.asList(foundInHierarchyClasses)); IType[] implementingClasses= hierarchy.getImplementingClasses(type); IMethod[] foundInImplementingClasses= classesDeclareMethodName(hierarchy, Arrays.asList(implementingClasses), method, newName); if (foundInImplementingClasses != null) result.addAll(Arrays.asList(foundInImplementingClasses)); return (IMethod[]) result.toArray(new IMethod[result.size()]); }
private int getDepth(ITypeHierarchy hierarchy, IType input) { int count= 0; IType superType= hierarchy.getSuperclass(input); while (superType != null) { count++; superType= hierarchy.getSuperclass(superType); } return count; }
public static IMethod isDeclaredInInterface(IMethod method, ITypeHierarchy hierarchy, IProgressMonitor monitor) throws JavaModelException { Assert.isTrue(isVirtual(method)); IProgressMonitor subMonitor= new SubProgressMonitor(monitor, 1); try { IType[] classes= hierarchy.getAllClasses(); subMonitor.beginTask("", classes.length); //$NON-NLS-1$ for (int i= 0; i < classes.length; i++) { final IType clazz= classes[i]; IType[] superinterfaces= null; if (clazz.equals(hierarchy.getType())) { superinterfaces= hierarchy.getAllSuperInterfaces(clazz); } else { superinterfaces= clazz.newSupertypeHierarchy(new SubProgressMonitor(subMonitor, 1)).getAllSuperInterfaces(clazz); } for (int j= 0; j < superinterfaces.length; j++) { IMethod found= Checks.findSimilarMethod(method, superinterfaces[j]); if (found != null && !found.equals(method)) { return found; } } subMonitor.worked(1); } return null; } finally { subMonitor.done(); } }
private IType[] getSubclasses(final IType type) { if (type.equals(fDeclaringType)) return new IType[0]; return fHierarchy.getSubclasses(type); }
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); }
public Collection findImplementingTypes(IType type, IProgressMonitor progressMonitor) { ITypeHierarchy typeHierarchy; try { typeHierarchy = type.newTypeHierarchy(progressMonitor); IType[] implementingTypes = typeHierarchy.getAllClasses(); HashSet result = new HashSet(Arrays.asList(implementingTypes)); return result; } catch (JavaModelException e) { JavaPlugin.log(e); } return null; }
protected void initialize(IProgressMonitor progressMonitor) throws JavaModelException { this.resourcePaths = new HashSet(); this.elements = new IResource[5]; this.elementCount = 0; this.needsRefresh = false; if (this.hierarchy == null) { if (this.javaProject != null) { this.hierarchy = this.focusType.newTypeHierarchy(this.javaProject, this.owner, progressMonitor); } else { this.hierarchy = this.focusType.newTypeHierarchy(this.owner, progressMonitor); } } else { this.hierarchy.refresh(progressMonitor); } buildResourceVector(); } /*
/** * Checks whether the given {@link ITypeHierarchy} contains an element with the given fully qualified name. * * @param h * The hierarchy to search in. * @param fqn * The fully qualified name of the types to search. Inner types must use the '$' enclosing type separator (e.g. * <code>org.eclipse.scout.TestClass$InnerClass$NextLevelInnerClass</code>). * @return <code>true</code> if it is part of the given {@link ITypeHierarchy}, <code>false</code> otherwise. */ public static boolean hierarchyContains(ITypeHierarchy h, String fqn) { for (IType t : h.getAllTypes()) { if (fqn.equals(t.getFullyQualifiedName())) { return true; } } return false; }
/** * Determines if the element has qname as a parent class * @param element the element to check for the parent class definition * @param qname the fully qualified name of the (potential) parent class * @return true if qname is a parent class, false otherwise */ private boolean hasSuperclass(IJavaElement element, String qname) { try { IType type = getType(element); if(type != null) { IType[] stypes = type.newSupertypeHierarchy(new NullProgressMonitor()).getAllSuperclasses(type); for(int i = 0; i < stypes.length; i++) { if(stypes[i].getFullyQualifiedName().equals(qname) || stypes[i].getElementName().equals(qname)) { return true; } } } } catch(JavaModelException e) {} return false; }