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

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

Introduction

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

Prototype

IType[] getSuperInterfaces(IType type);

Source Link

Document

Returns the direct resolved interfaces that the given type implements or extends, in no particular order, limited to the interfaces in this type hierarchy's graph.

Usage

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

License:unlicense.org

public IType[] getSuperinterfacesFor(IType t) {
    Set<IType> supers = new HashSet<IType>();
    for (ITypeHierarchy h : added.values()) {
        for (IType superinterface : h.getSuperInterfaces(t)) {
            if (!isHidden(superinterface)) {
                supers.add(superinterface);
            }//from  w ww.  j a  va2 s.  co  m
        }
    }
    return (IType[]) supers.toArray(new IType[supers.size()]);
}

From source file:com.google.gdt.eclipse.core.java.JavaModelSearch.java

License:Open Source License

private static IMethod findMethodOrCtorInHierarchy(ITypeHierarchy hierarchy, IType type, String methodName,
        boolean isConstructor) {
    try {//from w  w w.j ava  2 s . c o m
        IMethod[] methods = type.getMethods();
        for (IMethod method : methods) {
            if (method.getElementName().equals(methodName)) {
                return method;
            }
        }
    } catch (JavaModelException e) {
        CorePluginLog.logError(e);
        return null;
    }

    // Check super class
    IType superClass = hierarchy.getSuperclass(type);
    if (superClass != null) {
        IMethod method = findMethodOrCtorInHierarchy(hierarchy, superClass, methodName, isConstructor);
        if (method != null) {
            return method;
        }
    }

    if (!isConstructor) {
        // Check interfaces
        IType[] superInterfaces = hierarchy.getSuperInterfaces(type);
        for (IType superInterface : superInterfaces) {
            IMethod method = findMethodOrCtorInHierarchy(hierarchy, superInterface, methodName, false);
            if (method != null) {
                return method;
            }
        }
    }

    return null;
}

From source file:com.google.gdt.eclipse.core.java.JavaModelSearch.java

License:Open Source License

private static IMethod findMethodOrCtorInHierarchy(ITypeHierarchy hierarchy, IType type, String methodName,
        String[] paramTypes, boolean isConstructor) {
    IMethod method = findMethodOrCtor(type, methodName, paramTypes, isConstructor);
    if (method != null) {
        return method;
    }//from  w  ww  .  j  a v  a2  s . c o m

    // Check super class
    IType superClass = hierarchy.getSuperclass(type);
    if (superClass != null) {
        method = findMethodOrCtorInHierarchy(hierarchy, superClass, methodName, paramTypes, isConstructor);
        if (method != null) {
            return method;
        }
    }

    if (!isConstructor) {
        // Check interfaces
        IType[] superInterfaces = hierarchy.getSuperInterfaces(type);
        for (IType superInterface : superInterfaces) {
            method = findMethodOrCtorInHierarchy(hierarchy, superInterface, methodName, paramTypes, false);
            if (method != null) {
                return method;
            }
        }
    }

    return method;
}

From source file:edu.illinois.compositerefactorings.steps.UseSuperTypeWherePossible.java

License:Open Source License

protected static List<IType> getClosestSupertypes(IJavaProject project, IType type) throws CoreException {
    final int MAX_NUMBER_OF_SUPERTYPES = 2;
    List<IType> closestsSuperTypes = new LinkedList<IType>();
    LinkedList<IType> remainingTypes = new LinkedList<IType>();
    remainingTypes.add(type);//ww  w  . j av a2 s  .  c  om
    ITypeHierarchy typeHierarchy = type.newTypeHierarchy(project, new NullProgressMonitor());
    while (!remainingTypes.isEmpty() && closestsSuperTypes.size() < MAX_NUMBER_OF_SUPERTYPES) {
        IType currentType = remainingTypes.removeFirst();
        if (currentType != type) {
            closestsSuperTypes.add(currentType);
        }
        IType currentSupertype = typeHierarchy.getSuperclass(currentType);
        if (currentSupertype != null) {
            remainingTypes.addLast(currentSupertype);
        }
        remainingTypes.addAll(Arrays.asList(typeHierarchy.getSuperInterfaces(currentType)));
    }
    return closestsSuperTypes;
}

From source file:fr.ifpen.emptooling.reverse.JavaToEcore.java

License:Open Source License

/**
 * Resolve the super type and interfaces of the given {@link EClass} (corresponding to the given
 * {@link IType})./*from www . ja  v  a2s  . c  o m*/
 * 
 * @param iType the given {@link IType}).
 * @param clazz the given {@link EClass}.
 * @throws JavaModelException
 */
protected void postProcessType(IType iType, EClass clazz) throws JavaModelException {
    ITypeHierarchy hierarchy = iType.newSupertypeHierarchy(new NullProgressMonitor());
    IType superType = hierarchy.getSuperclass(iType);
    if (superType != null) {
        String superTypeFQN = superType.getFullyQualifiedName();
        if (!("java.lang.Object".equals(superTypeFQN) || "java.lang.Enum".equals(superTypeFQN))) {
            if (eClassesAdded.containsKey(superTypeFQN)) {
                clazz.getESuperTypes().add((EClass) eClassesAdded.get(superTypeFQN));
            } else {
                EClassifier eClassifier = getEClassifierInLibraries(superType.getElementName());
                if (eClassifier != null && eClassifier instanceof EClass) {
                    clazz.getESuperTypes().add((EClass) eClassifier);
                } else {
                    logEntry(errorLog, iType.getCompilationUnit().getElementName() + ";"
                            + iType.getElementName() + ";unresolved super type;" + superTypeFQN);
                }
            }
        }
    }

    List<IType> superInterfaces = Arrays.asList(hierarchy.getSuperInterfaces(iType));
    for (IType superInterface : superInterfaces) {
        String superInterfaceFQN = superInterface.getFullyQualifiedName();
        if (eClassesAdded.containsKey(superInterfaceFQN)) {
            clazz.getESuperTypes().add((EClass) eClassesAdded.get(superInterfaceFQN));
        } else {
            EClassifier eClassifier = getEClassifierInLibraries(superInterface.getElementName());
            if (eClassifier != null && eClassifier instanceof EClass) {
                clazz.getESuperTypes().add((EClass) eClassifier);
            } else {
                logEntry(errorLog, iType.getCompilationUnit().getElementName() + ";" + iType.getElementName()
                        + ";unresolved interface;" + superInterfaceFQN);
            }
        }
    }
}

From source file:net.sf.commonclipse.CompareToGenerator.java

License:Apache License

/**
 * Checks if superclass implements comparable.
 * @param type IType/*from  w w w . j a v a  2 s.  c  o  m*/
 * @return <code>true</code> if superclass implements comparable
 * @throws JavaModelException exception thrown when analyzing type hierarchy
 */
private boolean doesSuperImplementsComparable(IType type) throws JavaModelException {
    // get hierarchy
    ITypeHierarchy hierarchy = type.newSupertypeHierarchy(null);

    // get superclass
    IType superTypes = hierarchy.getSuperclass(type);

    // get interfaces starting from superclass
    IType[] interfaces = hierarchy.getSuperInterfaces(superTypes);

    // does superclass implements comparable?
    for (int j = 0; j < interfaces.length; j++) {
        if (interfaces[j].getFullyQualifiedName().equals("java.lang.Comparable")) //$NON-NLS-1$
        {
            return true;
        }
    }

    return false;
}

From source file:org.eclipse.jst.j2ee.internal.common.operations.JavaModelUtil.java

License:Open Source License

/**
 * Finds a method in a type and all its super types. The super class hierarchy is searched first, then the super interfaces.
 * This searches for a method with the same name and signature. Parameter types are only
 * compared by the simple name, no resolving for the fully qualified type name is done.
 * Constructors are only compared by parameters, not the name.
 * NOTE: For finding overridden methods or for finding the declaring method, use {@link MethodOverrideTester}
 * @param hierarchy The hierarchy containing the type
 *    @param type The type to start the search from
 * @param name The name of the method to find
 * @param paramTypes The type signatures of the parameters e.g. <code>{"QString;","I"}</code>
 * @param isConstructor If the method is a constructor
 * @return The first found method or <code>null</code>, if nothing found
 */// w w  w .  ja  v  a2 s.c om
public static IMethod findMethodInHierarchy(ITypeHierarchy hierarchy, IType type, String name,
        String[] paramTypes, boolean isConstructor) throws JavaModelException {
    IMethod method = findMethod(name, paramTypes, isConstructor, type);
    if (method != null) {
        return method;
    }
    IType superClass = hierarchy.getSuperclass(type);
    if (superClass != null) {
        IMethod res = findMethodInHierarchy(hierarchy, superClass, name, paramTypes, isConstructor);
        if (res != null) {
            return res;
        }
    }
    if (!isConstructor) {
        IType[] superInterfaces = hierarchy.getSuperInterfaces(type);
        for (int i = 0; i < superInterfaces.length; i++) {
            IMethod res = findMethodInHierarchy(hierarchy, superInterfaces[i], name, paramTypes, false);
            if (res != null) {
                return res;
            }
        }
    }
    return method;
}

From source file:org.eclipse.jst.j2ee.internal.common.operations.JavaModelUtil.java

License:Open Source License

public static boolean isSuperType(ITypeHierarchy hierarchy, IType possibleSuperType, IType type) {
    // filed bug 112635 to add this method to ITypeHierarchy
    IType superClass = hierarchy.getSuperclass(type);
    if (superClass != null && (possibleSuperType.equals(superClass)
            || isSuperType(hierarchy, possibleSuperType, superClass))) {
        return true;
    }/*from  w  w w  . j  a v a  2  s . c  o  m*/
    if (Flags.isInterface(hierarchy.getCachedFlags(possibleSuperType))) {
        IType[] superInterfaces = hierarchy.getSuperInterfaces(type);
        for (int i = 0; i < superInterfaces.length; i++) {
            IType curr = superInterfaces[i];
            if (possibleSuperType.equals(curr) || isSuperType(hierarchy, possibleSuperType, curr)) {
                return true;
            }
        }
    }
    return false;
}

From source file:org.eclipse.jst.jsf.common.ui.internal.utils.JavaModelUtil.java

License:Open Source License

private static IMethod findMethodInHierarchy(ITypeHierarchy hierarchy, IType type, String name,
        String[] paramTypes, boolean isConstructor) throws JavaModelException {
    IMethod method = findMethod(name, paramTypes, isConstructor, type);
    if (method != null) {
        return method;
    }/*from  ww  w.j  a  v  a  2 s .  c o  m*/
    IType superClass = hierarchy.getSuperclass(type);
    if (superClass != null) {
        IMethod res = findMethodInHierarchy(hierarchy, superClass, name, paramTypes, isConstructor);
        if (res != null) {
            return res;
        }
    }
    if (!isConstructor) {
        IType[] superInterfaces = hierarchy.getSuperInterfaces(type);
        for (int i = 0; i < superInterfaces.length; i++) {
            IMethod res = findMethodInHierarchy(hierarchy, superInterfaces[i], name, paramTypes, false);
            if (res != null) {
                return res;
            }
        }
    }
    return method;
}

From source file:org.eclipse.jst.jsf.common.ui.internal.utils.JavaModelUtil.java

License:Open Source License

/**
 * Finds the method that is defines/declares the given method. The search is
 * bottom-up, so this returns the nearest defining/declaring method.
 * @param typeHierarchy /*from  w w  w .j  a va  2  s.  co  m*/
 * @param type 
 * @param methodName 
 * @param paramTypes 
 * @param isConstructor 
 * 
 * @param testVisibility
 *            If true the result is tested on visibility. Null is returned
 *            if the method is not visible.
 * @return the method or null
 * @throws JavaModelException
 */
public static IMethod findMethodDefininition(ITypeHierarchy typeHierarchy, IType type, String methodName,
        String[] paramTypes, boolean isConstructor, boolean testVisibility) throws JavaModelException {
    IType superClass = typeHierarchy.getSuperclass(type);
    if (superClass != null) {
        IMethod res = findMethodInHierarchy(typeHierarchy, superClass, methodName, paramTypes, isConstructor);
        if (res != null && !Flags.isPrivate(res.getFlags())) {
            if (!testVisibility || isVisibleInHierarchy(res, type.getPackageFragment())) {
                return res;
            }
        }
    }
    if (!isConstructor) {
        IType[] interfaces = typeHierarchy.getSuperInterfaces(type);
        for (int i = 0; i < interfaces.length; i++) {
            IMethod res = findMethodInHierarchy(typeHierarchy, interfaces[i], methodName, paramTypes, false);
            if (res != null) {
                return res; // methods from interfaces are always public and
                // therefore visible
            }
        }
    }
    return null;
}