diff options
6 files changed, 63 insertions, 1 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java index 342f50c582..ce9c925041 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java @@ -494,6 +494,8 @@ public void test011_problem_categories() { expectedProblemAttributes.put("ExplicitThisParameterNotInLambda", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); expectedProblemAttributes.put("ExplicitThisParameterNotBelow18", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); expectedProblemAttributes.put("ExplicitlyClosedAutoCloseable", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); + expectedProblemAttributes.put("ExportingForeignPackage", new ProblemAttributes(CategorizedProblem.CAT_MODULE)); + expectedProblemAttributes.put("ExportedPackageDoesNotExistOrIsEmpty", new ProblemAttributes(CategorizedProblem.CAT_MODULE)); expectedProblemAttributes.put("ExpressionShouldBeAVariable", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); expectedProblemAttributes.put("ExternalProblemFixable", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); expectedProblemAttributes.put("ExternalProblemNotFixable", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); @@ -1464,6 +1466,7 @@ public void test012_compiler_problems_tuning() { expectedProblemAttributes.put("ExplicitThisParameterNotInLambda", SKIP); expectedProblemAttributes.put("ExplicitThisParameterNotBelow18", SKIP); expectedProblemAttributes.put("ExplicitlyClosedAutoCloseable", new ProblemAttributes(JavaCore.COMPILER_PB_EXPLICITLY_CLOSED_AUTOCLOSEABLE)); + expectedProblemAttributes.put("ExportingForeignPackage", SKIP); expectedProblemAttributes.put("ExportedPackageDoesNotExistOrIsEmpty", SKIP); expectedProblemAttributes.put("ExpressionShouldBeAVariable", SKIP); expectedProblemAttributes.put("ExternalProblemFixable", SKIP); 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 3ed24c82b3..4c83d917ee 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 @@ -1456,6 +1456,45 @@ public class ModuleBuilderTests extends ModifyingResourceTests { deleteProject("com.greetings"); } } + public void test_Exports_foreign_package1() throws CoreException { + try { + String[] src = new String[] { + "src/module-info.java", + "module com.greetings {\n" + + " exports java.util;\n" + + "}" + }; + IJavaProject p2 = setupModuleProject("com.greetings", src); + p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null); + IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE); + assertMarkers("Unexpected markers", + "Cannot export the package java.util which belongs to module java.base", markers); + } finally { + deleteProject("com.greetings"); + } + } + public void test_Exports_foreign_package2() throws CoreException { + try { + String[] src = new String[] { + "src/module-info.java", + "module com.greetings {\n" + + " exports java.util;\n" + + "}", + "src/java/util/Wrong.java", + "package java.util;\n" + + "public class Wrong {}\n" + }; + IJavaProject p2 = setupModuleProject("com.greetings", src); + p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null); + IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE); + sortMarkers(markers); + assertMarkers("Unexpected markers", + "The package java.util conflicts with a package accessible from another module: java.base", + markers); + } finally { + deleteProject("com.greetings"); + } + } public void test_DuplicateExports() throws CoreException { try { String[] sources = new String[] { diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java index 79fc84d4e3..64220c7a4d 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java @@ -1965,6 +1965,9 @@ void setSourceStart(int sourceStart); int IllegalModifierForModule = ModuleRelated + 1318; /** @since 3.18 */ int UndefinedModuleAddReads = ModuleRelated + 1319; + /** @since 3.20 */ + int ExportingForeignPackage = ModuleRelated + 1320; + /** @since 3.14 */ int DuplicateResource = Internal + 1251; diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ModuleDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ModuleDeclaration.java index 3f5ed7dded..2bc4e22245 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ModuleDeclaration.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ModuleDeclaration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2018 IBM Corporation and others. + * Copyright (c) 2015, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -314,6 +314,14 @@ public class ModuleDeclaration extends ASTNode implements ReferenceContext { continue; if (pb.hasCompilationUnit(true)) continue; + for (ModuleBinding req : this.binding.getAllRequiredModules()) { + for (PlainPackageBinding exported : req.getExports()) { + if (CharOperation.equals(pb.compoundName, exported.compoundName)) { + skope.problemReporter().exportingForeignPackage(stat, req); + return; + } + } + } skope.problemReporter().invalidPackageReference(IProblem.PackageDoesNotExistOrIsEmpty, stat); } } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java index 7876f23a88..c227f5b093 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java @@ -10992,6 +10992,14 @@ public void invalidPackageReference(int problem, PackageVisibilityStatement ref) ref.pkgRef.sourceStart, ref.pkgRef.sourceEnd); } +public void exportingForeignPackage(PackageVisibilityStatement ref, ModuleBinding enclosingModule) { + String[] arguments = new String[] { CharOperation.charToString(ref.pkgName), CharOperation.charToString(enclosingModule.moduleName) }; + this.handle(IProblem.ExportingForeignPackage, + arguments, + arguments, + ref.pkgRef.sourceStart, + ref.pkgRef.sourceEnd); +} public void duplicateModuleReference(int problem, ModuleReference ref) { this.handle(problem, NoArgument, new String[] { CharOperation.charToString(ref.moduleName) }, diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties index 03d5704d4e..c859ddd4db 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties @@ -916,6 +916,7 @@ 1317 = Invalid service implementation {0}, must be a public class or interface type 1318 = Illegal modifier for module {0}; only open is permitted 1319 = {0} cannot be resolved to a module, it is referenced from an add-reads directive +1320 = Cannot export the package {0} which belongs to module {1} #### Java 9 1351 = Variable resource not allowed here for source level below 9 |