Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTill Brychcy2019-05-14 15:58:22 -0400
committerTill Brychcy2019-05-16 13:42:06 -0400
commita068825c7323c0bdfce75ff65ce829eb7b4bf2e4 (patch)
tree67ec7305799b59d09dd421012eb852ad0c38d57e
parent506b84081b28a0a49c69bf0affa617d4dbc6012e (diff)
downloadeclipse.jdt.core-a068825c7323c0bdfce75ff65ce829eb7b4bf2e4.tar.gz
eclipse.jdt.core-a068825c7323c0bdfce75ff65ce829eb7b4bf2e4.tar.xz
eclipse.jdt.core-a068825c7323c0bdfce75ff65ce829eb7b4bf2e4.zip
Bug 544306 - [Java 11] Error in Editor when using class in Test sourceI20190516-1800
code from modular test dependency Change-Id: I316d5bf212a555b2855dafc7481abcf7b275ad1e
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter9Test.java4
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests9.java46
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProjectElementInfo.java2
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/NameLookup.java23
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SearchableEnvironment.java2
5 files changed, 69 insertions, 8 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter9Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter9Test.java
index 276625417f..1193890dff 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter9Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter9Test.java
@@ -1354,7 +1354,9 @@ public class ASTConverter9Test extends ConverterTestSetup {
// part two, where we access a module via a 'requires' reference from the second:
IJavaProject project2 = createJavaProject("Second", new String[] {"src"}, new String[] {jcl9lib}, "bin", "9");
- addClasspathEntry(project2, JavaCore.newProjectEntry(project1.getPath()));
+ addClasspathEntry(project2, JavaCore.newProjectEntry(project1.getPath(), null, false,
+ new IClasspathAttribute[] { JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true") },
+ false));
project2.open(null);
createFile("/Second/src/module-info.java",
"module second {\n" +
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 ea489c1876..2a2db521a0 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
@@ -805,4 +805,50 @@ public void testBug546315() throws Exception {
Util.flushDirectoryContent(outputDir);
}
}
+public void testBug544306() throws Exception {
+ if (!isJRE9)
+ return;
+ IJavaProject p1 = createJava9Project("p1");
+ IJavaProject p2 = createJava9Project("p2");
+ try {
+ createFolder("p1/src/p1");
+ createFile("p1/src/p1/P1.java",
+ "package p1;\n" +
+ "public class P1 {\n" +
+ "}\n");
+ createFile("p1/src/module-info.java",
+ "module p1 {\n" +
+ " exports p1;\n" +
+ "}\n");
+
+ IClasspathAttribute[] testAttrs = { JavaCore.newClasspathAttribute("test", "true") };
+ addClasspathEntry(p2, JavaCore.newProjectEntry(p1.getPath(), null, false, testAttrs, false));
+ addClasspathEntry(p2, JavaCore.newSourceEntry(new Path("/p2/src-test"), null, null, new Path("/p2/bin-test"), testAttrs));
+ createFolder("p2/src/p2");
+ createFolder("p2/src-test/p2");
+
+ createFile("p2/src/module-info.java",
+ "module p2 {\n" +
+ "}\n");
+ String testSource = "package p2;\n" +
+ "import p1.P1;\n" +
+ "class Test extends P1{ }";
+
+ createFile("p2/src-test/p2/Test.java", testSource);
+ waitForAutoBuild();
+ IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
+ assertMarkers("Unexpected markers",
+ "", markers);
+
+ this.workingCopy.discardWorkingCopy();
+ this.workingCopy = getCompilationUnit("p2/src-test/p2/Test.java").getWorkingCopy(this.wcOwner, null);
+ this.problemRequestor.initialize(testSource.toCharArray());
+ this.workingCopy.reconcile(AST_INTERNAL_JLS11, true, this.wcOwner, null);
+ assertProblems("Expecting no problems", "----------\n" + "----------\n", this.problemRequestor);
+ this.workingCopy.discardWorkingCopy();
+ } finally {
+ deleteProject(p1);
+ deleteProject(p2);
+ }
+}
}
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProjectElementInfo.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProjectElementInfo.java
index 8a67100331..695eed164d 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProjectElementInfo.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProjectElementInfo.java
@@ -364,7 +364,7 @@ class JavaProjectElementInfo extends OpenableElementInfo {
}
cache.allPkgFragmentsCache = allPkgFragmentsCache;
}
- return new NameLookup(cache.allPkgFragmentRootsCache, cache.allPkgFragmentsCache, workingCopies, cache.rootToResolvedEntries);
+ return new NameLookup(project, cache.allPkgFragmentRootsCache, cache.allPkgFragmentsCache, workingCopies, cache.rootToResolvedEntries);
}
/*
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/NameLookup.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/NameLookup.java
index 835d45736e..d3603526ac 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/NameLookup.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/NameLookup.java
@@ -227,11 +227,14 @@ public class NameLookup implements SuffixConstants {
public long timeSpentInSeekTypesInSourcePackage = 0;
public long timeSpentInSeekTypesInBinaryPackage = 0;
+ private JavaProject rootProject;
+
public NameLookup(
- IPackageFragmentRoot[] packageFragmentRoots,
+ JavaProject rootProject, IPackageFragmentRoot[] packageFragmentRoots,
HashtableOfArrayToObject packageFragments,
ICompilationUnit[] workingCopies,
Map rootToResolvedEntries) {
+ this.rootProject = rootProject;
long start = -1;
if (VERBOSE) {
Util.verbose(" BUILDING NameLoopkup"); //$NON-NLS-1$
@@ -795,7 +798,7 @@ public class NameLookup implements SuffixConstants {
}
}
Answer answer = new Answer(type, accessRestriction, entry,
- getModuleDescription(root, this.rootToModule, this.rootToResolvedEntries::get));
+ getModuleDescription(this.rootProject, root, this.rootToModule, this.rootToResolvedEntries::get));
if (!answer.ignoreIfBetter()) {
if (answer.isBetter(suggestedAnswer))
return answer;
@@ -872,10 +875,20 @@ public class NameLookup implements SuffixConstants {
}
/** Internal utility, which is able to answer explicit and automatic modules. */
- static IModuleDescription getModuleDescription(IPackageFragmentRoot root, Map<IPackageFragmentRoot,IModuleDescription> cache, Function<IPackageFragmentRoot,IClasspathEntry> rootToEntry) {
+ static IModuleDescription getModuleDescription(JavaProject project, IPackageFragmentRoot root, Map<IPackageFragmentRoot,IModuleDescription> cache, Function<IPackageFragmentRoot,IClasspathEntry> rootToEntry) {
IModuleDescription module = cache.get(root);
if (module != null)
return module != NO_MODULE ? module : null;
+ if (!Objects.equals(project, root.getJavaProject())) {
+ IClasspathEntry classpathEntry2 = rootToEntry.apply(root);
+ if (classpathEntry2 instanceof ClasspathEntry) {
+ if (!((ClasspathEntry) classpathEntry2).isModular()) {
+ // not on the module path and not a local source folder
+ cache.put(root, NO_MODULE);
+ return null;
+ }
+ }
+ }
try {
if (root.getKind() == IPackageFragmentRoot.K_SOURCE)
module = root.getJavaProject().getModuleDescription(); // from any root in this project
@@ -903,7 +916,7 @@ public class NameLookup implements SuffixConstants {
}
public IModule getModuleDescriptionInfo(PackageFragmentRoot root) {
- IModuleDescription desc = getModuleDescription(root, this.rootToModule, this.rootToResolvedEntries::get);
+ IModuleDescription desc = getModuleDescription(this.rootProject, root, this.rootToModule, this.rootToResolvedEntries::get);
if (desc != null) {
return getModuleDescriptionInfo(desc);
}
@@ -1284,7 +1297,7 @@ public class NameLookup implements SuffixConstants {
continue;
}
}
- module = getModuleDescription(root, this.rootToModule, this.rootToResolvedEntries::get);
+ module = getModuleDescription(this.rootProject, root, this.rootToModule, this.rootToResolvedEntries::get);
if (module != null && prefixMatcher.matches(name, module.getElementName().toCharArray(), false)) {
requestor.acceptModule(module);
}
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SearchableEnvironment.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SearchableEnvironment.java
index 0f7c5d756f..5595856759 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SearchableEnvironment.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SearchableEnvironment.java
@@ -993,7 +993,7 @@ private void findPackagesFromRequires(char[] prefix, boolean isMatchAllPrefix, I
this.rootToModule = new HashMap<>();
}
for (IPackageFragmentRoot root : roots) {
- IModuleDescription moduleDescription = NameLookup.getModuleDescription(root, this.rootToModule, this.nameLookup.rootToResolvedEntries::get);
+ IModuleDescription moduleDescription = NameLookup.getModuleDescription(this.project, root, this.rootToModule, this.nameLookup.rootToResolvedEntries::get);
if (moduleDescription != null)
return moduleDescription;
}

Back to the top