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>();
}
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;
}
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);
}
}
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;
}
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);
}
}
Aggregations