View | Details | Raw Unified | Return to bug 120667
Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java (+45 lines)
Lines 149-154 Link Here
149
		"	public int compareTo(CycleChild o) { return 0; }\n" +
149
		"	public int compareTo(CycleChild o) { return 0; }\n" +
150
		"}"
150
		"}"
151
	);
151
	);
152
	createFile(
153
		"/TypeHierarchy15/src/Try.java", 
154
		"public enum Try {\n" + 
155
		"    THIS,\n" + 
156
		"    THAT(),\n" + 
157
		"    ANONYMOUS() {}\n" + 
158
		"}"
159
	);
160
	
152
}
161
}
153
162
154
/* (non-Javadoc)
163
/* (non-Javadoc)
Lines 271-276 Link Here
271
	IType[] subtypes = hierarchy.getSubtypes(type);
280
	IType[] subtypes = hierarchy.getSubtypes(type);
272
	assertEquals("Unexpected key", "Lmy/pkg/Y$1;", subtypes.length < 1 ? null : subtypes[0].getKey());
281
	assertEquals("Unexpected key", "Lmy/pkg/Y$1;", subtypes.length < 1 ? null : subtypes[0].getKey());
273
}
282
}
283
/*
284
 * Ensure that hierarchy on an enum also include the anonymous of its enum contants
285
 * (regression test for bug 120667 [hierarchy] Type hierarchy for enum type does not include anonymous subtypes)
286
 */
287
public void testAnonymousType8() throws CoreException {
288
	IType type = getCompilationUnit("TypeHierarchy15/src/Try.java").getType("Try");
289
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
290
	assertHierarchyEquals(
291
		"Focus: Try [in Try.java [in <default> [in src [in TypeHierarchy15]]]]\n" + 
292
		"Super types:\n" + 
293
		"  Enum [in Enum.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" + 
294
		"    Comparable [in Comparable.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" + 
295
		"    Object [in Object.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" + 
296
		"    Serializable [in Serializable.class [in java.io [in "+ getExternalJCLPathString("1.5") + "]]]\n" + 
297
		"Sub types:\n" + 
298
		"  <anonymous #1> [in ANONYMOUS [in Try [in Try.java [in <default> [in src [in TypeHierarchy15]]]]]]\n",
299
		hierarchy);
300
}
301
/*
302
 * Ensure that hierarchy on the anonymous type of an enum constant is correct
303
 * (regression test for bug 120667 [hierarchy] Type hierarchy for enum type does not include anonymous subtypes)
304
 */
305
public void testAnonymousType9() throws CoreException {
306
	IType type = getCompilationUnit("TypeHierarchy15/src/Try.java").getType("Try").getField("ANONYMOUS").getType("", 1);
307
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
308
	assertHierarchyEquals(
309
		"Focus: <anonymous #1> [in ANONYMOUS [in Try [in Try.java [in <default> [in src [in TypeHierarchy15]]]]]]\n" + 
310
		"Super types:\n" + 
311
		"  Try [in Try.java [in <default> [in src [in TypeHierarchy15]]]]\n" + 
312
		"    Enum [in Enum.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" + 
313
		"      Comparable [in Comparable.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" + 
314
		"      Object [in Object.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" + 
315
		"      Serializable [in Serializable.class [in java.io [in "+ getExternalJCLPathString("1.5") + "]]]\n" + 
316
		"Sub types:\n",
317
		hierarchy);
318
}
274
/**
319
/**
275
 * Ensures that the superclass can be retrieved for a binary inner type.
320
 * Ensures that the superclass can be retrieved for a binary inner type.
276
 */
321
 */
(-)model/org/eclipse/jdt/internal/compiler/parser/SourceTypeConverter.java (-10 / +19 lines)
Lines 248-274 Link Here
248
		if ((this.flags & LOCAL_TYPE) != 0) {
248
		if ((this.flags & LOCAL_TYPE) != 0) {
249
			IJavaElement[] children = fieldInfo.getChildren();
249
			IJavaElement[] children = fieldInfo.getChildren();
250
			int childrenLength = children.length;
250
			int childrenLength = children.length;
251
			if (childrenLength > 0) {
251
			if (childrenLength == 1) {
252
				field.initialization = convert(children[0], isEnumConstant ? field : null, compilationResult);
253
			} else if (childrenLength > 1) {
252
				ArrayInitializer initializer = new ArrayInitializer();
254
				ArrayInitializer initializer = new ArrayInitializer();
253
				field.initialization = initializer;
255
				field.initialization = initializer;
254
				Expression[] expressions = new Expression[childrenLength];
256
				Expression[] expressions = new Expression[childrenLength];
255
				initializer.expressions = expressions;
257
				initializer.expressions = expressions;
256
				for (int i = 0; i < childrenLength; i++) {
258
				for (int i = 0; i < childrenLength; i++) {
257
					IJavaElement localType = children[i];
259
					expressions[i] = convert(children[i], isEnumConstant ? field : null, compilationResult);
258
					TypeDeclaration anonymousLocalTypeDeclaration = convert((SourceType) localType, compilationResult);
259
					QualifiedAllocationExpression expression = new QualifiedAllocationExpression(anonymousLocalTypeDeclaration);
260
					expression.type = anonymousLocalTypeDeclaration.superclass;
261
					anonymousLocalTypeDeclaration.superclass = null;
262
					anonymousLocalTypeDeclaration.superInterfaces = null;
263
					anonymousLocalTypeDeclaration.allocation = expression;
264
					anonymousLocalTypeDeclaration.modifiers &= ~ClassFileConstants.AccEnum; // remove tag in case this is the init of an enum constant
265
					expressions[i] = expression;
266
				}
260
				}
267
			}
261
			}
268
		}
262
		}
269
		return field;
263
		return field;
270
	}
264
	}
271
265
266
	private QualifiedAllocationExpression convert(IJavaElement localType, FieldDeclaration enumConstant, CompilationResult compilationResult) throws JavaModelException {
267
		TypeDeclaration anonymousLocalTypeDeclaration = convert((SourceType) localType, compilationResult);
268
		QualifiedAllocationExpression expression = new QualifiedAllocationExpression(anonymousLocalTypeDeclaration);
269
		expression.type = anonymousLocalTypeDeclaration.superclass;
270
		anonymousLocalTypeDeclaration.superclass = null;
271
		anonymousLocalTypeDeclaration.superInterfaces = null;
272
		anonymousLocalTypeDeclaration.allocation = expression;
273
		if (enumConstant != null) {
274
			anonymousLocalTypeDeclaration.modifiers &= ~ClassFileConstants.AccEnum;
275
			expression.enumConstant = enumConstant;
276
			expression.type = null;
277
		}
278
		return expression;
279
	}
280
272
	/*
281
	/*
273
	 * Convert a method source element into a parsed method/constructor declaration 
282
	 * Convert a method source element into a parsed method/constructor declaration 
274
	 */
283
	 */
(-)search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java (-1 / +3 lines)
Lines 14-19 Link Here
14
import org.eclipse.jdt.core.compiler.*;
14
import org.eclipse.jdt.core.compiler.*;
15
import org.eclipse.jdt.internal.compiler.ISourceElementRequestor;
15
import org.eclipse.jdt.internal.compiler.ISourceElementRequestor;
16
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
16
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
17
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
17
import org.eclipse.jdt.internal.core.search.processing.JobManager;
18
import org.eclipse.jdt.internal.core.search.processing.JobManager;
18
19
19
/**
20
/**
Lines 196-202 Link Here
196
	} else {
197
	} else {
197
		typeNames = this.enclosingTypeNames();
198
		typeNames = this.enclosingTypeNames();
198
	}
199
	}
199
	this.indexer.addEnumDeclaration(typeInfo.modifiers, packageName, typeInfo.name, typeNames, typeInfo.superinterfaces, typeInfo.secondary);
200
	char[] superclass = typeInfo.superclass == null ? CharOperation.concatWith(TypeConstants.JAVA_LANG_ENUM, '.'): typeInfo.superclass;
201
	this.indexer.addEnumDeclaration(typeInfo.modifiers, packageName, typeInfo.name, typeNames, superclass, typeInfo.superinterfaces, typeInfo.secondary);
200
	this.pushTypeName(typeInfo.name);	
202
	this.pushTypeName(typeInfo.name);	
201
}
203
}
202
/**
204
/**
(-)search/org/eclipse/jdt/internal/core/search/indexing/AbstractIndexer.java (-2 / +2 lines)
Lines 89-102 Link Here
89
		if (innermostTypeName != simpleTypeName)
89
		if (innermostTypeName != simpleTypeName)
90
			addIndexEntry(CONSTRUCTOR_REF, ConstructorPattern.createIndexKey(innermostTypeName, argCount));
90
			addIndexEntry(CONSTRUCTOR_REF, ConstructorPattern.createIndexKey(innermostTypeName, argCount));
91
	}
91
	}
92
	public void addEnumDeclaration(int modifiers, char[] packageName, char[] name, char[][] enclosingTypeNames, char[][] superinterfaces, boolean secondary) {
92
	public void addEnumDeclaration(int modifiers, char[] packageName, char[] name, char[][] enclosingTypeNames, char[] superclass, char[][] superinterfaces, boolean secondary) {
93
		char[] indexKey = TypeDeclarationPattern.createIndexKey(modifiers, name, packageName, enclosingTypeNames, secondary);
93
		char[] indexKey = TypeDeclarationPattern.createIndexKey(modifiers, name, packageName, enclosingTypeNames, secondary);
94
		addIndexEntry(TYPE_DECL, indexKey);
94
		addIndexEntry(TYPE_DECL, indexKey);
95
95
96
		addIndexEntry(
96
		addIndexEntry(
97
			SUPER_REF, 
97
			SUPER_REF, 
98
			SuperTypeReferencePattern.createIndexKey(
98
			SuperTypeReferencePattern.createIndexKey(
99
				modifiers, packageName, name, enclosingTypeNames, null, ENUM_SUFFIX, CharOperation.concatWith(TypeConstants.JAVA_LANG_ENUM, '.'), CLASS_SUFFIX));
99
				modifiers, packageName, name, enclosingTypeNames, null, ENUM_SUFFIX, superclass, CLASS_SUFFIX));
100
		if (superinterfaces != null) {
100
		if (superinterfaces != null) {
101
			for (int i = 0, max = superinterfaces.length; i < max; i++) {
101
			for (int i = 0, max = superinterfaces.length; i < max; i++) {
102
				char[] superinterface = erasure(superinterfaces[i]);
102
				char[] superinterface = erasure(superinterfaces[i]);
(-)search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java (-1 / +2 lines)
Lines 677-683 Link Here
677
					addInterfaceDeclaration(modifiers, packageName, name, enclosingTypeNames, superinterfaces, typeParameterSignatures, false);
677
					addInterfaceDeclaration(modifiers, packageName, name, enclosingTypeNames, superinterfaces, typeParameterSignatures, false);
678
					break;
678
					break;
679
				case TypeDeclaration.ENUM_DECL :
679
				case TypeDeclaration.ENUM_DECL :
680
					addEnumDeclaration(modifiers, packageName, name, enclosingTypeNames, superinterfaces, false);
680
					superclass = replace('/', '.', reader.getSuperclassName());
681
					addEnumDeclaration(modifiers, packageName, name, enclosingTypeNames, superclass, superinterfaces, false);
681
					break;
682
					break;
682
				case TypeDeclaration.ANNOTATION_TYPE_DECL :
683
				case TypeDeclaration.ANNOTATION_TYPE_DECL :
683
					addAnnotationTypeDeclaration(modifiers, packageName, name, enclosingTypeNames, false);
684
					addAnnotationTypeDeclaration(modifiers, packageName, name, enclosingTypeNames, false);
(-)search/org/eclipse/jdt/internal/core/index/DiskIndex.java (-1 / +1 lines)
Lines 37-43 Link Here
37
private HashtableOfObject categoryTables; // category name -> HashtableOfObject(words -> int[] of document #'s) or offset if not read yet
37
private HashtableOfObject categoryTables; // category name -> HashtableOfObject(words -> int[] of document #'s) or offset if not read yet
38
private char[] cachedCategoryName;
38
private char[] cachedCategoryName;
39
39
40
public static final String SIGNATURE= "INDEX VERSION 1.112"; //$NON-NLS-1$
40
public static final String SIGNATURE= "INDEX VERSION 1.113"; //$NON-NLS-1$
41
public static boolean DEBUG = false;
41
public static boolean DEBUG = false;
42
42
43
private static final int RE_INDEXED = -1;
43
private static final int RE_INDEXED = -1;

Return to bug 120667