Example usage for org.eclipse.jdt.internal.core.hierarchy TypeHierarchy TypeHierarchy

List of usage examples for org.eclipse.jdt.internal.core.hierarchy TypeHierarchy TypeHierarchy

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core.hierarchy TypeHierarchy TypeHierarchy.

Prototype

public TypeHierarchy(IType type, ICompilationUnit[] workingCopies, IJavaSearchScope scope,
        boolean computeSubtypes) 

Source Link

Document

Creates a TypeHierarchy on the given type.

Usage

From source file:org.eclipse.ajdt.ui.tests.hierarchy.ITDAwareHierarchyTests.java

License:Open Source License

/**
 * Tests that ITD super types and super interfaces are included in the type hierarchy
 * when they are declared on the focus type
 *//*w w w  .  jav  a2  s  . c  o  m*/
public void testSuperTypeHierarchyOfFocusType() throws Exception {
    TypeHierarchy hierarchy = new TypeHierarchy(ship.findPrimaryType(), new ICompilationUnit[] { ship, yacht },
            shipProj, false);
    hierarchy.refresh(null);
    IType[] allClasses = hierarchy.getAllClasses();
    assertEquals(3, allClasses.length);
    arrayContains("Object", allClasses);
    arrayContains("FloatingThing", allClasses);
    arrayContains("Ship", allClasses);

    IType[] allInterfaces = hierarchy.getAllInterfaces();
    assertEquals(1, allInterfaces.length);
    arrayContains("Log", allInterfaces);
}

From source file:org.eclipse.ajdt.ui.tests.hierarchy.ITDAwareHierarchyTests.java

License:Open Source License

/**
 * Tests that ITD super types and super interfaces are included in the type hierarchy
 * when they are declared on the non-focus type
 *//*ww w  . jav  a 2 s.co  m*/
public void testSuperTypeHierarchyOfNonFocusType() throws Exception {
    TypeHierarchy hierarchy = new TypeHierarchy(yacht.findPrimaryType(), new ICompilationUnit[] { ship, yacht },
            shipProj, false);
    hierarchy.refresh(null);
    IType[] allClasses = hierarchy.getAllClasses();
    assertEquals(4, allClasses.length);
    arrayContains("Object", allClasses);
    arrayContains("FloatingThing", allClasses);
    arrayContains("Ship", allClasses);
    arrayContains("Yacht", allClasses);

    IType[] allInterfaces = hierarchy.getAllInterfaces();
    assertEquals(1, allInterfaces.length);
    arrayContains("Log", allInterfaces);
}

From source file:org.eclipse.ajdt.ui.tests.hierarchy.ITDAwareHierarchyTests2.java

License:Open Source License

public void testAbstractAspectWithDeclare() throws Exception {
    ICompilationUnit[] units = createUnits(new String[] { "p" }, new String[] { "AbstractAspect.aj" },
            new String[] { "package p;\n" + "public abstract aspect AbstractAspect {\n"
                    + "declare parents : Class extends X;\n" + "declare parents : Class extends Y;\n" + "}\n"
                    + "aspect Aspect extends AbstractAspect {\n" + "    void something(X x) {\n"
                    + "       something(new Class());\n" + "    }\n" + "    void something2(Y y) {\n"
                    + "        something2(new Class());\n" + "    }\n" + "}\n" + "interface X { }\n"
                    + "interface Y { }\n" + "class Class { }" },
            proj);//from  w w w  . j  a  va  2 s .  c  o m

    IType clazz = units[0].getType("Class");

    TypeHierarchy hierarchy = new TypeHierarchy(clazz, units, proj, false);
    hierarchy.refresh(null);
    IType[] allClasses = hierarchy.getAllClasses();
    assertEquals(2, allClasses.length);
    arrayContains("Object", allClasses);
    arrayContains("Class", allClasses);

    IType[] allInterfaces = hierarchy.getAllInterfaces();
    assertEquals(2, allInterfaces.length);
    arrayContains("X", allInterfaces);
    arrayContains("Y", allInterfaces);
}

From source file:org.eclipse.ajdt.ui.tests.hierarchy.ITDAwareHierarchyTests2.java

License:Open Source License

public void testAbstractGenericAspectWithDeclare() throws Exception {
    ICompilationUnit[] units = createUnits(new String[] { "p" }, new String[] { "AbstractAspect.aj" },
            new String[] { "package p;\n" + "public abstract aspect AbstractAspect<S, T> {\n"
                    + "declare parents : Class extends S;\n" + "declare parents : Class extends T;\n" + "}\n"
                    + "aspect Aspect extends AbstractAspect<X, Y> {\n" + "    void something(X x) {\n"
                    + "       something(new Class());\n" + "    }\n" + "    void something2(Y y) {\n"
                    + "        something2(new Class());\n" + "    }\n" + "}\n" + "interface X { }\n"
                    + "interface Y { }\n" + "class Class { }" },
            proj);/*from  w  w  w. j av  a  2  s  .  c  o  m*/

    IType clazz = units[0].getType("Class");

    TypeHierarchy hierarchy = new TypeHierarchy(clazz, units, proj, false);
    hierarchy.refresh(null);
    IType[] allClasses = hierarchy.getAllClasses();
    assertEquals(2, allClasses.length);
    arrayContains("Object", allClasses);
    arrayContains("Class", allClasses);

    IType[] allInterfaces = hierarchy.getAllInterfaces();
    assertEquals(2, allInterfaces.length);
    arrayContains("X", allInterfaces);
    arrayContains("Y", allInterfaces);
}

From source file:org.eclipse.objectteams.otdt.internal.core.ext.AbstractMarkable.java

License:Open Source License

/**
 * Get all direct and indirect subtypes of all types in 'types'.
 * @param types//from  w  w w.j  a  v a  2 s .c  o  m
 * @param monitor
 * @return
 * @throws JavaModelException
 */
Set<IType> getSubTypes(Set<IType> types, IProgressMonitor monitor) throws JavaModelException {
    monitor.beginTask(OTCoreExtMessages.AbstractMarkable_baseClassHierarchy_progress, types.size());

    IJavaSearchScope workspaceScope = SearchEngine.createWorkspaceScope();
    Set<IType> subTypes = new HashSet<IType>(13);
    for (IType type : types) {
        TypeHierarchy hier = new TypeHierarchy(type, null, workspaceScope, true);
        hier.refresh(monitor);
        for (IType subType : hier.getAllSubtypes(type))
            subTypes.add(subType);
        monitor.worked(1);
    }
    monitor.done();
    return subTypes;
}

From source file:org.eclipse.objectteams.otdt.tests.hierarchy.CompleteRoleHierarchyWithClasses.java

License:Open Source License

public void setUpSuite() throws Exception {
    setTestProjectDir("Hierarchy");
    super.setUpSuite();

    _focusRole = getRole(getTestProjectDir(), "complete_rolehierarchy_with_classes", "test002.inlined", "ATeam",
            "R1");

    _hierarchy = new TypeHierarchy(_focusRole, null, _focusRole.getJavaProject(), true);
    _hierarchy.refresh(new NullProgressMonitor());

    _implSuperRole = getRole(getTestProjectDir(), "complete_rolehierarchy_with_classes", "test002.inlined",
            "SuperTeam", "R1");

    _implSuperSuperRole = getRole(getTestProjectDir(), "complete_rolehierarchy_with_classes", "test002.inlined",
            "SuperSuperTeam", "R1");

    _implSubRole1 = getRole(getTestProjectDir(), "complete_rolehierarchy_with_classes", "test002.inlined",
            "SubTeam1", "R1");

    _implSubRole2 = getRole(getTestProjectDir(), "complete_rolehierarchy_with_classes", "test002.inlined",
            "SubTeam2", "R1");

    _implSubSubRole11 = getRole(getTestProjectDir(), "complete_rolehierarchy_with_classes", "test002.inlined",
            "SubSubTeam11", "R1");

    _implSubSubRole12 = getRole(getTestProjectDir(), "complete_rolehierarchy_with_classes", "test002.inlined",
            "SubSubTeam12", "R1");

    _class = getType(getTestProjectDir(), "complete_rolehierarchy_with_classes", "test002.standard", "AClass");

    _superClass = getType(getTestProjectDir(), "complete_rolehierarchy_with_classes", "test002.standard",
            "SuperClass");

    _subClass1 = getType(getTestProjectDir(), "complete_rolehierarchy_with_classes", "test002.standard",
            "SubClass1");

    _subClass2 = getType(getTestProjectDir(), "complete_rolehierarchy_with_classes", "test002.standard",
            "SubClass2");

    _subSubClass11 = getType(getTestProjectDir(), "complete_rolehierarchy_with_classes", "test002.standard",
            "SubSubClass11");

    _subSubClass12 = getType(getTestProjectDir(), "complete_rolehierarchy_with_classes", "test002.standard",
            "SubSubClass12");

    _object = getType(getTestProjectDir(), "rt.jar", "java.lang", "Object");

}

From source file:org.eclipse.objectteams.otdt.tests.hierarchy.CompleteRoleHierarchyWithClasses.java

License:Open Source License

public void testGetAllTypes_withLowFocus() throws JavaModelException {
    try {//from www. j a va 2 s.  c  o m
        _hierarchy = new TypeHierarchy(_implSubRole2, null, _implSubRole2.getJavaProject(), true);
        _hierarchy.refresh(null);

        ArrayList<IType> expectedList = new ArrayList<IType>();
        expectedList.add(_implSuperSuperRole);
        expectedList.add(_implSuperRole);
        expectedList.add(_focusRole);
        //            expectedList.add(_implSubRole1); // no longer reached
        expectedList.add(_implSubRole2);
        //            expectedList.add(_implSubSubRole11); // no longer reached
        //            expectedList.add(_implSubSubRole12); // no longer reached
        expectedList.add(_superClass);
        expectedList.add(_object);
        expectedList.add(_class);
        expectedList.add(_subClass1);
        //            expectedList.add(_subClass2); // still outside
        expectedList.add(_subSubClass11);

        IType[] expected = expectedList.toArray(new IType[expectedList.size()]);
        IType[] actual = _hierarchy.getAllTypes();

        assertEquals(expected.length, actual.length);
        assertTrue(compareTypes(expected, actual));
    } finally {
        _hierarchy = new TypeHierarchy(_focusRole, null, _focusRole.getJavaProject(), true);
        _hierarchy.refresh(new NullProgressMonitor());
    }
}

From source file:org.eclipse.objectteams.otdt.tests.hierarchy.CompleteRoleHierarchyWithClasses.java

License:Open Source License

public void testGetAllSuperclasses_ofImplSubRole2_withFocus() throws JavaModelException {
    try {/*from   ww w  .j a  v  a2 s. c  o  m*/
        _hierarchy = new TypeHierarchy(_implSubRole2, null, _implSubRole2.getJavaProject(), true);
        _hierarchy.refresh(null);
        ArrayList<IType> expectedList = new ArrayList<IType>();
        expectedList.add(_implSuperSuperRole);
        expectedList.add(_implSuperRole);
        expectedList.add(_focusRole);
        expectedList.add(_superClass);
        expectedList.add(_class);
        expectedList.add(_subClass1);
        expectedList.add(_subSubClass11);
        expectedList.add(_object);

        IType[] expected = expectedList.toArray(new IType[expectedList.size()]);
        IType[] actual = _hierarchy.getAllSuperclasses((IType) _implSubRole2.getCorrespondingJavaElement());

        assertEquals(expected.length, actual.length);
        assertTrue(compareTypes(expected, actual));
    } finally {
        _hierarchy = new TypeHierarchy(_focusRole, null, _focusRole.getJavaProject(), true);
        _hierarchy.refresh(new NullProgressMonitor());
    }
}

From source file:org.eclipse.objectteams.otdt.tests.hierarchy.CompleteRoleHierarchyWithClasses.java

License:Open Source License

public void testGetAllSuperclasses_ofImplSubSubRole12_withFocus() throws JavaModelException {
    try {/* w ww  . j a v  a 2 s . c  o  m*/
        _hierarchy = new TypeHierarchy(_implSubSubRole12, null, _implSubSubRole12.getJavaProject(), true);
        _hierarchy.refresh(null);

        ArrayList<IType> expectedList = new ArrayList<IType>();
        expectedList.add(_implSuperSuperRole);
        expectedList.add(_implSuperRole);
        expectedList.add(_focusRole);
        expectedList.add(_implSubRole1);
        expectedList.add(_superClass);
        expectedList.add(_class);
        expectedList.add(_subClass1);
        expectedList.add(_object);

        IType[] expected = expectedList.toArray(new IType[expectedList.size()]);
        IType[] actual = _hierarchy.getAllSuperclasses((IType) _implSubSubRole12.getCorrespondingJavaElement());

        assertEquals(expected.length, actual.length);
        assertTrue(compareTypes(expected, actual));
    } finally {
        _hierarchy = new TypeHierarchy(_focusRole, null, _focusRole.getJavaProject(), true);
        _hierarchy.refresh(new NullProgressMonitor());
    }
}

From source file:org.eclipse.objectteams.otdt.tests.hierarchy.FileBasedHierarchyTest.java

License:Open Source License

private ITypeHierarchy createTypeHierarchy(IType focusType, boolean computeSubtypes) throws JavaModelException {
    ITypeHierarchy hierarchy = new TypeHierarchy(focusType, null, focusType.getJavaProject(), computeSubtypes);
    hierarchy.refresh(new NullProgressMonitor());
    return hierarchy;
}