Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjay2018-11-26 10:16:26 +0000
committerJay Arthanareeswaran2018-11-29 04:01:42 +0000
commite2b7468d95fff64647905e495bcc8efa650d588c (patch)
tree54a9fe605ba7a0aa7fdce0d47998bd24ea2bbdbd
parent88ffa8b00ed7028c05521f42ef45b04243f92c61 (diff)
downloadeclipse.jdt.core-e2b7468d95fff64647905e495bcc8efa650d588c.tar.gz
eclipse.jdt.core-e2b7468d95fff64647905e495bcc8efa650d588c.tar.xz
eclipse.jdt.core-e2b7468d95fff64647905e495bcc8efa650d588c.zip
Bug 540067 - [9] An empty compilation unit in a package in a named
module is rejected Change-Id: Iadd25b6e7b722f4f43ab60c71d24d716a3ae08a5 Signed-off-by: jay <jarthana@in.ibm.com>
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java204
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java18
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java2
3 files changed, 214 insertions, 10 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java
index 6cda2da17e..74b75a5444 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java
@@ -40,7 +40,7 @@ import junit.framework.Test;
public class ModuleCompilationTests extends AbstractBatchCompilerTest {
static {
-// TESTS_NAMES = new String[] { "test_npe_bug535107" };
+// TESTS_NAMES = new String[] { "testBug540067e" };
// TESTS_NUMBERS = new int[] { 1 };
// TESTS_RANGE = new int[] { 298, -1 };
}
@@ -3630,11 +3630,7 @@ public void testBug521362_emptyFile() {
" ^^\n" +
"The package p1 does not exist or is empty\n" +
"----------\n" +
- "----------\n" +
- "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p1/X.java\n" +
- "Must declare a named package because this compilation unit is associated to the named module \'mod.one\'\n" +
- "----------\n" +
- "2 problems (2 errors)\n",
+ "1 problem (1 error)\n",
false,
"empty",
OUTPUT_DIR + File.separator + out);
@@ -5004,4 +5000,200 @@ public void testBug521362_emptyFile() {
"",
true);
}
+ public void testBug540067a() {
+ File outputDirectory = new File(OUTPUT_DIR);
+ Util.flushDirectoryContent(outputDirectory);
+ String out = "bin";
+ String directory = OUTPUT_DIR + File.separator + "src";
+ String moduleLoc = directory + File.separator + "mod.one";
+ List<String> files = new ArrayList<>();
+ writeFileCollecting(files, moduleLoc, "module-info.java",
+ "module mod.one { \n" +
+ " exports p;\n" +
+ "}");
+ writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java",
+ "package p;\n" +
+ "public class X {\n" +
+ "}");
+ writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "q", "Test.java",
+ "/*nothing in it */");
+
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("-d " + OUTPUT_DIR + File.separator + out )
+ .append(" -9 ")
+ .append(" -classpath \"")
+ .append(Util.getJavaClassLibsAsString())
+ .append("\" ")
+ .append(" --module-source-path " + "\"" + directory + "\" ")
+ .append(moduleLoc + File.separator + "module-info.java ")
+ .append(moduleLoc + File.separator + "p" + File.separator + "X.java ")
+ .append(moduleLoc + File.separator + "p" + File.separator + "q" + File.separator + "Test.java");
+
+ runConformModuleTest(
+ new String[0],
+ buffer.toString(),
+ "",
+ "",
+ false);
+ }
+ public void testBug540067b() {
+ File outputDirectory = new File(OUTPUT_DIR);
+ Util.flushDirectoryContent(outputDirectory);
+ String out = "bin";
+ String directory = OUTPUT_DIR + File.separator + "src";
+ String moduleLoc = directory + File.separator + "mod.one";
+ List<String> files = new ArrayList<>();
+ writeFileCollecting(files, moduleLoc, "module-info.java",
+ "module mod.one { \n" +
+ " exports p;\n" +
+ "}");
+ writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java",
+ "package p;\n" +
+ "public class X {\n" +
+ "}");
+ writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "q", "Test.java",
+ "package p.q;");
+
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("-d " + OUTPUT_DIR + File.separator + out )
+ .append(" -9 ")
+ .append(" -classpath \"")
+ .append(Util.getJavaClassLibsAsString())
+ .append("\" ")
+ .append(" --module-source-path " + "\"" + directory + "\" ")
+ .append(moduleLoc + File.separator + "module-info.java ")
+ .append(moduleLoc + File.separator + "p" + File.separator + "X.java ")
+ .append(moduleLoc + File.separator + "p" + File.separator + "q" + File.separator + "Test.java");
+
+ runConformModuleTest(
+ new String[0],
+ buffer.toString(),
+ "",
+ "",
+ false);
+ }
+ public void testBug540067c() {
+ File outputDirectory = new File(OUTPUT_DIR);
+ Util.flushDirectoryContent(outputDirectory);
+ String out = "bin";
+ String directory = OUTPUT_DIR + File.separator + "src";
+ String moduleLoc = directory + File.separator + "mod.one";
+ List<String> files = new ArrayList<>();
+ writeFileCollecting(files, moduleLoc, "module-info.java",
+ "module mod.one { \n" +
+ " exports p;\n" +
+ "}");
+ writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java",
+ "package p;\n" +
+ "public class X {\n" +
+ "}");
+ writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "q", "Test.java",
+ "package p.q;\n"
+ + "class Test {}");
+
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("-d " + OUTPUT_DIR + File.separator + out )
+ .append(" -9 ")
+ .append(" -classpath \"")
+ .append(Util.getJavaClassLibsAsString())
+ .append("\" ")
+ .append(" --module-source-path " + "\"" + directory + "\" ")
+ .append(moduleLoc + File.separator + "module-info.java ")
+ .append(moduleLoc + File.separator + "p" + File.separator + "X.java ")
+ .append(moduleLoc + File.separator + "p" + File.separator + "q" + File.separator + "Test.java");
+
+ runConformModuleTest(
+ new String[0],
+ buffer.toString(),
+ "",
+ "",
+ false);
+ }
+ public void testBug540067d() {
+ File outputDirectory = new File(OUTPUT_DIR);
+ Util.flushDirectoryContent(outputDirectory);
+ String out = "bin";
+ String directory = OUTPUT_DIR + File.separator + "src";
+ String moduleLoc = directory + File.separator + "mod.one";
+ List<String> files = new ArrayList<>();
+ writeFileCollecting(files, moduleLoc, "module-info.java",
+ "module mod.one { \n" +
+ " exports p;\n" +
+ "}");
+ writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java",
+ "package p;\n" +
+ "public class X {\n" +
+ "}");
+ writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "q", "Test.java",
+ "class Test {}");
+
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("-d " + OUTPUT_DIR + File.separator + out )
+ .append(" -9 ")
+ .append(" -classpath \"")
+ .append(Util.getJavaClassLibsAsString())
+ .append("\" ")
+ .append(" --module-source-path " + "\"" + directory + "\" ")
+ .append(moduleLoc + File.separator + "module-info.java ")
+ .append(moduleLoc + File.separator + "p" + File.separator + "X.java ")
+ .append(moduleLoc + File.separator + "p" + File.separator + "q" + File.separator + "Test.java");
+
+ runNegativeModuleTest(
+ new String[0],
+ buffer.toString(),
+ "",
+ "----------\n" +
+ "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/q/Test.java (at line 1)\n" +
+ " class Test {}\n" +
+ " ^\n" +
+ "Must declare a named package because this compilation unit is associated to the named module \'mod.one\'\n" +
+ "----------\n" +
+ "1 problem (1 error)\n",
+ false,
+ "unnamed package is not allowed in named modules");
+ }
+ public void testBug540067e() {
+ File outputDirectory = new File(OUTPUT_DIR);
+ Util.flushDirectoryContent(outputDirectory);
+ String out = "bin";
+ String directory = OUTPUT_DIR + File.separator + "src";
+ String moduleLoc = directory + File.separator + "mod.one";
+ List<String> files = new ArrayList<>();
+ writeFileCollecting(files, moduleLoc, "module-info.java",
+ "module mod.one { \n" +
+ " exports p;\n" +
+ "}");
+ writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java",
+ "package p;\n" +
+ "public class X {\n" +
+ "}");
+ writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "q", "Test.java",
+ "import java.lang.*;");
+
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("-d " + OUTPUT_DIR + File.separator + out )
+ .append(" -9 ")
+ .append(" -classpath \"")
+ .append(Util.getJavaClassLibsAsString())
+ .append("\" ")
+ .append(" -warn:-unused")
+ .append(" --module-source-path " + "\"" + directory + "\" ")
+ .append(moduleLoc + File.separator + "module-info.java ")
+ .append(moduleLoc + File.separator + "p" + File.separator + "X.java ")
+ .append(moduleLoc + File.separator + "p" + File.separator + "q" + File.separator + "Test.java");
+
+ runNegativeModuleTest(
+ new String[0],
+ buffer.toString(),
+ "",
+ "----------\n" +
+ "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/q/Test.java (at line 1)\n" +
+ " import java.lang.*;\n" +
+ " ^\n" +
+ "Must declare a named package because this compilation unit is associated to the named module \'mod.one\'\n" +
+ "----------\n" +
+ "1 problem (1 error)\n",
+ false,
+ "unnamed package is not allowed in named modules");
+ }
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java
index 6ea3c6228b..ea2b9006d5 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2017 IBM Corporation and others.
+ * Copyright (c) 2000, 2018 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -125,8 +125,8 @@ void buildTypeBindings(AccessRestriction accessRestriction) {
moduleDecl.createScope(this);
moduleDecl.checkAndSetModifiers();
}
- } else if (this.environment.module != this.environment.UnNamedModule) {
- problemReporter().unnamedPackageInNamedModule(this.environment.module);
+ } else if (module() != this.environment.UnNamedModule) {
+ problemReporter().unnamedPackageInNamedModule(module());
}
} else {
if ((this.fPackage = this.environment.createPackage(this.currentPackageName)) == null) {
@@ -678,6 +678,18 @@ public int nextCaptureID() {
return this.captureID++;
}
+@Override
+public ModuleBinding module() {
+ if (!this.referenceContext.isModuleInfo() &&
+ this.referenceContext.types == null &&
+ this.referenceContext.currentPackage == null &&
+ this.referenceContext.imports == null) {
+ this.environment = this.environment.UnNamedModule.environment;
+ return this.environment.UnNamedModule;
+ }
+ return super.module();
+}
+
/* Answer the problem reporter to use for raising new problems.
*
* Note that as a side-effect, this updates the current reference context
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java
index da4f2cf817..28ef21f810 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java
@@ -751,7 +751,7 @@ public abstract class Scope {
} while (scope != null);
return (CompilationUnitScope) lastScope;
}
- public final ModuleBinding module() {
+ public ModuleBinding module() {
return environment().module;
}
public boolean isLambdaScope() {

Back to the top