Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Langer2018-11-19 17:44:00 -0500
committerStephan Herrmann2019-01-19 18:03:51 -0500
commit9046e04f52630ef84dd29d3db30e339f0fe02d36 (patch)
tree64b02ce1eca06b653507d1b67f8c07a022283e80
parent091f126c79d8fb903dec0c06d028661cc8a31d04 (diff)
downloadeclipse.jdt.core-9046e04f52630ef84dd29d3db30e339f0fe02d36.tar.gz
eclipse.jdt.core-9046e04f52630ef84dd29d3db30e339f0fe02d36.tar.xz
eclipse.jdt.core-9046e04f52630ef84dd29d3db30e339f0fe02d36.zip
Bug 541328 - Package from another modular project that is made visible
via add-export project setting is not accessible rewrite org.eclipse.jdt.internal.compiler.lookup.ModuleBinding.recordExportRestrictions(PackageBinding, char[][]) to merge restrictions Change-Id: I788a317d14dbe883bd920d769333566e576365a7 Signed-off-by: Christoph Langer <christoph.langer@sap.com> Also-by: Stephan Herrmann <stephan.herrmann@berlin.de>
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java53
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java30
2 files changed, 74 insertions, 9 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 bdb5dd010c..cecea2825e 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
@@ -7581,6 +7581,59 @@ public class ModuleBuilderTests extends ModifyingResourceTests {
deleteProject(current);
}
}
+ public void testBug541328() throws Exception {
+ IJavaProject pa = createJava9Project("m.a");
+ IJavaProject pb = createJava9Project("m.b");
+ IJavaProject test = createJava9Project("test");
+ try {
+ createFolder("m.a/src/a/foo");
+ createFile("m.a/src/a/foo/Bar.java", "package a.foo;\n public class Bar {}\n");
+ createFile("m.a/src/module-info.java",
+ "module m.a {\n" +
+ " exports a.foo to m.b;\n" +
+ "}\n");
+ createFile("m.b/src/module-info.java",
+ "module m.b {\n" +
+ " requires m.a;\n" +
+ " exports b;\n" +
+ "}\n");
+ createFolder("m.b/src/b");
+ createFile("m.b/src/b/Boo.java",
+ "package b;\n" +
+ "import a.foo.Bar;\n" +
+ "public class Boo extends Bar {}\n");
+ addModularProjectEntry(pb, pa);
+
+ IClasspathAttribute[] forceExport = {
+ JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true"),
+ JavaCore.newClasspathAttribute(IClasspathAttribute.ADD_EXPORTS, "m.a/a.foo=ALL-UNNAMED")
+ };
+ addClasspathEntry(test, JavaCore.newProjectEntry(pa.getPath(), null, false, forceExport, false));
+ addModularProjectEntry(test, pb);
+
+ String testSource =
+ "import a.foo.Bar;\n" +
+ "import b.Boo;\n" +
+ "public class Test {\n" +
+ " Bar b = new Boo();\n" +
+ "}\n";
+ String testPath = "test/src/Test.java";
+ createFile(testPath, testSource);
+ getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
+ assertNoErrors();
+
+ this.problemRequestor.initialize(testSource.toCharArray());
+ getCompilationUnit(testPath).getWorkingCopy(this.wcOwner, null);
+ assertProblems("unexpected problems",
+ "----------\n" +
+ "----------\n",
+ this.problemRequestor);
+ } finally {
+ deleteProject(pa);
+ deleteProject(pb);
+ 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/ModuleBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java
index d6117ed47a..c799b88d0a 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2016, 2018 IBM Corporation and others.
+ * Copyright (c) 2016, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -325,25 +325,37 @@ public class ModuleBinding extends Binding implements IUpdatableModule {
protected void recordExportRestrictions(PackageBinding exportedPackage, char[][] targetModules) {
if (targetModules != null && targetModules.length > 0) {
- SimpleSetOfCharArray targetModuleSet = new SimpleSetOfCharArray(targetModules.length);
+ SimpleSetOfCharArray targetModuleSet = null;
+ if (this.exportRestrictions != null) {
+ targetModuleSet = this.exportRestrictions.get(exportedPackage);
+ } else {
+ this.exportRestrictions = new HashMap<>();
+ }
+ if (targetModuleSet == null) {
+ targetModuleSet = new SimpleSetOfCharArray(targetModules.length);
+ this.exportRestrictions.put(exportedPackage, targetModuleSet);
+ }
for (int i = 0; i < targetModules.length; i++) {
targetModuleSet.add(targetModules[i]);
}
- if (this.exportRestrictions == null)
- this.exportRestrictions = new HashMap<>();
- this.exportRestrictions.put(exportedPackage, targetModuleSet);
}
}
protected void recordOpensRestrictions(PackageBinding openedPackage, char[][] targetModules) {
if (targetModules != null && targetModules.length > 0) {
- SimpleSetOfCharArray targetModuleSet = new SimpleSetOfCharArray(targetModules.length);
+ SimpleSetOfCharArray targetModuleSet = null;
+ if (this.openRestrictions != null) {
+ targetModuleSet = this.openRestrictions.get(openedPackage);
+ } else {
+ this.openRestrictions = new HashMap<>();
+ }
+ if (targetModuleSet == null) {
+ targetModuleSet = new SimpleSetOfCharArray(targetModules.length);
+ this.openRestrictions.put(openedPackage, targetModuleSet);
+ }
for (int i = 0; i < targetModules.length; i++) {
targetModuleSet.add(targetModules[i]);
}
- if (this.openRestrictions == null)
- this.openRestrictions = new HashMap<>();
- this.openRestrictions.put(openedPackage, targetModuleSet);
}
}

Back to the top