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

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

Introduction

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

Prototype

IType[] getAllSupertypes(IType type);

Source Link

Document

Returns all resolved supertypes of the given type, in bottom-up order.

Usage

From source file:ar.com.tadp.xml.rinzo.jdt.JDTUtils.java

License:Open Source License

public static IType[] getAllSuperTypes(String qualifiedTypeName) {
    try {//  w ww  . j  a v a  2  s .  c o m
        IType type;
        ITypeHierarchy supertypeHierarchy;
        type = JDTUtils.findType(qualifiedTypeName);
        supertypeHierarchy = type.newSupertypeHierarchy(null);
        return supertypeHierarchy.getAllSupertypes(type);
    } catch (JavaModelException e) {
        return new IType[] {};
    }
}

From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess.java

License:Open Source License

private static Reader findDocInHierarchy(IMethod method, boolean isHTML, boolean useAttachedJavadoc)
        throws JavaModelException {
    /*// w w  w  .j ava 2 s .co m
     * Catch ExternalJavaProject in which case
     * no hierarchy can be built.
     */
    if (!method.getJavaProject().exists())
        return null;

    IType type = method.getDeclaringType();
    ITypeHierarchy hierarchy = type.newSupertypeHierarchy(null);

    MethodOverrideTester tester = new MethodOverrideTester(type, hierarchy);

    IType[] superTypes = hierarchy.getAllSupertypes(type);
    for (int i = 0; i < superTypes.length; i++) {
        IType curr = superTypes[i];
        IMethod overridden = tester.findOverriddenMethodInType(curr, method);
        if (overridden != null) {
            Reader reader;
            if (isHTML)
                reader = getHTMLContentReader(overridden, false, useAttachedJavadoc);
            else
                reader = getContentReader(overridden, false);
            if (reader != null)
                return reader;
        }
    }
    return null;
}

From source file:cn.ieclipse.adt.ext.helpers.ProjectHelper.java

License:Apache License

public static Set<IType> getSuperType(ICompilationUnit unit, boolean includeInterface) {
    Set<IType> set = new HashSet<IType>();
    try {//from  ww  w . j a v a2 s  . c o  m
        IType[] types = unit.getTypes();
        if (null != types && types.length > 0) {
            ITypeHierarchy typeHierarchy = types[0].newSupertypeHierarchy(null);
            IType[] superclass = typeHierarchy.getAllSupertypes(types[0]);
            for (IType type : superclass) {
                if (type.isInterface() && includeInterface) {
                    set.add(type);
                } else {
                    set.add(type);
                }

            }
        }
    } catch (Exception e) {
    }
    return set;
}

From source file:cn.ieclipse.adt.ext.helpers.ProjectHelper.java

License:Apache License

public static Set<String> getSuperTypeName(ICompilationUnit unit, boolean includeInterface) {
    Set<String> set = new HashSet<String>();
    try {// w ww.j  a  va2s.c  om
        IType[] types = unit.getTypes();
        if (null != types && types.length > 0) {
            ITypeHierarchy typeHierarchy = types[0].newSupertypeHierarchy(null);
            IType[] superclass = typeHierarchy.getAllSupertypes(types[0]);
            for (IType type : superclass) {
                if (type.isInterface()) {
                    if (includeInterface) {
                        set.add(type.getFullyQualifiedName());
                    }
                } else {
                    set.add(type.getFullyQualifiedName());
                }

            }
        }
    } catch (Exception e) {
    }
    return set;
}

From source file:cn.ieclipse.adt.ext.helpers.ProjectHelper.java

License:Apache License

public static List<String> getSuperTypeName(IJavaProject project, String className, boolean includeInterface) {
    List<String> set = new ArrayList<String>();
    try {/*from  w  w w  . ja  v a  2s  .com*/
        IType type = project.findType(className);
        if (type != null) {
            set.add(className);
            ITypeHierarchy typeHierarchy = type.newSupertypeHierarchy(null);
            IType[] superclass = typeHierarchy.getAllSupertypes(type);
            for (IType s : superclass) {
                if (s.isInterface()) {
                    if (includeInterface) {
                        set.add(s.getFullyQualifiedName());
                    }
                } else {
                    set.add(s.getFullyQualifiedName());
                }

            }
        }
    } catch (Exception e) {

    }
    return set;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.IndexSelector.java

License:Open Source License

private static IJavaElement[] getFocusedElementsAndTypes(SearchPattern pattern, IJavaElement focusElement,
        ObjectVector superTypes) throws JavaModelException {
    if (pattern instanceof MethodPattern) {
        // For method pattern, it needs to walk along the focus type super hierarchy
        // and add jars/projects of all the encountered types.
        IType type = (IType) pattern.focus.getAncestor(IJavaElement.TYPE);
        MethodPattern methodPattern = (MethodPattern) pattern;
        String selector = new String(methodPattern.selector);
        int parameterCount = methodPattern.parameterCount;
        ITypeHierarchy superHierarchy = type.newSupertypeHierarchy(null);
        IType[] allTypes = superHierarchy.getAllSupertypes(type);
        int length = allTypes.length;
        SimpleSet focusSet = new SimpleSet(length + 1);
        if (focusElement != null)
            focusSet.add(focusElement);/*from  w w w .  j a va  2s .co  m*/
        for (int i = 0; i < length; i++) {
            IMethod[] methods = allTypes[i].getMethods();
            int mLength = methods.length;
            for (int m = 0; m < mLength; m++) {
                if (parameterCount == methods[m].getNumberOfParameters()
                        && methods[m].getElementName().equals(selector)) {
                    IPackageFragmentRoot root = (IPackageFragmentRoot) allTypes[i]
                            .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
                    IJavaElement element = root.isArchive() ? root : root.getParent();
                    focusSet.add(element);
                    if (superTypes != null)
                        superTypes.add(allTypes[i]);
                    break;
                }
            }
        }
        // Rebuilt a contiguous array
        IJavaElement[] focuses = new IJavaElement[focusSet.elementSize];
        Object[] values = focusSet.values;
        int count = 0;
        for (int i = values.length; --i >= 0;) {
            if (values[i] != null) {
                focuses[count++] = (IJavaElement) values[i];
            }
        }
        return focuses;
    }
    if (focusElement == null)
        return new IJavaElement[0];
    return new IJavaElement[] { focusElement };
}

From source file:com.google.inject.tools.ideplugin.eclipse.TypeUtil.java

License:Open Source License

private static IType resolveInParents(IType childType, String fullyQualifiedName) throws JavaModelException {
    IType resolvedType = null;//from  w ww. j  a v  a2 s. co m

    // not resolved? try the supertypes
    final ITypeHierarchy typeHierarchy = childType.newSupertypeHierarchy(new NullProgressMonitor());
    IType[] superTypes = typeHierarchy.getAllSupertypes(childType);
    String[][] resolved;

    LOOP_UNTIL_FIRST_MATCH: for (int i = 0; i < superTypes.length; i++) {
        IType type = superTypes[i];
        resolved = type.resolveType(fullyQualifiedName);

        if (resolved != null && resolved.length > 0) {
            resolvedType = childType.getJavaProject().findType(resolved[0][0], resolved[0][1]);
            break LOOP_UNTIL_FIRST_MATCH;
        }
    }

    return resolvedType;
}

From source file:com.iw.plugins.spindle.core.builder.WebXMLScanner.java

License:Mozilla Public License

protected boolean checkJavaSubclassOfImplements(IType superclass, IType candidate, ISourceLocation location) {
    boolean match = false;
    if (superclass.equals(candidate))
        return match;

    try {// w  w  w  . ja v  a 2  s .  co m
        if (candidate.isInterface())
            addProblem(IProblem.ERROR, location, "web-xml-must-be-class-not-interface", false,
                    IProblem.WEB_XML_INCORRECT_APPLICATION_SERVLET_CLASS);

        ITypeHierarchy hierarchy = candidate.newSupertypeHierarchy(null);
        if (hierarchy.exists()) {
            IType[] superClasses = hierarchy.getAllSupertypes(candidate);
            for (int i = 0; i < superClasses.length; i++) {
                match = superClasses[i].equals(superclass);
                if (match)
                    break;

            }
        }
    } catch (JavaModelException e) {
        TapestryCore.log(e);
        e.printStackTrace();
    }
    // if (!match)
    // addProblem(IProblem.ERROR, location, "web-xml-does-not-subclass");

    return match;
}

From source file:com.iw.plugins.spindle.core.util.CoreUtils.java

License:Mozilla Public License

/**
 * Answer true iff the candidate type is a subclass of the base Type
 * /* w w  w. j av  a  2  s  .  c om*/
 * @param candidate
 *            the supposed subclass of the base Type
 * @param baseType
 *            the supposed superclass of the candidate Type
 * @return true iff the candidate type is a subclass of the base Type
 * @throws JavaModelException
 */
public static boolean extendsType(IType candidate, IType baseType) throws JavaModelException {
    Assert.isNotNull(candidate);
    Assert.isNotNull(baseType);

    boolean match = false;
    ITypeHierarchy hierarchy = candidate.newSupertypeHierarchy(null);
    if (hierarchy.exists()) {
        IType[] superClasses = hierarchy.getAllSupertypes(candidate);
        for (int i = 0; i < superClasses.length; i++) {
            match = superClasses[i].equals(baseType);
            if (match)
                break;

        }
    }
    return match;
}

From source file:com.iw.plugins.spindle.ui.wizards.fields.ApplicationServletClassDialog.java

License:Mozilla Public License

private IStatus hasTapestryServletClassAsSuperType(String superclassName, IPackageFragmentRoot root) {
    SpindleStatus status = new SpindleStatus();
    enableButton(root == null);// ww  w.  j a va2 s. c o m
    if (root == null) {
        return status;
    }
    String superclassBaseTypeName = UIPlugin.getString("TapestryEngine.defaultServlet");
    if (superclassBaseTypeName == null) {
        throw new Error("tapestry servlet type: " + superclassBaseTypeName + " does not exist in properties!");
    }
    if (!superclassName.equals(superclassBaseTypeName)) {
        try {
            IType chosenSuperclassType = resolveTypeName(root.getJavaProject(), superclassName);
            if (chosenSuperclassType == null) {
                status.setWarning(UIPlugin.getString(name + ".warning.TypeNotExists", superclassName));
                return status;
            }
            boolean isBinary = chosenSuperclassType.isBinary();
            IType superclassBaseType = resolveTypeName(root.getJavaProject(), superclassBaseTypeName);
            if (superclassBaseType == null || !superclassBaseType.exists()) {
                status.setError(UIPlugin.getString(name + ".warning.TypeNotExists", superclassBaseTypeName));
                return status;
            }
            boolean match = false;
            ITypeHierarchy hierarchy = chosenSuperclassType.newSupertypeHierarchy(null);
            if (hierarchy.exists()) {
                IType[] superClasses = hierarchy.getAllSupertypes(chosenSuperclassType);
                for (int i = 0; i < superClasses.length; i++) {
                    if (superClasses[i].equals(superclassBaseType)) {
                        match = true;
                    }
                }
            }
            if (!match) {
                status.setError(
                        UIPlugin.getString(name + ".warning.SuperclassClassNotExtend", superclassBaseTypeName));
                return status;
            }

        } catch (JavaModelException e) {
            status.setError(name + ".error.couldn't.do.it");
        }
    }
    return status;
}