Example usage for org.eclipse.jdt.core ITypeHierarchy getType

List of usage examples for org.eclipse.jdt.core ITypeHierarchy getType

Introduction

In this page you can find the example usage for org.eclipse.jdt.core ITypeHierarchy getType.

Prototype

IType getType();

Source Link

Document

Returns the type this hierarchy was computed for.

Usage

From source file:at.bestsolution.fxide.jdt.corext.util.SuperTypeHierarchyCache.java

License:Open Source License

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<>(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;/*from  w  ww .  j  a  va2  s. co  m*/
                    }
                }
            }
            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);
    }
}

From source file:ca.mt.wb.devtools.tx.ComparisonModel.java

License:unlicense.org

public Set<IType> getAllTypes() {
    Set<IType> results = new HashSet<IType>();
    for (ITypeHierarchy h : added.values()) {
        getAllTypes(results, h, h.getType());
    }//from  w ww.j  a  va2  s .c  o m
    return results;
}

From source file:com.motorola.studio.android.generatecode.JDTUtils.java

License:Apache License

private static boolean isSubclass(ITypeHierarchy hierarchy, IType type, String superclass) {
    boolean contains = false;
    IType superclasstype = hierarchy.getSuperclass(type);
    if (superclasstype != null) {
        if (hierarchy.getType().getFullyQualifiedName().equals(superclass)
                || superclasstype.getFullyQualifiedName().equals(superclass)) {
            contains = true;/*from w  w  w  .  j a v a  2s .  co m*/
        } else {
            contains = isSubclass(hierarchy, superclasstype, superclass);
        }
    }

    return contains;
}

From source file:net.sourceforge.metrics.calculators.NumberOfMethods.java

License:Open Source License

private boolean isPolymorphic(IMethod method, ITypeHierarchy hierarchy) throws JavaModelException {
    for (IType subType : hierarchy.getAllSubtypes(hierarchy.getType())) {
        IMethod found = Checks.findMethod(method, subType);
        if (found != null)
            return true;
    }//from  w w w. j a v  a2 s  .  com
    return false;
}

From source file:org.eclipse.objectteams.otdt.internal.refactoring.util.RefactoringUtil.java

License:Open Source License

/**
 * Locates the topmost method of an override ripple and returns it. If none
 * is found, null is returned./*from w w  w  .j  a v a2  s.  c  o m*/
 * 
 * @param method
 *            the IMethod which may be part of a ripple
 * @param typeHierarchy
 *            a ITypeHierarchy of the declaring type of the method. May be
 *            null
 * @param monitor
 *            an IProgressMonitor
 * @return the topmost method of the ripple, or null if none
 * @throws JavaModelException
 */
public static IMethod getTopmostMethod(IMethod method, ITypeHierarchy typeHierarchy, IProgressMonitor monitor)
        throws JavaModelException {

    assert method != null;

    ITypeHierarchy hierarchy = typeHierarchy;
    IMethod topmostMethod = null;
    final IType declaringType = method.getDeclaringType();
    if (!declaringType.isInterface()) {
        if ((hierarchy == null) || !declaringType.equals(hierarchy.getType())) {
            hierarchy = declaringType.newSupertypeHierarchy(monitor);
        }
        IMethod inInterface = isDeclaredInInterface(method, hierarchy, monitor);
        if (inInterface != null && !inInterface.equals(method))
            topmostMethod = inInterface;
    }
    if (topmostMethod == null) {
        if (hierarchy == null) {
            hierarchy = declaringType.newSupertypeHierarchy(monitor);
        }
        IMethod overrides = overridesAnotherMethod(method, hierarchy, monitor);
        if (overrides != null && !overrides.equals(method))
            topmostMethod = overrides;
    }
    return topmostMethod;
}

From source file:org.eclipse.objectteams.otdt.tests.hierarchy.ITypeIOTTypeTest.java

License:Open Source License

public void testHierarchyCreation_equalFocusType() throws JavaModelException {
    ITypeHierarchy first = createTypeHierarchy(_MyTeam);
    ITypeHierarchy second = createTypeHierarchy(_OT_MyTeam);

    assertEquals(first.getType(), second.getType());
}

From source file:org.eclipse.wst.xml.search.editor.internal.jdt.SuperTypeHierarchyCache.java

License:Open Source License

private static void addTypeHierarchyToCache(ITypeHierarchy hierarchy) {
    synchronized (HIERACHY_CACHE) {
        int nEntries = HIERACHY_CACHE.size();
        if (nEntries >= 50) {
            HierarchyCacheEntry oldest = null;
            List<HierarchyCacheEntry> obsoleteHierarchies = new ArrayList<HierarchyCacheEntry>(50);
            for (int i = 0; i < nEntries; i++) {
                HierarchyCacheEntry entry = HIERACHY_CACHE.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;/* w  ww . j a  v  a  2 s . co  m*/
            }

            if (!obsoleteHierarchies.isEmpty()) {
                for (int i = 0; i < obsoleteHierarchies.size(); i++)
                    removeHierarchyEntryFromCache((HierarchyCacheEntry) obsoleteHierarchies.get(i));

            } else if (oldest != null)
                removeHierarchyEntryFromCache(oldest);
        }
        HierarchyCacheEntry newEntry = new HierarchyCacheEntry(hierarchy);
        HIERACHY_CACHE.add(newEntry);
    }
}

From source file:org.hawkinssoftware.rns.analysis.compile.domain.DomainRoleTypeBinding.java

License:Open Source License

public boolean isMember(String typename) {
    ITypeHierarchy hierarchy = TypeHierarchyCache.getInstance().get(typename);
    if (isImmediateMember(hierarchy.getType().getFullyQualifiedName())) {
        return true;
    }//from   w  w w.  j  a  v  a  2  s .c  o m
    for (IType type : hierarchy.getAllSupertypes(hierarchy.getType())) {
        if (isImmediateMember(type.getFullyQualifiedName())) {
            return true;
        }
    }
    return false;
}

From source file:org.hawkinssoftware.rns.analysis.compile.domain.DomainRoleTypeBinding.java

License:Open Source License

public boolean isContainedIn(DomainRoleTypeBinding role) {
    if (role.domainRoleType.equals(this.domainRoleType)) {
        return true;
    }// ww w  .j  a  va2s  . co m

    ITypeHierarchy roleHierarchy = TypeHierarchyCache.getInstance().get(role.domainRoleType);
    IType roleType = roleHierarchy.getType();
    while (true) {
        roleType = roleHierarchy.getSuperclass(roleType);
        if ((roleType == null)
                || roleType.getFullyQualifiedName().equals(DomainRole.class.getCanonicalName())) {
            break;
        }
        if (roleType.getFullyQualifiedName().equals(this.domainRoleType)) {
            return true;
        }
    }

    return false;
}

From source file:org.hawkinssoftware.rns.analysis.compile.HierarchyAnnotationChecker.java

License:Open Source License

public final void analyzeHierarchy(ParsedJavaSource source, ITypeHierarchy hierarchy) throws CoreException {
    Log.out(Tag.PUB_OPT, "%s analyzes the hierarchy of %s", getClass().getSimpleName(),
            hierarchy.getType().getFullyQualifiedName());
    this.hierarchy = hierarchy;

    startAnalysis(source);/*from w ww  .j  av  a  2s .  c  o  m*/

    this.hierarchy = null;
}