Search in sources :

Example 26 with ITypeHierarchy

use of org.eclipse.jdt.core.ITypeHierarchy in project che by eclipse.

the class RippleMethodFinder2 method createUnionFind.

private void createUnionFind() throws JavaModelException {
    fRootTypes = new HashSet<IType>(fTypeToMethod.keySet());
    fUnionFind = new UnionFind();
    for (Iterator<IType> iter = fTypeToMethod.keySet().iterator(); iter.hasNext(); ) {
        IType type = iter.next();
        fUnionFind.init(type);
    }
    for (Iterator<IType> iter = fTypeToMethod.keySet().iterator(); iter.hasNext(); ) {
        IType type = iter.next();
        uniteWithSupertypes(type, type);
    }
    fRootReps = new MultiMap<IType, IType>();
    for (Iterator<IType> iter = fRootTypes.iterator(); iter.hasNext(); ) {
        IType type = iter.next();
        IType rep = fUnionFind.find(type);
        if (rep != null)
            fRootReps.put(rep, type);
    }
    fRootHierarchies = new HashMap<IType, ITypeHierarchy>();
}
Also used : ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) IType(org.eclipse.jdt.core.IType)

Example 27 with ITypeHierarchy

use of org.eclipse.jdt.core.ITypeHierarchy in project che by eclipse.

the class SuperTypeHierarchyCache method getTypeHierarchy.

/**
	 * Returns a super type hierarchy that contains the given type.
	 * The returned hierarchy may actually be based on a subtype of the
	 * requested type. Therefore, queries such as {@link ITypeHierarchy#getAllClasses()}
	 * or {@link ITypeHierarchy#getRootInterfaces()} may return more types than the same
	 * queries on a type hierarchy for just the given type.
	 *
	 * @param type the focus type
	 * @param progressMonitor progress monitor
	 * @return a supertype hierarchy that contains <code>type</code>
	 * @throws JavaModelException if a problem occurs
	 */
public static ITypeHierarchy getTypeHierarchy(IType type, IProgressMonitor progressMonitor) throws JavaModelException {
    ITypeHierarchy hierarchy = findTypeHierarchyInCache(type);
    if (hierarchy == null) {
        fgCacheMisses++;
        hierarchy = type.newSupertypeHierarchy(progressMonitor);
        addTypeHierarchyToCache(hierarchy);
    } else {
        fgCacheHits++;
    }
    return hierarchy;
}
Also used : ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy)

Example 28 with ITypeHierarchy

use of org.eclipse.jdt.core.ITypeHierarchy in project che by eclipse.

the class SuperTypeHierarchyCache method addTypeHierarchyToCache.

private static void addTypeHierarchyToCache(ITypeHierarchy hierarchy) {
    synchronized (fgHierarchyCache) {
        int nEntries = fgHierarchyCache.size();
        if (nEntries >= CACHE_SIZE) {
            // find obsolete entries or remove entry that was least recently accessed
            HierarchyCacheEntry oldest = null;
            ArrayList<HierarchyCacheEntry> obsoleteHierarchies = new ArrayList<HierarchyCacheEntry>(CACHE_SIZE);
            for (int i = 0; i < nEntries; i++) {
                HierarchyCacheEntry entry = fgHierarchyCache.get(i);
                ITypeHierarchy curr = entry.getTypeHierarchy();
                if (!curr.exists() || hierarchy.contains(curr.getType())) {
                    obsoleteHierarchies.add(entry);
                } else {
                    if (oldest == null || entry.getLastAccess() < oldest.getLastAccess()) {
                        oldest = entry;
                    }
                }
            }
            if (!obsoleteHierarchies.isEmpty()) {
                for (int i = 0; i < obsoleteHierarchies.size(); i++) {
                    removeHierarchyEntryFromCache(obsoleteHierarchies.get(i));
                }
            } else if (oldest != null) {
                removeHierarchyEntryFromCache(oldest);
            }
        }
        HierarchyCacheEntry newEntry = new HierarchyCacheEntry(hierarchy);
        fgHierarchyCache.add(newEntry);
    }
}
Also used : ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) ArrayList(java.util.ArrayList)

Example 29 with ITypeHierarchy

use of org.eclipse.jdt.core.ITypeHierarchy in project che by eclipse.

the class SuperTypeHierarchyCache method getMethodOverrideTester.

public static MethodOverrideTester getMethodOverrideTester(IType type) throws JavaModelException {
    MethodOverrideTester test = null;
    synchronized (fgMethodOverrideTesterCache) {
        test = fgMethodOverrideTesterCache.get(type);
    }
    if (test == null) {
        // don't nest the locks
        ITypeHierarchy hierarchy = getTypeHierarchy(type);
        synchronized (fgMethodOverrideTesterCache) {
            // test again after waiting a long time for 'getTypeHierarchy'
            test = fgMethodOverrideTesterCache.get(type);
            if (test == null) {
                test = new MethodOverrideTester(type, hierarchy);
                fgMethodOverrideTesterCache.put(type, test);
            }
        }
    }
    return test;
}
Also used : ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy)

Example 30 with ITypeHierarchy

use of org.eclipse.jdt.core.ITypeHierarchy in project che by eclipse.

the class JavaTypeHierarchy method findTypesWithSubMethods.

private void findTypesWithSubMethods(IJavaElement element, List<Type> implementations) throws JavaModelException {
    IMethod selectedMethod = (IMethod) element;
    IType parentType = selectedMethod.getDeclaringType();
    if (parentType == null) {
        return;
    }
    ITypeHierarchy typeHierarchy = parentType.newTypeHierarchy(new NullProgressMonitor());
    IType[] subTypes = typeHierarchy.getAllSubtypes(parentType);
    MethodOverrideTester methodOverrideTester = new MethodOverrideTester(parentType, typeHierarchy);
    for (IType type : subTypes) {
        IMethod method = methodOverrideTester.findOverridingMethodInType(type, selectedMethod);
        if (method == null) {
            continue;
        }
        Type openDeclaration = convertToTypeDTO(type);
        setRange(openDeclaration, method);
        implementations.add(openDeclaration);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) IType(org.eclipse.jdt.core.IType) Type(org.eclipse.che.ide.ext.java.shared.dto.model.Type) MethodOverrideTester(org.eclipse.jdt.internal.corext.util.MethodOverrideTester) IMethod(org.eclipse.jdt.core.IMethod) IType(org.eclipse.jdt.core.IType)

Aggregations

ITypeHierarchy (org.eclipse.jdt.core.ITypeHierarchy)37 IType (org.eclipse.jdt.core.IType)25 IMethod (org.eclipse.jdt.core.IMethod)14 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)11 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 ArrayList (java.util.ArrayList)6 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)5 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)4 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)4 ModifierKeyword (org.eclipse.jdt.core.dom.Modifier.ModifierKeyword)4 MethodOverrideTester (org.eclipse.jdt.internal.corext.util.MethodOverrideTester)4 Type (org.eclipse.che.ide.ext.java.shared.dto.model.Type)3 JavaModelException (org.eclipse.jdt.core.JavaModelException)3 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 IJavaElement (org.eclipse.jdt.core.IJavaElement)2 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)2 RefactoringStatusContext (org.eclipse.ltk.core.refactoring.RefactoringStatusContext)2 HashMap (java.util.HashMap)1 List (java.util.List)1