diff options
author | Stephan Herrmann | 2019-04-11 13:52:33 +0000 |
---|---|---|
committer | Stephan Herrmann | 2019-04-11 13:52:33 +0000 |
commit | fd5bb609f244a4b470f78f7693693f1904202502 (patch) | |
tree | d2f3e3566a38257e8e63d36a2ef393222559a299 | |
parent | 978592738789d49483a16097408de086280a2cfd (diff) | |
download | eclipse.jdt.core-I20190413-1800.tar.gz eclipse.jdt.core-I20190413-1800.tar.xz eclipse.jdt.core-I20190413-1800.zip |
module: <unnamed>, […]" error shown in Java editor by mistake
Change-Id: Ie5e373d09c3dd2d15ffb969db0a89bc251ba36cd
Signed-off-by: Stephan Herrmann <stephan.herrmann@berlin.de>
4 files changed, 132 insertions, 7 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests9.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests9.java index 06ffacef01..ea489c1876 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests9.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests9.java @@ -15,7 +15,9 @@ package org.eclipse.jdt.core.tests.model; +import java.io.File; import java.io.IOException; +import java.util.HashMap; import java.util.Hashtable; import org.eclipse.core.resources.IMarker; @@ -32,6 +34,7 @@ import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.WorkingCopyOwner; import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.tests.util.Util; import junit.framework.Test; @@ -684,4 +687,122 @@ public void testBug545687() throws CoreException, IOException { JavaCore.setOptions(options); } } +public void testBug546315() throws Exception { + if (!isJRE9) + return; + IJavaProject p = null; + String outputDirectory = Util.getOutputDirectory(); + try { + String fooPath = "externalLib/foo.jar"; + Util.createJar( + new String[] { + "test/src/foo/Foo.java", //$NON-NLS-1$ + "package foo;\n" + + "public class Foo {\n" + + " public static String get() { return \"\"; }\n" + + "}", + }, + null, + new HashMap<>(), + null, + getExternalResourcePath(fooPath)); + + String fooBarPath = "externalLib/foo.bar.jar"; + Util.createJar( + new String[] { + "test/src/foo/bar/FooBar.java", //$NON-NLS-1$ + "package foo.bar;\n" + + "public class FooBar {\n" + + " public static String get() { return \"\"; }\n" + + "}", + }, + null, + new HashMap<>(), + null, + getExternalResourcePath(fooBarPath)); + + String fooBar2Path = "externalLib/foo.bar2.jar"; + Util.createJar( + new String[] { + "test/src/foo/bar2/FooBar2.java", //$NON-NLS-1$ + "package foo.bar2;\n" + + "public class FooBar2 {\n" + + " public static String get() { return \"\"; }\n" + + "}", + }, + null, + new HashMap<>(), + null, + getExternalResourcePath(fooBar2Path)); + + p = createJava9Project("p", "11"); + IClasspathAttribute[] testAttrs = { JavaCore.newClasspathAttribute("test", "true") }; + addClasspathEntry(p, JavaCore.newSourceEntry(new Path("/p/src-test"), null, null, new Path("/p/bin-test"), testAttrs)); + addModularLibraryEntry(p, new Path(getExternalResourcePath(fooBarPath)), null); + addLibraryEntry(p, new Path(getExternalResourcePath(fooPath)), null, null, null, null, testAttrs, false); + addLibraryEntry(p, new Path(getExternalResourcePath(fooBar2Path)), null, null, null, null, testAttrs, false); + + createFolder("p/src/main"); + createFile("p/src/main/Main.java", + "package main;\n" + + "\n" + + "import foo.bar.FooBar;\n" + + "\n" + + "public class Main {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(FooBar.get());\n" + + " }\n" + + "\n" + + "}\n"); + createFile("p/src/module-info.java", + "module com.example.main {\n" + + " requires foo.bar;\n" + + "}\n"); + String testSource = + "package test;\n" + + "\n" + + "// errors shown in Java editor (but not in Problems view)\n" + + "// can be run without dialog \"error exists...\"\n" + + "\n" + + "import foo.bar.FooBar;\n" + + "import foo.bar2.FooBar2;\n" + + "import foo.Foo; // <- The package foo is accessible from more than one module: <unnamed>, foo.bar\n" + + "\n" + + "public class Test {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(Foo.get()); // <- Foo cannot be resolved\n" + + " System.out.println(FooBar.get());\n" + + " System.out.println(FooBar2.get());\n" + + " }\n" + + "\n" + + "}\n"; + createFolder("p/src-test/test"); + String mPath = "p/src-test/test/Test.java"; + createFile(mPath, + testSource); + p.getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null); + waitForAutoBuild(); + IMarker[] markers = p.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE); + assertMarkers("Unexpected markers", + "Name of automatic module \'foo.bar\' is unstable, it is derived from the module\'s file name.", markers); + + this.workingCopy.discardWorkingCopy(); + this.problemRequestor.initialize(testSource.toCharArray()); + this.workingCopy = getCompilationUnit("p/src-test/test/Test.java").getWorkingCopy(this.wcOwner, null); + this.problemRequestor.initialize(this.workingCopy.getSource().toCharArray()); + this.workingCopy.reconcile(AST_INTERNAL_JLS11, true, this.wcOwner, null); + assertProblems("Expecting no problems", "----------\n" + "----------\n", this.problemRequestor); + + markers = p.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE); + assertMarkers("Unexpected markers", "Name of automatic module \'foo.bar\' is unstable, it is derived from the module\'s file name.", markers); + } finally { + deleteExternalResource("externalLib"); + deleteProject(p); + File outputDir = new File(outputDirectory); + if (outputDir.exists()) + Util.flushDirectoryContent(outputDir); + } +} } diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java index 6e7831c188..cd433e2851 100644 --- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java +++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java @@ -91,7 +91,8 @@ public class ClasspathJep247 extends ClasspathJrt { } if (content != null) { reader = new ClassFileReader(content, qualifiedBinaryFileName.toCharArray()); - return new NameEnvironmentAnswer(reader, fetchAccessRestriction(qualifiedBinaryFileName), null); + char[] modName = moduleName != null ? moduleName.toCharArray() : null; + return new NameEnvironmentAnswer(reader, fetchAccessRestriction(qualifiedBinaryFileName), modName); } } catch(ClassFormatException e) { // Continue diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247Jdk12.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247Jdk12.java index 3daf6bdb7b..7b6ff4c82c 100644 --- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247Jdk12.java +++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247Jdk12.java @@ -92,7 +92,8 @@ public class ClasspathJep247Jdk12 extends ClasspathJep247 { } if (content != null) { reader = new ClassFileReader(content, qualifiedBinaryFileName.toCharArray()); - return new NameEnvironmentAnswer(reader, fetchAccessRestriction(qualifiedBinaryFileName), null); + char[] modName = moduleName != null ? moduleName.toCharArray() : null; + return new NameEnvironmentAnswer(reader, fetchAccessRestriction(qualifiedBinaryFileName), modName); } } catch(ClassFormatException e) { // Continue 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 55f0152795..f2b914d086 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 @@ -389,11 +389,13 @@ private NameEnvironmentAnswer[] askForTypeFromModules(ModuleBinding clientModule for (int i = 0; i < otherModules.length; i++) { NameEnvironmentAnswer answer = oracle.apply(otherModules[i]); if (answer != null) { - char[] nameFromAnswer = answer.moduleName(); - if (nameFromAnswer == null || CharOperation.equals(nameFromAnswer, otherModules[i].moduleName)) { - answer.moduleBinding = otherModules[i]; - } else { - answer.moduleBinding = getModule(nameFromAnswer); + if (answer.moduleBinding == null) { + char[] nameFromAnswer = answer.moduleName(); + if (CharOperation.equals(nameFromAnswer, otherModules[i].moduleName)) { + answer.moduleBinding = otherModules[i]; + } else { + answer.moduleBinding = getModule(nameFromAnswer); + } } answers[i] = answer; found = true; |