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

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

Introduction

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

Prototype

IType[] getImplementingClasses(IType type);

Source Link

Document

Returns all classes resolved to implement the given interface, in no particular order, limited to the classes in this type hierarchy's graph.

Usage

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 .  j a  v a  2s.c  om
    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.eclipse.objectteams.otdt.internal.refactoring.util.RefactoringUtil.java

License:Open Source License

public static IMethod[] hierarchyDeclaresMethodName(IProgressMonitor pm, IMethod method, String newName)
        throws CoreException {
    Set<IMethod> result = new HashSet<IMethod>();
    IType type = method.getDeclaringType();
    ITypeHierarchy hier = type.newTypeHierarchy(pm);
    IMethod foundMethod = Checks.findMethod(newName, method.getParameterTypes().length, false, type);
    if (foundMethod != null) {
        result.add(foundMethod);//from  w  w  w  .  j a  v  a  2 s .c o  m
    }
    IMethod[] foundInHierarchyClasses = classesDeclareMethodName(hier, Arrays.asList(hier.getAllClasses()),
            method, newName);
    if (foundInHierarchyClasses != null) {
        result.addAll(Arrays.asList(foundInHierarchyClasses));
    }
    IType[] implementingClasses = hier.getImplementingClasses(type);
    IMethod[] foundInImplementingClasses = classesDeclareMethodName(hier, Arrays.asList(implementingClasses),
            method, newName);
    if (foundInImplementingClasses != null) {
        result.addAll(Arrays.asList(foundInImplementingClasses));
    }
    return result.toArray(new IMethod[result.size()]);
}

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

License:Open Source License

/**
 * Checks, if method has a special OT name. Does not use the
 * OTTypeHIerarchy, because of performance optimization (team constants are
 * using)//from   w  ww. ja va  2 s  .  co  m
 * 
 * @param current
 *            method to check
 * @param new method name, should be <code>null</code> or an empty String if
 *        you wants to check the current method and not the new method with
 *        the same arguments like the current method
 * @return the refactoring status
 */
public static boolean isOTSpecialCase(IMethod origMethod, String newMethodName,
        boolean checkImplementingClasses, IProgressMonitor pm) throws CoreException {
    // TODO(jsv) what to do in case of interface is only used by base
    // class(es) ? to check the impolementing classes is a performance
    // overhead
    IType declaringType = origMethod.getDeclaringType();

    if (!Flags.isTeam(declaringType.getFlags())) {
        // heavyweight check for interfaces
        if (Flags.isInterface(declaringType.getFlags()) && checkImplementingClasses) {
            ITypeHierarchy hier = declaringType.newTypeHierarchy(pm);
            IType[] impementingClasses = hier.getImplementingClasses(declaringType);
            boolean teamImplementsInterface = false;
            for (int idx = 0; idx < impementingClasses.length; idx++) {
                if (Flags.isTeam(impementingClasses[idx].getFlags())) {
                    teamImplementsInterface = true;
                    break;
                }
            }

            if (!teamImplementsInterface) {
                return false;
            }
        } else {
            return false;
        }
    }

    if (newMethodName == null || newMethodName.length() == 0)
        newMethodName = origMethod.getElementName();

    assert (virtualTeamMethodNames.length == virtualTeamMethodParamTypes.length)
            && (virtualTeamMethodParamTypes.length == virtualTeamMethodReturnTypes.length);
    for (int i = 0; i < virtualTeamMethodNames.length; i++) {
        if (virtualTeamMethodNames[i].equals(newMethodName)
                && Checks.compareParamTypes(origMethod.getParameterTypes(), virtualTeamMethodParamTypes[i])
                && virtualTeamMethodReturnTypes[i].equals(origMethod.getReturnType())) {
            return true;
        }
    }
    return false;
}

From source file:org.gw4e.eclipse.facade.TestConvertor.java

License:Open Source License

private List<ICompilationUnit> findTests(IProgressMonitor monitor) throws JavaModelException {
    List<ICompilationUnit> units = new ArrayList<ICompilationUnit>();
    ITypeHierarchy th = testInterface.findPrimaryType().newTypeHierarchy(testInterface.getJavaProject(),
            monitor);//from   w ww.  j a v a  2  s  .  c om
    IType[] types = th.getImplementingClasses(testInterface.findPrimaryType());
    for (int i = 0; i < types.length; i++) {
        units.add(types[i].getCompilationUnit());
    }
    return units;
}