### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/hierarchy/TypeHierarchy.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/hierarchy/TypeHierarchy.java,v retrieving revision 1.103 diff -u -r1.103 TypeHierarchy.java --- model/org/eclipse/jdt/internal/core/hierarchy/TypeHierarchy.java 27 Jun 2008 16:04:14 -0000 1.103 +++ model/org/eclipse/jdt/internal/core/hierarchy/TypeHierarchy.java 21 Aug 2008 16:48:26 -0000 @@ -438,54 +438,62 @@ * @see ITypeHierarchy */ public IType[] getAllSuperInterfaces(IType type) { - ArrayList supers = new ArrayList(); - if (this.typeToSuperInterfaces.get(type) == null) { + ArrayList supers = getAllSuperInterfaces0(type, null); + if (supers == null) return NO_TYPE; - } - getAllSuperInterfaces0(type, supers); IType[] superinterfaces = new IType[supers.size()]; supers.toArray(superinterfaces); return superinterfaces; } -private void getAllSuperInterfaces0(IType type, ArrayList supers) { +private ArrayList getAllSuperInterfaces0(IType type, ArrayList supers) { IType[] superinterfaces = (IType[]) this.typeToSuperInterfaces.get(type); - if (superinterfaces != null && superinterfaces.length != 0) { + if (superinterfaces == null) // type is not part of the hierarchy + return supers; + if (superinterfaces.length != 0) { + if (supers == null) + supers = new ArrayList(); addAllCheckingDuplicates(supers, superinterfaces); for (int i = 0; i < superinterfaces.length; i++) { - getAllSuperInterfaces0(superinterfaces[i], supers); + supers = getAllSuperInterfaces0(superinterfaces[i], supers); } } IType superclass = (IType) this.classToSuperclass.get(type); if (superclass != null) { - getAllSuperInterfaces0(superclass, supers); + supers = getAllSuperInterfaces0(superclass, supers); } + return supers; } /** * @see ITypeHierarchy */ public IType[] getAllSupertypes(IType type) { - ArrayList supers = new ArrayList(); - if (this.typeToSuperInterfaces.get(type) == null) { + ArrayList supers = getAllSupertypes0(type, null); + if (supers == null) return NO_TYPE; - } - getAllSupertypes0(type, supers); IType[] supertypes = new IType[supers.size()]; supers.toArray(supertypes); return supertypes; } -private void getAllSupertypes0(IType type, ArrayList supers) { +private ArrayList getAllSupertypes0(IType type, ArrayList supers) { IType[] superinterfaces = (IType[]) this.typeToSuperInterfaces.get(type); - if (superinterfaces != null && superinterfaces.length != 0) { + if (superinterfaces == null) // type is not part of the hierarchy + return supers; + if (superinterfaces.length != 0) { + if (supers == null) + supers = new ArrayList(); addAllCheckingDuplicates(supers, superinterfaces); for (int i = 0; i < superinterfaces.length; i++) { - getAllSuperInterfaces0(superinterfaces[i], supers); + supers = getAllSuperInterfaces0(superinterfaces[i], supers); } } IType superclass = (IType) this.classToSuperclass.get(type); if (superclass != null) { + if (supers == null) + supers = new ArrayList(); supers.add(superclass); - getAllSupertypes0(superclass, supers); + supers = getAllSupertypes0(superclass, supers); } + return supers; } /** * @see ITypeHierarchy #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java,v retrieving revision 1.90 diff -u -r1.90 TypeHierarchyTests.java --- src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java 27 Jun 2008 16:02:38 -0000 1.90 +++ src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java 21 Aug 2008 16:48:30 -0000 @@ -1240,6 +1240,34 @@ types); } /** + * Ensures that the correct supertypes of a type exist in the type + * hierarchy. + * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=239096 ) + */ +public void testGetAllSupertypes3() throws JavaModelException { + IType type = getCompilationUnit("TypeHierarchy", "src", "p1", "A.java").getType("B"); + ITypeHierarchy hierarchy = type.newTypeHierarchy(null); + IType[] types = hierarchy.getAllSupertypes(type); + assertTypesEqual( + "Unexpected all super types of B", + "java.lang.Object\n", + types); +} +/** + * Ensures that the correct supertypes of a type exist in the type + * hierarchy. + * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=239096 ) + */ +public void testGetAllSupertypes4() throws JavaModelException { + IType type = getCompilationUnit("TypeHierarchy", "src", "p1", "A.java").getType("B"); + ITypeHierarchy hierarchy = type.newTypeHierarchy(null); + IType[] types = hierarchy.getAllSuperInterfaces(type); + assertTypesEqual( + "Unexpected all super interfaces of B", + "", + types); +} +/** * Ensures that the correct types exist in the type * hierarchy. */