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

(-)model/org/eclipse/jdt/internal/compiler/ISourceElementRequestor.java (+1 lines)
Lines 50-55 Link Here
50
		public long[] annotationPositions;
50
		public long[] annotationPositions;
51
		public char[][] categories;
51
		public char[][] categories;
52
		public boolean secondary;
52
		public boolean secondary;
53
		public boolean anonymousMember;
53
	}
54
	}
54
	
55
	
55
	public static class TypeParameterInfo {
56
	public static class TypeParameterInfo {
(-)model/org/eclipse/jdt/internal/compiler/SourceElementParser.java (+1 lines)
Lines 1400-1405 Link Here
1400
			typeInfo.annotationPositions = collectAnnotationPositions(typeDeclaration.annotations);
1400
			typeInfo.annotationPositions = collectAnnotationPositions(typeDeclaration.annotations);
1401
			typeInfo.categories = (char[][]) this.nodesToCategories.get(typeDeclaration);
1401
			typeInfo.categories = (char[][]) this.nodesToCategories.get(typeDeclaration);
1402
			typeInfo.secondary = typeDeclaration.isSecondary();
1402
			typeInfo.secondary = typeDeclaration.isSecondary();
1403
			typeInfo.anonymousMember = typeDeclaration.allocation != null && typeDeclaration.allocation.enclosingInstance != null;
1403
			requestor.enterType(typeInfo);
1404
			requestor.enterType(typeInfo);
1404
			switch (kind) {
1405
			switch (kind) {
1405
				case TypeDeclaration.CLASS_DECL :
1406
				case TypeDeclaration.CLASS_DECL :
(-)model/org/eclipse/jdt/internal/compiler/parser/SourceTypeConverter.java (-12 / +27 lines)
Lines 44-49 Link Here
44
import org.eclipse.jdt.internal.core.*;
44
import org.eclipse.jdt.internal.core.*;
45
45
46
public class SourceTypeConverter {
46
public class SourceTypeConverter {
47
	
48
	/* 
49
	 * Exception thrown while converting an anonymous type of a member type
50
	 * in this case, we must parse the source as the enclosing instance cannot be recreated
51
	 * from the model
52
	 */
53
	static class AnonymousMemberFound extends RuntimeException {
54
		private static final long serialVersionUID = 1L;
55
	}
47
56
48
	public static final int FIELD = 0x01;
57
	public static final int FIELD = 0x01;
49
	public static final int CONSTRUCTOR = 0x02;
58
	public static final int CONSTRUCTOR = 0x02;
Lines 138-156 Link Here
138
				sourceImport.getModifiers());
147
				sourceImport.getModifiers());
139
		}
148
		}
140
		/* convert type(s) */
149
		/* convert type(s) */
141
		int typeCount = sourceTypes.length;
150
		try {
142
		final TypeDeclaration[] types = new TypeDeclaration[typeCount];
151
			int typeCount = sourceTypes.length;
143
		/*
152
			final TypeDeclaration[] types = new TypeDeclaration[typeCount];
144
		 * We used a temporary types collection to prevent this.unit.types from being null during a call to
153
			/*
145
		 * convert(...) when the source is syntactically incorrect and the parser is flushing the unit's types.
154
			 * We used a temporary types collection to prevent this.unit.types from being null during a call to
146
		 * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=97466
155
			 * convert(...) when the source is syntactically incorrect and the parser is flushing the unit's types.
147
		 */
156
			 * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=97466
148
		for (int i = 0; i < typeCount; i++) {
157
			 */
149
			SourceTypeElementInfo typeInfo = (SourceTypeElementInfo) sourceTypes[i];
158
			for (int i = 0; i < typeCount; i++) {
150
			types[i] = convert((SourceType) typeInfo.getHandle(), compilationResult);
159
				SourceTypeElementInfo typeInfo = (SourceTypeElementInfo) sourceTypes[i];
160
				types[i] = convert((SourceType) typeInfo.getHandle(), compilationResult);
161
			}
162
			this.unit.types = types;
163
			return this.unit;
164
		} catch (AnonymousMemberFound e) {
165
			return new Parser(this.problemReporter, true).parse(this.cu, compilationResult);
151
		}
166
		}
152
		this.unit.types = types;
153
		return this.unit;
154
	}
167
	}
155
	
168
	
156
	private void addIdentifiers(String typeSignature, int start, int endExclusive, int identCount, ArrayList fragments) {
169
	private void addIdentifiers(String typeSignature, int start, int endExclusive, int identCount, ArrayList fragments) {
Lines 422-427 Link Here
422
	 */
435
	 */
423
	private TypeDeclaration convert(SourceType typeHandle, CompilationResult compilationResult) throws JavaModelException {
436
	private TypeDeclaration convert(SourceType typeHandle, CompilationResult compilationResult) throws JavaModelException {
424
		SourceTypeElementInfo typeInfo = (SourceTypeElementInfo) typeHandle.getElementInfo();
437
		SourceTypeElementInfo typeInfo = (SourceTypeElementInfo) typeHandle.getElementInfo();
438
		if (typeInfo.isAnonymousMember())
439
			throw new AnonymousMemberFound();
425
		/* create type declaration - can be member type */
440
		/* create type declaration - can be member type */
426
		TypeDeclaration type = new TypeDeclaration(compilationResult);
441
		TypeDeclaration type = new TypeDeclaration(compilationResult);
427
		if (typeInfo.getEnclosingType() == null) {
442
		if (typeInfo.getEnclosingType() == null) {
(-)model/org/eclipse/jdt/internal/core/SourceTypeElementInfo.java (+6 lines)
Lines 279-284 Link Here
279
public boolean isBinaryType() {
279
public boolean isBinaryType() {
280
	return false;
280
	return false;
281
}
281
}
282
/*
283
 * Returns whether the source type is an anonymous type of a member type.
284
 */
285
public boolean isAnonymousMember() {
286
	return false;
287
}
282
/**
288
/**
283
 * Sets the handle for this type info
289
 * Sets the handle for this type info
284
 */
290
 */
(-)model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java (-1 / +8 lines)
Lines 357-363 Link Here
357
	SourceType handle = new SourceType(parentHandle, nameString); //NB: occurenceCount is computed in resolveDuplicates
357
	SourceType handle = new SourceType(parentHandle, nameString); //NB: occurenceCount is computed in resolveDuplicates
358
	resolveDuplicates(handle);
358
	resolveDuplicates(handle);
359
	
359
	
360
	SourceTypeElementInfo info = new SourceTypeElementInfo();
360
	SourceTypeElementInfo info = 
361
		typeInfo.anonymousMember ? 
362
			new SourceTypeElementInfo() {
363
				public boolean isAnonymousMember() {
364
					return true;
365
				}
366
			} : 
367
		new SourceTypeElementInfo();
361
	info.setHandle(handle);
368
	info.setHandle(handle);
362
	info.setSourceRangeStart(typeInfo.declarationStart);
369
	info.setSourceRangeStart(typeInfo.declarationStart);
363
	info.setFlags(typeInfo.modifiers);
370
	info.setFlags(typeInfo.modifiers);
(-)src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java (-9 / +26 lines)
Lines 173-179 Link Here
173
/*
173
/*
174
 * Ensures that a hierarchy on an anonymous type in an initializer is correct.
174
 * Ensures that a hierarchy on an anonymous type in an initializer is correct.
175
 */
175
 */
176
public void testAnonymousType1() throws JavaModelException {
176
public void testAnonymousType01() throws JavaModelException {
177
	IType typeA = getCompilationUnit("TypeHierarchy", "src", "p7", "A.java").getType("A");
177
	IType typeA = getCompilationUnit("TypeHierarchy", "src", "p7", "A.java").getType("A");
178
	IType type = typeA.getInitializer(1).getType("", 1);
178
	IType type = typeA.getInitializer(1).getType("", 1);
179
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
179
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
Lines 188-194 Link Here
188
/*
188
/*
189
 * Ensures that a hierarchy on an anonymous type in a second initializer is correct.
189
 * Ensures that a hierarchy on an anonymous type in a second initializer is correct.
190
 */
190
 */
191
public void testAnonymousType2() throws JavaModelException {
191
public void testAnonymousType02() throws JavaModelException {
192
	IType typeA = getCompilationUnit("TypeHierarchy", "src", "p7", "A.java").getType("A");
192
	IType typeA = getCompilationUnit("TypeHierarchy", "src", "p7", "A.java").getType("A");
193
	IType type = typeA.getInitializer(2).getType("", 1);
193
	IType type = typeA.getInitializer(2).getType("", 1);
194
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
194
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
Lines 203-209 Link Here
203
/*
203
/*
204
 * Ensures that a hierarchy on an anonymous type in a field declaration is correct.
204
 * Ensures that a hierarchy on an anonymous type in a field declaration is correct.
205
 */
205
 */
206
public void testAnonymousType3() throws JavaModelException {
206
public void testAnonymousType03() throws JavaModelException {
207
	IType typeA = getCompilationUnit("TypeHierarchy", "src", "p7", "A.java").getType("A");
207
	IType typeA = getCompilationUnit("TypeHierarchy", "src", "p7", "A.java").getType("A");
208
	IType type = typeA.getField("field1").getType("", 1);
208
	IType type = typeA.getField("field1").getType("", 1);
209
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
209
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
Lines 218-224 Link Here
218
/*
218
/*
219
 * Ensures that a hierarchy on an anonymous type in a field declaration is correct.
219
 * Ensures that a hierarchy on an anonymous type in a field declaration is correct.
220
 */
220
 */
221
public void testAnonymousType4() throws JavaModelException {
221
public void testAnonymousType04() throws JavaModelException {
222
	IType typeA = getCompilationUnit("TypeHierarchy", "src", "p7", "A.java").getType("A");
222
	IType typeA = getCompilationUnit("TypeHierarchy", "src", "p7", "A.java").getType("A");
223
	IType type = typeA.getField("field2").getType("", 1);
223
	IType type = typeA.getField("field2").getType("", 1);
224
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
224
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
Lines 242-248 Link Here
242
/*
242
/*
243
 * Ensures that a hierarchy on an anonymous type in a method declaration is correct.
243
 * Ensures that a hierarchy on an anonymous type in a method declaration is correct.
244
 */
244
 */
245
public void testAnonymousType5() throws JavaModelException {
245
public void testAnonymousType05() throws JavaModelException {
246
	IType typeA = getCompilationUnit("TypeHierarchy", "src", "p7", "A.java").getType("A");
246
	IType typeA = getCompilationUnit("TypeHierarchy", "src", "p7", "A.java").getType("A");
247
	IType type = typeA.getMethod("foo", new String[] {}).getType("", 1);
247
	IType type = typeA.getMethod("foo", new String[] {}).getType("", 1);
248
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
248
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
Lines 258-264 Link Here
258
 * Ensures that a hierarchy on an anonymous type that uses a non-default constructor is correct.
258
 * Ensures that a hierarchy on an anonymous type that uses a non-default constructor is correct.
259
 * (regression test for bug 44506 Type hierarchy is missing anonymous type)
259
 * (regression test for bug 44506 Type hierarchy is missing anonymous type)
260
 */
260
 */
261
public void testAnonymousType6() throws JavaModelException {
261
public void testAnonymousType06() throws JavaModelException {
262
	IType typeA = getCompilationUnit("TypeHierarchy", "src", "p8", "X.java").getType("X");
262
	IType typeA = getCompilationUnit("TypeHierarchy", "src", "p8", "X.java").getType("X");
263
	IType type = typeA.getMethod("foo", new String[] {}).getType("", 1);
263
	IType type = typeA.getMethod("foo", new String[] {}).getType("", 1);
264
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
264
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
Lines 274-280 Link Here
274
 * Ensure that the key of an anonymous binary type in a hierarchy is correct.
274
 * Ensure that the key of an anonymous binary type in a hierarchy is correct.
275
 * (regression test for bug 93826 ArrayIndexOutOfBoundsException when opening type hierarchy)
275
 * (regression test for bug 93826 ArrayIndexOutOfBoundsException when opening type hierarchy)
276
 */
276
 */
277
public void testAnonymousType7() throws CoreException {
277
public void testAnonymousType07() throws CoreException {
278
	IType type = getClassFile("TypeHierarchy","myLib.jar", "my.pkg", "X.class").getType();
278
	IType type = getClassFile("TypeHierarchy","myLib.jar", "my.pkg", "X.class").getType();
279
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
279
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
280
	IType[] subtypes = hierarchy.getSubtypes(type);
280
	IType[] subtypes = hierarchy.getSubtypes(type);
Lines 284-290 Link Here
284
 * Ensure that hierarchy on an enum also include the anonymous of its enum contants
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)
285
 * (regression test for bug 120667 [hierarchy] Type hierarchy for enum type does not include anonymous subtypes)
286
 */
286
 */
287
public void testAnonymousType8() throws CoreException {
287
public void testAnonymousType08() throws CoreException {
288
	IType type = getCompilationUnit("TypeHierarchy15/src/Try.java").getType("Try");
288
	IType type = getCompilationUnit("TypeHierarchy15/src/Try.java").getType("Try");
289
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
289
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
290
	assertHierarchyEquals(
290
	assertHierarchyEquals(
Lines 302-308 Link Here
302
 * Ensure that hierarchy on the anonymous type of an enum constant is correct
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)
303
 * (regression test for bug 120667 [hierarchy] Type hierarchy for enum type does not include anonymous subtypes)
304
 */
304
 */
305
public void testAnonymousType9() throws CoreException {
305
public void testAnonymousType09() throws CoreException {
306
	IType type = getCompilationUnit("TypeHierarchy15/src/Try.java").getType("Try").getField("ANONYMOUS").getType("", 1);
306
	IType type = getCompilationUnit("TypeHierarchy15/src/Try.java").getType("Try").getField("ANONYMOUS").getType("", 1);
307
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
307
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
308
	assertHierarchyEquals(
308
	assertHierarchyEquals(
Lines 316-321 Link Here
316
		"Sub types:\n",
316
		"Sub types:\n",
317
		hierarchy);
317
		hierarchy);
318
}
318
}
319
/*
320
 * Ensure that hierarchy on the anonymous type of a member type that is opened is correct
321
 * (regression test for bug 122444 [hierarchy] Type hierarchy of inner member type misses anonymous subtypes)
322
 */
323
public void testAnonymousType10() throws CoreException {
324
	ICompilationUnit cu =  getCompilationUnit("TypeHierarchy/src/q7/X.java");
325
	cu.open(null);
326
	IType type = cu.getType("X").getType("Member");
327
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
328
	assertHierarchyEquals(
329
		"Focus: Member [in X [in X.java [in q7 [in src [in TypeHierarchy]]]]]\n" + 
330
		"Super types:\n" + 
331
		"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" + 
332
		"Sub types:\n" + 
333
		"  <anonymous #1> [in foo(X) [in Y [in X.java [in q7 [in src [in TypeHierarchy]]]]]]\n",
334
		hierarchy);
335
}
319
/**
336
/**
320
 * Ensures that the superclass can be retrieved for a binary inner type.
337
 * Ensures that the superclass can be retrieved for a binary inner type.
321
 */
338
 */
(-)workspace/TypeHierarchy/src/q7/X.java (+11 lines)
Added Link Here
1
package q7;
2
public class X {
3
    public class Member {
4
    }
5
}
6
class Y {
7
    void foo(X arg) {
8
        arg.new Member() {
9
        };
10
    } 
11
}

Return to bug 122444