View | Details | Raw Unified | Return to bug 254738 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java (+53 lines)
Lines 2351-2354 Link Here
2351
		project.setRawClasspath(originalClasspath, null);
2351
		project.setRawClasspath(originalClasspath, null);
2352
	}
2352
	}
2353
}
2353
}
2354
/**
2355
 * @bug 254738: NPE in HierarchyResolver.setFocusType
2356
 * @test that a nested method/anonymous sub type is included in the hierarchy when the number of annotations > 10
2357
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=254738"
2358
 */
2359
public void testBug254738() throws CoreException {
2360
	try {
2361
		createJavaProject("P", new String[] {"src"}, new String[] {}, "bin", "1.5");
2362
		createFolder("/P/src/abc");
2363
		createFile(
2364
			"/P/src/abc/Parent.java",
2365
			"package abc;\n" +
2366
			"public class Parent {\n" +
2367
			"	public void parentmethod() {\n" +
2368
			"   	new Object() {\n" +
2369
			"			void nestedonemethod() {\n" +
2370
			"           	new Object(){\n" +
2371
			"               	public int hashCode() {\n" +
2372
			"                   	return 0; \n" +
2373
			"                   } \n" +
2374
			"				}; \n" +
2375
			"         	}\n" +
2376
			"   	};\n" +
2377
			"	}\n" +
2378
			"}\n" +
2379
			"@Deprecated\n" +
2380
			"class Dep {\n" +
2381
			"        @Deprecated void a() {}\n" +
2382
			"        @Deprecated void b() {}\n" +
2383
			"        @Deprecated void c() {}\n" +
2384
			"        @Deprecated void d() {}\n" +
2385
			"        @Deprecated void e() {}\n" +
2386
			"        @Deprecated void f() {}\n" +
2387
			"        @Deprecated void g() {}\n" +
2388
			"        @Deprecated void h() {}\n" +
2389
			"        @Deprecated void i() {}\n" +
2390
			"        @Deprecated void j() {}\n" +
2391
			"        @Deprecated void k() {}\n" +
2392
			"}"
2393
			);
2394
		IType focus  = getCompilationUnit("/P/src/abc/Parent.java").getType("Parent");
2395
		focus =	focus.getMethod("parentmethod", new String[]{}).getType("", 1).getMethod("nestedonemethod", new String[]{}).
2396
												getType("", 1);
2397
		ITypeHierarchy hierarchy = focus.newTypeHierarchy(null);
2398
		assertHierarchyEquals(
2399
				"Focus: <anonymous #1> [in nestedonemethod() [in <anonymous #1> [in parentmethod() [in Parent [in Parent.java [in abc [in src [in P]]]]]]]]\n" + 
2400
				"Super types:\n" + 
2401
				"Sub types:\n",
2402
			hierarchy);
2403
	} finally {
2404
		deleteProjects(new String[] {"P"});
2405
	}
2406
}
2354
}
2407
}
(-)model/org/eclipse/jdt/internal/compiler/parser/SourceTypeConverter.java (-1 / +4 lines)
Lines 114-120 Link Here
114
114
115
		if (this.has1_5Compliance && ((CompilationUnitElementInfo) ((JavaElement) this.cu).getElementInfo()).annotationNumber > 10) { // experimental value
115
		if (this.has1_5Compliance && ((CompilationUnitElementInfo) ((JavaElement) this.cu).getElementInfo()).annotationNumber > 10) { // experimental value
116
			// if more than 10 annotations, diet parse as this is faster
116
			// if more than 10 annotations, diet parse as this is faster
117
			return new Parser(this.problemReporter, true).dietParse(this.cu, compilationResult);
117
			// Diet parse only if METHOD flag is not set (https://bugs.eclipse.org/bugs/show_bug.cgi?id=254738) 
118
			if ((this.flags & METHOD) == 0) {
119
				return new Parser(this.problemReporter, true).dietParse(this.cu, compilationResult);
120
			}
118
		}
121
		}
119
122
120
		/* only positions available */
123
		/* only positions available */
(-)model/org/eclipse/jdt/internal/core/hierarchy/HierarchyResolver.java (-2 / +6 lines)
Lines 645-651 Link Here
645
				CompilationUnitDeclaration parsedUnit = null;
645
				CompilationUnitDeclaration parsedUnit = null;
646
				if (cu.isOpen()) {
646
				if (cu.isOpen()) {
647
					// create parsed unit from source element infos
647
					// create parsed unit from source element infos
648
					CompilationResult result = new CompilationResult(((ICompilationUnit)cu).getFileName(), i, openablesLength, this.options.maxProblemsPerUnit);
648
					// As part of fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=254738
649
					// Since we have the handle to the ICompilationUnit, instead of the name pass the ICompilationUnit, which is required if we were 
650
					// to get through Parser.getMethodBodies(), which is invoked later in this method. Note that as part of this fix,
651
					// ASTNode.HasAllMethodBodies flag - which was being set earlier - has been removed. As a design feature, only the Parser 
652
					// is supposed to handle this particular bit.
653
					CompilationResult result = new CompilationResult((ICompilationUnit)cu, i, openablesLength, this.options.maxProblemsPerUnit);
649
					SourceTypeElementInfo[] typeInfos = null;
654
					SourceTypeElementInfo[] typeInfos = null;
650
					try {
655
					try {
651
						IType[] topLevelTypes = cu.getTypes();
656
						IType[] topLevelTypes = cu.getTypes();
Lines 668-674 Link Here
668
							flags,
673
							flags,
669
							this.lookupEnvironment.problemReporter,
674
							this.lookupEnvironment.problemReporter,
670
							result);
675
							result);
671
					if (containsLocalType) 	parsedUnit.bits |= ASTNode.HasAllMethodBodies;
672
				} else {
676
				} else {
673
					// create parsed unit from file
677
					// create parsed unit from file
674
					IFile file = (IFile) cu.getResource();
678
					IFile file = (IFile) cu.getResource();

Return to bug 254738