diff options
author | Stephan Herrmann | 2018-04-23 23:02:38 +0000 |
---|---|---|
committer | Stephan Herrmann | 2018-04-23 23:04:04 +0000 |
commit | 74d3bf3304f82a48f3c1a8d63f1abcde3c2c4533 (patch) | |
tree | 8c34cfbe207ac3ba668385949858749e312f810e | |
parent | 747856a76606d57cb67c300aa2c06c7104b1d436 (diff) | |
download | eclipse.jdt.core-74d3bf3304f82a48f3c1a8d63f1abcde3c2c4533.tar.gz eclipse.jdt.core-74d3bf3304f82a48f3c1a8d63f1abcde3c2c4533.tar.xz eclipse.jdt.core-74d3bf3304f82a48f3c1a8d63f1abcde3c2c4533.zip |
Change-Id: I23fb6975e9d0179f5a390a2c2d2c0ab99693f062
2 files changed, 92 insertions, 9 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java index 2a543d1d3e..067e67f514 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -3014,4 +3014,63 @@ public void testBug507954_0001() throws JavaModelException, CoreException { } } +public void testBug533949() throws CoreException { + if (!isJRE9) return; + IJavaProject javaProject1 = null; + IJavaProject javaProject2 = null; + try { + javaProject1 = createJava9Project("mod1"); + String packA = "/mod1/src/a/"; + createFolder(packA); + createFile(packA + "A.java", + "package a;\n" + + "public abstract class A {\n"+ + "}\n"); + createFile("/mod1/src/module-info.java", + "module mod1 {\n" + + " exports a;\n"+ + "}\n"); + + javaProject2 = createJava9Project("mod2"); + addClasspathEntry(javaProject2, JavaCore.newProjectEntry(javaProject1.getPath())); + String packB = "/mod2/src/b/"; + createFolder(packB); + createFile(packB + "B.java", + "package b;\n" + + "public class B extends a.A {\n"+ + "}\n"); + createFile("/mod2/src/module-info.java", + "module mod2 {\n" + + " requires mod1;\n"+ + "}\n"); + + waitUntilIndexesReady(); + + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy(packB + "B.java", true); + + IType focus = javaProject2.findType("b.B"); + ITypeHierarchy hierarchy = focus.newTypeHierarchy(this.workingCopies, null); + IType[] allSuperTypes = hierarchy.getAllSupertypes(focus); + assertTypesEqual("Incorrect super hierarchy", + "a.A\n" + + "java.lang.Object\n", + allSuperTypes, + true); + + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy(packA + "A.java", true); + + focus = javaProject1.findType("a.A"); + hierarchy = focus.newTypeHierarchy(this.workingCopies, null); + IType[] allSubTypes = hierarchy.getAllSubtypes(focus); + assertTypesEqual("Incorrect sub hierarchy", + "b.B\n", + allSubTypes, + true); + } finally{ + if (javaProject1 != null) deleteProject(javaProject1); + if (javaProject2 != null) deleteProject(javaProject2); + } +} } diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/hierarchy/HierarchyResolver.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/hierarchy/HierarchyResolver.java index 61bfe5a953..f8656fc3e5 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/hierarchy/HierarchyResolver.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/hierarchy/HierarchyResolver.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -78,6 +78,7 @@ public class HierarchyResolver implements ITypeRequestor { private int typeIndex; private IGenericType[] typeModels; + private Parser basicParser; private static final CompilationUnitDeclaration FakeUnit; static { @@ -126,11 +127,31 @@ public void accept(IBinaryType binaryType, PackageBinding packageBinding, Access */ @Override public void accept(ICompilationUnit sourceUnit, AccessRestriction accessRestriction) { - //System.out.println("Cannot accept compilation units inside the HierarchyResolver."); - this.lookupEnvironment.problemReporter.abortDueToInternalError( - new StringBuffer(Messages.accept_cannot) - .append(sourceUnit.getFileName()) - .toString()); + if (CharOperation.equals(TypeConstants.MODULE_INFO_NAME, sourceUnit.getMainTypeName())) { + // module is needed for resolving, so parse and build it now: + CompilationResult unitResult = new CompilationResult(sourceUnit, 1, 1, this.options.maxProblemsPerUnit); + CompilationUnitDeclaration parsedUnit = basicParser().dietParse(sourceUnit, unitResult); + this.lookupEnvironment.buildTypeBindings(parsedUnit, accessRestriction); + this.lookupEnvironment.completeTypeBindings(parsedUnit, true); // work done inside checkAndSetImports() + } else { + //System.out.println("Cannot accept compilation units inside the HierarchyResolver."); + this.lookupEnvironment.problemReporter.abortDueToInternalError( + new StringBuffer(Messages.accept_cannot) + .append(sourceUnit.getFileName()) + .toString()); + } +} +private Parser basicParser() { + if (this.basicParser == null) { + ProblemReporter problemReporter = + new ProblemReporter( + DefaultErrorHandlingPolicies.proceedWithAllProblems(), + this.options, + new DefaultProblemFactory()); + this.basicParser = new Parser(problemReporter, false); + this.basicParser.reportOnlyOneSyntaxError = true; + } + return this.basicParser; } /** @@ -163,12 +184,15 @@ public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, Acc // build bindings if (unit != null) { try { - this.lookupEnvironment.buildTypeBindings(unit, accessRestriction); + LookupEnvironment environment = packageBinding.environment; + if (environment == null) + environment = this.lookupEnvironment; + environment.buildTypeBindings(unit, accessRestriction); org.eclipse.jdt.core.ICompilationUnit cu = ((SourceTypeElementInfo)sourceType).getHandle().getCompilationUnit(); rememberAllTypes(unit, cu, false); - this.lookupEnvironment.completeTypeBindings(unit, true/*build constructor only*/); + environment.completeTypeBindings(unit, true/*build constructor only*/); } catch (AbortCompilation e) { // missing 'java.lang' package: ignore } |