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

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

Introduction

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

Prototype

IType[] getRootClasses();

Source Link

Document

Returns all classes in the graph which have no resolved superclass, in no particular order.

Usage

From source file:org.eclipse.jst.jsf.common.internal.types.TypeInfoCache.java

License:Open Source License

/**Returns the TypeInfo for the given type. If no TypeInfo exists for this type, an empty TypeInfo
 * will be created and cached.//from w  ww .j  a v a 2  s .c  om
 * @param type - the type in question
 * @return the (modifyable) TypeInfo for the given type
 */
protected TypeInfo getOrCreateTypeInfo(IType type) {
    TypeInfo typeInfo = getTypeInfo(type);
    if (typeInfo == null) {
        try {
            final ITypeHierarchy hierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
            final IType[] supertypes = hierarchy.getAllSuperclasses(type);
            final IType[] interfaceTypes = hierarchy.getAllInterfaces();
            final IType[] rootClasses = hierarchy.getRootClasses();
            List missingSupertypesList = null;
            for (int i = 0; i < rootClasses.length; i++) {
                String superclassName = rootClasses[i].getSuperclassName();
                if (superclassName != null) {
                    if (missingSupertypesList == null) {
                        missingSupertypesList = new ArrayList(1);
                    }
                    superclassName = shortTypename(superclassName);
                    missingSupertypesList.add(superclassName);
                }
            }
            String[] missingSupertypes = null;
            if (missingSupertypesList != null) {
                missingSupertypes = (String[]) missingSupertypesList
                        .toArray(new String[missingSupertypesList.size()]);
            } else {
                missingSupertypes = TypeInfo.NO_NAMES;
            }
            typeInfo = new TypeInfo();
            typeInfo.setSupertypes(supertypes);
            typeInfo.setInterfaceTypes(interfaceTypes);
            typeInfo.setMissingSupertypeNames(missingSupertypes);
            cachedInfo.put(type, typeInfo);
            registerCachedType(type, typeInfo);
        } catch (JavaModelException e) {
            JSFCommonPlugin.log(e);
        }
    }
    return typeInfo;
}

From source file:org.eclipse.recommenders.rcp.JavaElementResolver.java

License:Open Source License

private List<IType> createListOfSupertypes(final IType jdtType) throws JavaModelException {
    final ITypeHierarchy hierarchy = SuperTypeHierarchyCache.getTypeHierarchy(jdtType);
    List<IType> supertypes = Lists.newArrayList(jdtType);
    for (IType supertype : hierarchy.getAllSupertypes(jdtType)) {
        supertypes.add(supertype);/* w  w w. j a v  a2s  .com*/
    }
    if (jdtType.isInterface()) {
        // ensure java.lang.Object is in the list to resolve, e.g., calls to 'interface.getClass()'
        for (IType s : hierarchy.getRootClasses()) {
            supertypes.add(s);
        }
    }
    return supertypes;
}