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

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

Introduction

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

Prototype

IType[] getAllSuperInterfaces(IType type);

Source Link

Document

Returns all resolved superinterfaces (direct and indirect) of the given type.

Usage

From source file:com.google.gwt.eclipse.platform.clientbundle.ResourceTypeDefaultExtensions.java

License:Open Source License

/**
 * Find all default extensions for this resource type. If the type itself does
 * not declare any extensions, it may inherit extensions from any of the
 * interfaces in its super type hierarchy.
 *///from w w w  . ja va2  s  . c  o  m
public static String[] getDefaultExtensions(IType resourceType) throws JavaModelException {
    String[] extensions = getDeclaredDefaultExtensions(resourceType);

    // Check the super interface hierarchy for @DefaultExtensions
    if (extensions.length == 0) {
        ITypeHierarchy superHierarchy = resourceType.newSupertypeHierarchy(null);
        IType[] superInterfaces = superHierarchy.getAllSuperInterfaces(resourceType);
        for (IType superInterface : superInterfaces) {
            extensions = getDeclaredDefaultExtensions(superInterface);
            if (extensions.length > 0) {
                break;
            }
        }
    }
    return extensions;
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockUtil.java

License:Open Source License

/********************************************************************************/

static void outputTypeHierarchy(ITypeHierarchy th, IvyXmlWriter xw) {
    xw.begin("HIERARCHY");
    IType[] typs = th.getAllTypes();//from  w  ww.  java 2  s .c  o  m
    for (IType typ : typs) {
        xw.begin("TYPE");
        try {
            xw.field("NAME", typ.getFullyQualifiedName());
            xw.field("QNAME", typ.getTypeQualifiedName());
            xw.field("PNAME", typ.getFullyQualifiedParameterizedName());
            if (typ.isClass())
                xw.field("KIND", "CLASS");
            else if (typ.isEnum())
                xw.field("KIND", "ENUM");
            else if (typ.isInterface())
                xw.field("KIND", "INTERFACE");
            xw.field("LOCAL", typ.isLocal());
            xw.field("MEMBER", typ.isMember());
            xw.field("KEY", typ.getKey());
            IType[] subs = th.getAllSubtypes(typ);
            for (IType styp : subs) {
                xw.begin("SUBTYPE");
                xw.field("NAME", styp.getFullyQualifiedName());
                xw.field("KEY", styp.getKey());
                xw.end("SUBTYPE");
            }
            IType[] sups = th.getAllSuperclasses(typ);
            for (IType styp : sups) {
                xw.begin("SUPERCLASS");
                xw.field("NAME", styp.getFullyQualifiedName());
                xw.field("KEY", styp.getKey());
                xw.end("SUPERCLASS");
            }
            sups = th.getAllSuperInterfaces(typ);
            for (IType styp : sups) {
                xw.begin("SUPERIFACE");
                xw.field("NAME", styp.getFullyQualifiedName());
                xw.field("KEY", styp.getKey());
                xw.end("SUPERIFACE");
            }
            sups = th.getAllSupertypes(typ);
            for (IType styp : sups) {
                xw.begin("SUPERTYPE");
                xw.field("NAME", styp.getFullyQualifiedName());
                xw.field("KEY", styp.getKey());
                xw.end("SUPERTYPE");
            }
            sups = th.getExtendingInterfaces(typ);
            for (IType styp : sups) {
                xw.begin("EXTENDIFACE");
                xw.field("NAME", styp.getFullyQualifiedName());
                xw.field("KEY", styp.getKey());
                xw.end("EXTENDIFACE");
            }
            sups = th.getImplementingClasses(typ);
            for (IType styp : sups) {
                xw.begin("IMPLEMENTOR");
                xw.field("NAME", styp.getFullyQualifiedName());
                xw.field("KEY", styp.getKey());
                xw.end("IMPLEMENTOR");
            }
        } catch (JavaModelException e) {
        }

        xw.end("TYPE");
    }
    xw.end("HIERARCHY");
}

From source file:org.dozer.eclipse.plugin.sourcepage.validation.Validator.java

License:Apache License

private boolean checkClassImplementsCustomConverter(IProject project, String className)
        throws JavaModelException {
    IType javaType = JdtUtils.getJavaType(project, className);

    if (javaType == null)
        return false;

    ITypeHierarchy hierarchy = javaType.newSupertypeHierarchy(new NullProgressMonitor());
    IType[] interfaces = hierarchy.getAllSuperInterfaces(javaType);

    for (IType type : interfaces) {
        if (type.getElementName().equals("CustomConverter")) {
            return true;
        }/*from   w ww .  ja v a 2  s.  c om*/
    }

    return false;
}

From source file:org.eclipse.jst.j2ee.internal.web.operations.AbstractSupertypesValidator.java

License:Open Source License

protected static boolean hasSuperInterface(IDataModel dataModel, String typeName, String superTypeName) {
    try {/* www  .  ja  v  a2s .  co  m*/
        IType type = getJavaProject(dataModel).findType(typeName);
        if (type != null) {
            ITypeHierarchy typeHierarchy = getTypeHierarchy(type);
            for (IType superType : typeHierarchy.getAllSuperInterfaces(type)) {
                if (superTypeName.equals(superType.getFullyQualifiedName()))
                    return true;
            }
        }
    } catch (JavaModelException e) {
        WebPlugin.log(e);
    }

    return false;
}

From source file:org.eclipse.jst.servlet.ui.internal.wizard.NewWebClassWizardPage.java

License:Open Source License

private boolean isObjectSubclassOf(Object obj, String base) {
    IJavaElement jelem = getJavaElement(obj);

    try {//from   w w w  .  j av  a2s. co m
        if (jelem != null) {
            if (jelem instanceof ICompilationUnit) {
                ICompilationUnit cu = (ICompilationUnit) jelem;
                jelem = getPrimaryType(cu);
            }

            if (jelem instanceof IType && ((IType) jelem).isClass()) {
                IType type = (IType) jelem;
                ITypeHierarchy typeHierarchy = type.newTypeHierarchy(null);
                for (IType superType : typeHierarchy.getAllSuperInterfaces(type)) {
                    if (base.equals(superType.getFullyQualifiedName()))
                        return true;
                }
            }
        }
    } catch (JavaModelException e) {
        ServletUIPlugin.log(e);
    }

    return false;
}

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

License:Open Source License

/**
 * Checks if the given method is declared in an interface. If the method's
 * declaring type is an interface the method returns <code>false</code> if
 * it is only declared in that interface.
 *//*from ww w.j av  a  2  s .  c o  m*/
public static IMethod isDeclaredInInterface(IMethod method, ITypeHierarchy hierarchy, IProgressMonitor pm)
        throws JavaModelException {
    assert isVirtual(method);
    try {
        IType[] classes = hierarchy.getAllClasses();
        IProgressMonitor subPm = new SubProgressMonitor(pm, 3);
        subPm.beginTask("", classes.length); //$NON-NLS-1$
        for (int idxAllHierarchyClasses = 0; idxAllHierarchyClasses < classes.length; idxAllHierarchyClasses++) {
            ITypeHierarchy superTypes = classes[idxAllHierarchyClasses].newSupertypeHierarchy(subPm);
            IType[] superinterfaces = superTypes.getAllSuperInterfaces(classes[idxAllHierarchyClasses]);

            for (int idxSuperInterfaces = 0; idxSuperInterfaces < superinterfaces.length; idxSuperInterfaces++) {
                IMethod found = Checks.findSimilarMethod(method, superinterfaces[idxSuperInterfaces]);
                if (found != null && !found.equals(method))
                    return found;
            }
            subPm.worked(1);
        }
        return null;
    } finally {
        pm.done();
    }
}

From source file:org.fastcode.util.SourceUtil.java

License:Open Source License

/**
 *
 * @param type//  w ww .  ja  v a 2  s .c  o m
 * @return
 * @throws Exception
 */
public static IType findSuperInterfaceType(final IType type) throws Exception {
    final ITypeHierarchy hierarchy = type.newSupertypeHierarchy(null);
    final String[] interfaces = type.getSuperInterfaceNames();

    if (interfaces == null || interfaces.length == 0) {
        return null;
    }

    for (final IType interfaceType : hierarchy.getAllSuperInterfaces(type)) {
        if (!interfaceType.isBinary() && interfaceType.getElementName().equals(interfaces[0])) {
            return interfaceType;
        }
    }
    return null;
}

From source file:org.fastcode.util.SourceUtil.java

License:Open Source License

/**
 * @param type//w w w. j  a v  a2  s. c o  m
 * @return
 * @throws Exception
 */
public static IType[] getSuperInterfacesType(final IType type) throws Exception {
    final List<IType> superInterfaceTypes = new ArrayList<IType>();
    if (type != null) {
        final ITypeHierarchy hierarchy = type.newSupertypeHierarchy(null);
        final String[] interfaces = type.getSuperInterfaceNames();

        if (interfaces == null || interfaces.length == 0) {
            return new IType[0];
        }

        for (final IType interfaceType : hierarchy.getAllSuperInterfaces(type)) {
            if (interfaceType != null) {
                superInterfaceTypes.add(interfaceType);
            }
        }
    }
    if (superInterfaceTypes != null && !superInterfaceTypes.isEmpty()) {
        return superInterfaceTypes.toArray(new IType[0]);
    }
    return new IType[0];
}

From source file:org.jboss.tools.arquillian.core.internal.dependencies.DependencyCache.java

License:Open Source License

private static void collectDependencies(ICompilationUnit unit, boolean excludeSuperclass) {
    if (unit == null || getDependencies().get(unit) != null) {
        return;//w  w  w  . j a v  a 2s.  c  o m
    }
    CompilationUnit cu = getAST(unit);
    IType primaryType = unit.findPrimaryType();
    if (primaryType == null) {
        return;
    }
    Set<String> excludeSet = new HashSet<String>();
    String name = primaryType.getFullyQualifiedName();
    if (excludeSuperclass) {
        try {
            ITypeHierarchy hierarchy = primaryType.newSupertypeHierarchy(null);
            IType superclass = hierarchy.getSuperclass(primaryType);
            if (superclass != null) {
                excludeSet.add(superclass.getFullyQualifiedName());
            }
            IType[] superInterfaces = hierarchy.getAllSuperInterfaces(primaryType);
            for (IType superInterface : superInterfaces) {
                excludeSet.add(superInterface.getFullyQualifiedName());
            }
        } catch (JavaModelException e) {
            ArquillianCoreActivator.logWarning(e.getLocalizedMessage());
        }
    }
    DependencyVisitor visitor = new DependencyVisitor(cu, name, excludeSet, unit.getJavaProject());
    cu.accept(visitor);
    getDependencies().put(unit, visitor.getTypes());
    IJavaProject javaProject = unit.getJavaProject();
    for (DependencyType dependencyType : visitor.getTypes()) {
        String typeName = dependencyType.getName();
        try {
            IType type = javaProject.findType(typeName);
            if (type == null) {
                continue;
            }
            ICompilationUnit compilationUnit = type.getCompilationUnit();
            collectDependencies(compilationUnit, false);
        } catch (JavaModelException e) {
            ArquillianCoreActivator.log(e);
        }
    }
    return;
}

From source file:org.jnario.spec.ui.wizards.NewSpecWizardPageTwo.java

License:Open Source License

@Override
public void setVisible(boolean visible) {
    super.setVisible(visible);
    if (visible) {
        if (fClassToTest == null) {
            return;
        }/* www .  j  av  a  2  s. c  o  m*/

        ArrayList<IType> types = null;
        try {
            ITypeHierarchy hierarchy = fClassToTest.newSupertypeHierarchy(null);
            IType[] superTypes;
            if (fClassToTest.isClass())
                superTypes = hierarchy.getAllSuperclasses(fClassToTest);
            else if (fClassToTest.isInterface())
                superTypes = hierarchy.getAllSuperInterfaces(fClassToTest);
            else
                superTypes = new IType[0];
            types = new ArrayList<IType>(superTypes.length + 1);
            types.add(fClassToTest);
            types.addAll(Arrays.asList(superTypes));
        } catch (JavaModelException e) {
            JUnitPlugin.log(e);
        }
        if (types == null)
            types = new ArrayList<IType>();
        fMethodsTree.setContentProvider(new MethodsTreeContentProvider(types.toArray()));
        fMethodsTree.setInput(types.toArray());
        fMethodsTree.setSelection(new StructuredSelection(fClassToTest), true);
        doCheckedStateChanged();

        fMethodsTree.getControl().setFocus();
    }
}