diff options
| author | Till Brychcy | 2017-09-22 20:36:49 +0000 |
|---|---|---|
| committer | Till Brychcy | 2017-09-27 06:32:43 +0000 |
| commit | f8770d508aeb5800826e9043ddb68269cfb486d1 (patch) | |
| tree | fb8ccc1e01bdee2f9fb481e843edbf8d1bd0a27a | |
| parent | 7c076c11f009e372d7f368c03521eadc251f60ee (diff) | |
| download | eclipse.jdt.core-f8770d508aeb5800826e9043ddb68269cfb486d1.tar.gz eclipse.jdt.core-f8770d508aeb5800826e9043ddb68269cfb486d1.tar.xz eclipse.jdt.core-f8770d508aeb5800826e9043ddb68269cfb486d1.zip | |
Change-Id: I11e9716fa5991208c3adbcdb7f5c73f3d8b4376c
3 files changed, 101 insertions, 10 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java index 8041086983..cbadd372bc 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java @@ -5759,6 +5759,97 @@ public class ModuleBuilderTests extends ModifyingResourceTests { deleteProject("mod.two"); } } + public void testBug522671() throws Exception { + if (!isJRE9) return; + try { + IJavaProject p1 = setupModuleProject("util", + new String[] { + "src/module-info.java", + "module util {\n" + + " exports my.util;\n" + + "}\n" + + "", + "src/my/util/Data.java", + "package my.util;\n" + + "public class Data {\n" + + "}\n" + + "", + "src/my/util/AnnotatedInModule.java", + "package my.util;\n" + + "public abstract class AnnotatedInModule {\n" + + " abstract public Data getTime();\n" + + "}\n" + + "", + }); + IJavaProject p2 = setupModuleProject("util2", + new String[] { + "src/module-info.java", + "module util2 {\n" + + " exports my.util.nested;\n" + + "}\n" + + "", + "src/my/util/nested/Unrelated.java", + "package my.util.nested;\n" + + "class Unrelated {\n" + + "}\n" + + "", + }); + String[] sources3 = { + "src/a/other/AnnotatedInOtherNonModule.java", + "package a.other;\n" + + "import my.util.Data;\n" + + "public class AnnotatedInOtherNonModule {\n" + + " Data generationDate;\n" + + "}\n" + + "", + }; + IClasspathAttribute[] attr = { JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true") }; + // modulepath + IClasspathEntry[] deps3 = { JavaCore.newProjectEntry(p1.getPath(), null, false, attr, false) }; + IJavaProject p3 = setupModuleProject("other", sources3, deps3); + + String[] sources4 = { + "src/test/Test.java", + "package test;\n" + + "\n" + + "import a.other.AnnotatedInOtherNonModule;\n" + + "import my.util.AnnotatedInModule;\n" + + "import my.util.Data;\n" + + "\n" + + "public class Test extends AnnotatedInOtherNonModule {\n" + + " public Data f(AnnotatedInModule calendar) {\n" + + " return calendar.getTime();\n" + + " }\n" + + "}\n" + + "", + }; + IClasspathEntry[] deps4 = { // + // modulepath (with split package my.util) + JavaCore.newProjectEntry(p1.getPath(), null, false, attr, false), // + JavaCore.newProjectEntry(p2.getPath(), null, false, attr, false), // + // classpath + JavaCore.newProjectEntry(p3.getPath()) // + }; + IJavaProject p4 = setupModuleProject("test", sources4, deps4); + p4.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null); + + assertNoErrors(); + + this.problemRequestor.reset(); + ICompilationUnit cu = getCompilationUnit("/test/src/test/Test.java"); + cu.getWorkingCopy(this.wcOwner, null); + assertProblems( + "Unexpected problems", + "----------\n" + + "----------\n", + this.problemRequestor); + } finally { + deleteProject("util"); + deleteProject("util2"); + deleteProject("other"); + deleteProject("test"); + } + } protected void assertNoErrors() throws CoreException { for (IProject p : getWorkspace().getRoot().getProjects()) { diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java index 61c2688c08..247b1cd49f 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java @@ -1661,17 +1661,11 @@ private ReferenceBinding getTypeFromCompoundName(char[][] compoundName, boolean ReferenceBinding binding = getCachedType(compoundName); if (binding == null) { PackageBinding packageBinding = computePackageFrom(compoundName, false /* valid pkg */); - if(this.useModuleSystem) { - // the package might not have been seen in getCachedType, so retry - binding = packageBinding.getType0(compoundName[compoundName.length - 1]); - } - if(binding == null) { - binding = new UnresolvedReferenceBinding(compoundName, packageBinding); - if (wasMissingType) { - binding.tagBits |= TagBits.HasMissingType; // record it was bound to a missing type - } - packageBinding.addType(binding); + binding = new UnresolvedReferenceBinding(compoundName, packageBinding); + if (wasMissingType) { + binding.tagBits |= TagBits.HasMissingType; // record it was bound to a missing type } + packageBinding.addType(binding); } else if (binding == TheNotFoundType) { // report the missing class file first if (!wasMissingType) { diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java index eec6305ca5..6ac1c53460 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java @@ -500,6 +500,9 @@ public class ModuleBinding extends Binding implements IUpdatableModule { PackageBinding binding = new PackageBinding(subPkgCompoundName, parent, this.environment, this); // remember this.declaredPackages.put(fullFlatName, binding); + if (parent == null) { + this.environment.knownPackages.put(name, binding); + } return binding; } // Given parent is visible in this module, see if there is sub package named name visible in this module @@ -639,6 +642,9 @@ public class ModuleBinding extends Binding implements IUpdatableModule { } } this.declaredPackages.put(packageName, packageBinding); + if (packageBinding.parent == null) { + this.environment.knownPackages.put(packageName, packageBinding); + } } return packageBinding; } |
