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 --- src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java 14 Jun 2006 10:53:55 -0000 1.59 +++ src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java 14 Jun 2006 16:40:26 -0000 @@ -149,6 +149,15 @@ " public int compareTo(CycleChild o) { return 0; }\n" + "}" ); + createFile( + "/TypeHierarchy15/src/Try.java", + "public enum Try {\n" + + " THIS,\n" + + " THAT(),\n" + + " ANONYMOUS() {}\n" + + "}" + ); + } /* (non-Javadoc) @@ -271,6 +280,42 @@ IType[] subtypes = hierarchy.getSubtypes(type); assertEquals("Unexpected key", "Lmy/pkg/Y$1;", subtypes.length < 1 ? null : subtypes[0].getKey()); } +/* + * Ensure that hierarchy on an enum also include the anonymous of its enum contants + * (regression test for bug 120667 [hierarchy] Type hierarchy for enum type does not include anonymous subtypes) + */ +public void testAnonymousType8() throws CoreException { + IType type = getCompilationUnit("TypeHierarchy15/src/Try.java").getType("Try"); + ITypeHierarchy hierarchy = type.newTypeHierarchy(null); + assertHierarchyEquals( + "Focus: Try [in Try.java [in [in src [in TypeHierarchy15]]]]\n" + + "Super types:\n" + + " Enum [in Enum.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" + + " Comparable [in Comparable.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" + + " Object [in Object.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" + + " Serializable [in Serializable.class [in java.io [in "+ getExternalJCLPathString("1.5") + "]]]\n" + + "Sub types:\n" + + " [in ANONYMOUS [in Try [in Try.java [in [in src [in TypeHierarchy15]]]]]]\n", + hierarchy); +} +/* + * Ensure that hierarchy on the anonymous type of an enum constant is correct + * (regression test for bug 120667 [hierarchy] Type hierarchy for enum type does not include anonymous subtypes) + */ +public void testAnonymousType9() throws CoreException { + IType type = getCompilationUnit("TypeHierarchy15/src/Try.java").getType("Try").getField("ANONYMOUS").getType("", 1); + ITypeHierarchy hierarchy = type.newTypeHierarchy(null); + assertHierarchyEquals( + "Focus: [in ANONYMOUS [in Try [in Try.java [in [in src [in TypeHierarchy15]]]]]]\n" + + "Super types:\n" + + " Try [in Try.java [in [in src [in TypeHierarchy15]]]]\n" + + " Enum [in Enum.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" + + " Comparable [in Comparable.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" + + " Object [in Object.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" + + " Serializable [in Serializable.class [in java.io [in "+ getExternalJCLPathString("1.5") + "]]]\n" + + "Sub types:\n", + hierarchy); +} /** * Ensures that the superclass can be retrieved for a binary inner type. */ Index: model/org/eclipse/jdt/internal/compiler/parser/SourceTypeConverter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/parser/SourceTypeConverter.java,v --- model/org/eclipse/jdt/internal/compiler/parser/SourceTypeConverter.java 24 Apr 2006 15:04:29 -0000 1.47 +++ model/org/eclipse/jdt/internal/compiler/parser/SourceTypeConverter.java 14 Jun 2006 16:40:28 -0000 @@ -248,27 +248,36 @@ if ((this.flags & LOCAL_TYPE) != 0) { IJavaElement[] children = fieldInfo.getChildren(); int childrenLength = children.length; - if (childrenLength > 0) { + if (childrenLength == 1) { + field.initialization = convert(children[0], isEnumConstant ? field : null, compilationResult); + } else if (childrenLength > 1) { ArrayInitializer initializer = new ArrayInitializer(); field.initialization = initializer; Expression[] expressions = new Expression[childrenLength]; initializer.expressions = expressions; for (int i = 0; i < childrenLength; i++) { - IJavaElement localType = children[i]; - TypeDeclaration anonymousLocalTypeDeclaration = convert((SourceType) localType, compilationResult); - QualifiedAllocationExpression expression = new QualifiedAllocationExpression(anonymousLocalTypeDeclaration); - expression.type = anonymousLocalTypeDeclaration.superclass; - anonymousLocalTypeDeclaration.superclass = null; - anonymousLocalTypeDeclaration.superInterfaces = null; - anonymousLocalTypeDeclaration.allocation = expression; - anonymousLocalTypeDeclaration.modifiers &= ~ClassFileConstants.AccEnum; // remove tag in case this is the init of an enum constant - expressions[i] = expression; + expressions[i] = convert(children[i], isEnumConstant ? field : null, compilationResult); } } } return field; } + private QualifiedAllocationExpression convert(IJavaElement localType, FieldDeclaration enumConstant, CompilationResult compilationResult) throws JavaModelException { + TypeDeclaration anonymousLocalTypeDeclaration = convert((SourceType) localType, compilationResult); + QualifiedAllocationExpression expression = new QualifiedAllocationExpression(anonymousLocalTypeDeclaration); + expression.type = anonymousLocalTypeDeclaration.superclass; + anonymousLocalTypeDeclaration.superclass = null; + anonymousLocalTypeDeclaration.superInterfaces = null; + anonymousLocalTypeDeclaration.allocation = expression; + if (enumConstant != null) { + anonymousLocalTypeDeclaration.modifiers &= ~ClassFileConstants.AccEnum; + expression.enumConstant = enumConstant; + expression.type = null; + } + return expression; + } + /* * Convert a method source element into a parsed method/constructor declaration */ Index: search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java,v --- search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java 29 Mar 2006 03:13:59 -0000 1.39 +++ search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java 14 Jun 2006 16:40:29 -0000 @@ -14,6 +14,7 @@ import org.eclipse.jdt.core.compiler.*; import org.eclipse.jdt.internal.compiler.ISourceElementRequestor; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; +import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; import org.eclipse.jdt.internal.core.search.processing.JobManager; /** @@ -196,7 +197,8 @@ } else { typeNames = this.enclosingTypeNames(); } - this.indexer.addEnumDeclaration(typeInfo.modifiers, packageName, typeInfo.name, typeNames, typeInfo.superinterfaces, typeInfo.secondary); + char[] superclass = typeInfo.superclass == null ? CharOperation.concatWith(TypeConstants.JAVA_LANG_ENUM, '.'): typeInfo.superclass; + this.indexer.addEnumDeclaration(typeInfo.modifiers, packageName, typeInfo.name, typeNames, superclass, typeInfo.superinterfaces, typeInfo.secondary); this.pushTypeName(typeInfo.name); } /** Index: search/org/eclipse/jdt/internal/core/search/indexing/AbstractIndexer.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/AbstractIndexer.java,v --- search/org/eclipse/jdt/internal/core/search/indexing/AbstractIndexer.java 29 Mar 2006 03:13:59 -0000 1.35 +++ search/org/eclipse/jdt/internal/core/search/indexing/AbstractIndexer.java 14 Jun 2006 16:40:28 -0000 @@ -89,14 +89,14 @@ if (innermostTypeName != simpleTypeName) addIndexEntry(CONSTRUCTOR_REF, ConstructorPattern.createIndexKey(innermostTypeName, argCount)); } - public void addEnumDeclaration(int modifiers, char[] packageName, char[] name, char[][] enclosingTypeNames, char[][] superinterfaces, boolean secondary) { + public void addEnumDeclaration(int modifiers, char[] packageName, char[] name, char[][] enclosingTypeNames, char[] superclass, char[][] superinterfaces, boolean secondary) { char[] indexKey = TypeDeclarationPattern.createIndexKey(modifiers, name, packageName, enclosingTypeNames, secondary); addIndexEntry(TYPE_DECL, indexKey); addIndexEntry( SUPER_REF, SuperTypeReferencePattern.createIndexKey( - modifiers, packageName, name, enclosingTypeNames, null, ENUM_SUFFIX, CharOperation.concatWith(TypeConstants.JAVA_LANG_ENUM, '.'), CLASS_SUFFIX)); + modifiers, packageName, name, enclosingTypeNames, null, ENUM_SUFFIX, superclass, CLASS_SUFFIX)); if (superinterfaces != null) { for (int i = 0, max = superinterfaces.length; i < max; i++) { char[] superinterface = erasure(superinterfaces[i]); Index: search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java,v --- search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java 8 Jun 2006 13:08:58 -0000 1.55 +++ search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java 14 Jun 2006 16:40:29 -0000 @@ -677,7 +677,8 @@ addInterfaceDeclaration(modifiers, packageName, name, enclosingTypeNames, superinterfaces, typeParameterSignatures, false); break; case TypeDeclaration.ENUM_DECL : - addEnumDeclaration(modifiers, packageName, name, enclosingTypeNames, superinterfaces, false); + superclass = replace('/', '.', reader.getSuperclassName()); + addEnumDeclaration(modifiers, packageName, name, enclosingTypeNames, superclass, superinterfaces, false); break; case TypeDeclaration.ANNOTATION_TYPE_DECL : addAnnotationTypeDeclaration(modifiers, packageName, name, enclosingTypeNames, false); Index: search/org/eclipse/jdt/internal/core/index/DiskIndex.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/index/DiskIndex.java,v --- search/org/eclipse/jdt/internal/core/index/DiskIndex.java 8 Jun 2006 13:08:58 -0000 1.50 +++ search/org/eclipse/jdt/internal/core/index/DiskIndex.java 14 Jun 2006 16:40:28 -0000 @@ -37,7 +37,7 @@ private HashtableOfObject categoryTables; // category name -> HashtableOfObject(words -> int[] of document #'s) or offset if not read yet private char[] cachedCategoryName; -public static final String SIGNATURE= "INDEX VERSION 1.112"; //$NON-NLS-1$ +public static final String SIGNATURE= "INDEX VERSION 1.113"; //$NON-NLS-1$ public static boolean DEBUG = false; private static final int RE_INDEXED = -1;