Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Arthanareeswaran2019-03-11 07:27:34 -0400
committerJay Arthanareeswaran2019-03-13 00:35:49 -0400
commit5ddf55f55ca67103310e86b77ee14683b0256bb9 (patch)
tree1d6297e29dcf8a4cb099283b5354deffeb85b12c /org.eclipse.jdt.compiler.apt.tests
parent47fb37f7d6c00a606581f58f437976bf45a48d6a (diff)
downloadeclipse.jdt.core-5ddf55f55ca67103310e86b77ee14683b0256bb9.tar.gz
eclipse.jdt.core-5ddf55f55ca67103310e86b77ee14683b0256bb9.tar.xz
eclipse.jdt.core-5ddf55f55ca67103310e86b77ee14683b0256bb9.zip
Bug 544936 - RoundEnvImpl#getRootElements() does not include include
binary modules Change-Id: Ib9dae78e279820db00f2b0dc5be3f509daa651ef Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
Diffstat (limited to 'org.eclipse.jdt.compiler.apt.tests')
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jarbin257099 -> 257765 bytes
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java12ElementProcessor.java82
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java9ElementProcessor.java23
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.main/module-info.java6
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.main/my1/mod/Main.java8
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.one/module-info.java2
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.one/my1/mod/samePackage/SomeType.java4
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.two/module-info.java3
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.two/my1/mod/samePackage/SomeType.java8
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java12ElementsTests.java8
10 files changed, 115 insertions, 29 deletions
diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
index e18d62ebc3..89b229279b 100644
--- a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
+++ b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
Binary files differ
diff --git a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java12ElementProcessor.java b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java12ElementProcessor.java
index 8fcd6b1817..3a906d3764 100644
--- a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java12ElementProcessor.java
+++ b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java12ElementProcessor.java
@@ -54,6 +54,7 @@ public class Java12ElementProcessor extends BaseProcessor {
Messager _messager = null;
Filer _filer = null;
boolean isBinaryMode = false;
+ String mode;
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
@@ -78,6 +79,9 @@ public class Java12ElementProcessor extends BaseProcessor {
try {
if (options.containsKey("binary")) {
this.isBinaryMode = true;
+ this.mode = "binary";
+ } else {
+ this.mode = "source";
}
if (!invokeTestMethods(options)) {
testAll();
@@ -157,14 +161,14 @@ public class Java12ElementProcessor extends BaseProcessor {
}
Collections.sort(types, (x, y) -> x.compareTo(y)); //unused as of now
Collections.sort(modules, (x, y) -> x.compareTo(y));
- assertEquals("incorrect no of modules in root elements", 3, modules.size());
- assertEquals("incorrect modules among root elements", "[module.main, module.readable.one, module.readable.two]", modules.toString());
- assertNotNull("module should not be null", mod1);
- assertNotNull("module should not be null", mod2);
- assertNotNull("module should not be null", mod3);
- assertEquals("Incorrect enclosed packages", "[lang.MOD.same, ]", getElementsAsString(mod3.getEnclosedElements()));
- assertEquals("Incorrect enclosed packages", "[lang.MOD.same, ]", getElementsAsString(mod2.getEnclosedElements()));
- assertEquals("Incorrect enclosed packages", "[lang.MOD, ]", getElementsAsString(mod1.getEnclosedElements()));
+ assertEquals("incorrect no of modules in root elements in in "+ this.mode + " mode", 3, modules.size());
+ assertEquals("incorrect modules among root elements in "+ this.mode + " mode", "[module.main, module.readable.one, module.readable.two]", modules.toString());
+ assertNotNull("module should not be null in "+ this.mode + " mode", mod1);
+ assertNotNull("module should not be null in "+ this.mode + " mode", mod2);
+ assertNotNull("module should not be null in "+ this.mode + " mode", mod3);
+ assertEquals("Incorrect enclosed packages in "+ this.mode + " mode", "[lang.MOD.same, ]", getElementsAsString(mod3.getEnclosedElements()));
+ assertEquals("Incorrect enclosed packages in "+ this.mode + " mode", "[lang.MOD.same, ]", getElementsAsString(mod2.getEnclosedElements()));
+ assertEquals("Incorrect enclosed packages in "+ this.mode + " mode", "[lang.MOD, ]", getElementsAsString(mod1.getEnclosedElements()));
}
public void testRootElements2() throws IOException {
@@ -204,18 +208,64 @@ public class Java12ElementProcessor extends BaseProcessor {
}
Collections.sort(types, (x, y) -> x.compareTo(y)); //unused as of now
Collections.sort(modules, (x, y) -> x.compareTo(y));
- assertEquals("incorrect no of modules in root elements", this.isBinaryMode ? 2 : 3, modules.size());
- assertEquals("incorrect modules among root elements", "[module.main, module.readable.one" +
+ assertEquals("incorrect no of modules in root elements in "+ this.mode + " mode", this.isBinaryMode ? 2 : 3, modules.size());
+ assertEquals("incorrect modules among root elements in "+ this.mode + " mode", "[module.main, module.readable.one" +
(this.isBinaryMode ? "" : ", module.readable.two") + "]", modules.toString());
- assertNotNull("module should not be null", mod1);
- assertEquals("Incorrect enclosed packages", "[my.mod, ]", getElementsAsString(mod1.getEnclosedElements()));
- assertEquals("Incorrect enclosed packages", "[my.mod.same, ]", getElementsAsString(mod2.getEnclosedElements()));
- assertNotNull("module should not be null", mod2);
+ assertNotNull("module should not be null in "+ this.mode + " mode", mod1);
+ assertEquals("Incorrect enclosed packages in "+ this.mode + " mode", "[my.mod, ]", getElementsAsString(mod1.getEnclosedElements()));
+ assertEquals("Incorrect enclosed packages in "+ this.mode + " mode", "[my.mod.same, ]", getElementsAsString(mod2.getEnclosedElements()));
+ assertNotNull("module should not be null in "+ this.mode + " mode", mod2);
if (!this.isBinaryMode) {
- assertNotNull("module should not be null", mod3);
- assertEquals("Incorrect enclosed packages", "[]", getElementsAsString(mod3.getEnclosedElements()));
+ assertNotNull("module should not be null ", mod3);
+ assertEquals("Incorrect enclosed packages ", "[]", getElementsAsString(mod3.getEnclosedElements()));
}
}
+ public void testRootElements3() throws IOException {
+ Set<? extends Element> rootElements = this.roundEnv.getRootElements();
+ List<String> types = new ArrayList<>();
+ List<String> modules = new ArrayList<>();
+ ModuleElement mod1 = null, mod2 = null, mod3 = null;
+ for (Element element : rootElements) {
+ Element root = getRoot(element);
+ String modName = null;
+ ModuleElement mod = null;
+ if (element instanceof ModuleElement) {
+ mod = (ModuleElement) element;
+ modName = mod.getQualifiedName().toString();
+ if (!modules.contains(modName) && !modName.equals("java.base"))
+ modules.add(modName);
+ assertNull("module should not have an enclosing element", root);
+ } else {
+ if (element instanceof TypeElement) {
+ types.add(((TypeElement) element).getQualifiedName().toString());
+ }
+ assertTrue("Should be a module element", (root instanceof ModuleElement));
+ mod = (ModuleElement) root;
+ modName = mod.getQualifiedName().toString();
+ assertFalse("should be a named module", mod.isUnnamed());
+ String string = mod.getQualifiedName().toString();
+ if (!modules.contains(string) && !modName.equals("java.base"))
+ modules.add(string);
+ }
+ if (modName.equals("module.main")) {
+ mod1 = mod;
+ } else if (modName.equals("module.readable.one")) {
+ mod2 = mod;
+ } else if (modName.equals("module.readable.two")) {
+ mod3 = mod;
+ }
+ }
+ Collections.sort(types, (x, y) -> x.compareTo(y)); //unused as of now
+ Collections.sort(modules, (x, y) -> x.compareTo(y));
+ assertEquals("incorrect no of modules in root elements in "+ this.mode + " mode", 3, modules.size());
+ assertEquals("incorrect modules among root elements in "+ this.mode + " mode", "[module.main, module.readable.one, module.readable.two]", modules.toString());
+ assertNotNull("module should not be null in "+ this.mode + " mode", mod1);
+ assertEquals("Incorrect enclosed packages in "+ this.mode + " mode", "[my1.mod, ]", getElementsAsString(mod1.getEnclosedElements()));
+ assertEquals("Incorrect enclosed packages in "+ this.mode + " mode", "[my1.mod.samePackage, ]", getElementsAsString(mod2.getEnclosedElements()));
+ assertNotNull("module should not be null in "+ this.mode + " mode", mod2);
+ assertNotNull("module should not be null in "+ this.mode + " mode", mod3);
+ assertEquals("Incorrect enclosed packages in "+ this.mode + " mode", "[my1.mod.samePackage, ]", getElementsAsString(mod3.getEnclosedElements()));
+ }
private Element getRoot(Element elem) {
Element enclosingElement = elem.getEnclosingElement();
while (enclosingElement != null) {
diff --git a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java9ElementProcessor.java b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java9ElementProcessor.java
index 0b400a7fd5..a412679a7f 100644
--- a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java9ElementProcessor.java
+++ b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java9ElementProcessor.java
@@ -51,6 +51,7 @@ import javax.lang.model.type.TypeMirror;
import org.eclipse.jdt.compiler.apt.tests.processors.base.BaseProcessor;
import org.eclipse.jdt.compiler.apt.tests.processors.util.TestDirectiveVisitor;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
/**
* A processor that explores the java 9 specific elements and validates the lambda and
@@ -63,6 +64,7 @@ public class Java9ElementProcessor extends BaseProcessor {
boolean reportSuccessAlready = true;
RoundEnvironment roundEnv = null;
Messager _messager = null;
+ boolean isJre12;
boolean isJre11;
boolean isJre10;
@Override
@@ -70,19 +72,14 @@ public class Java9ElementProcessor extends BaseProcessor {
super.init(processingEnv);
_typeUtils = processingEnv.getTypeUtils();
_messager = processingEnv.getMessager();
- try {
- SourceVersion.valueOf("RELEASE_11");
+ String property = System.getProperty("java.specification.version");
+ if (property.equals(CompilerOptions.VERSION_10)) {
this.isJre10 = true;
+ } else if (property.equals(CompilerOptions.VERSION_11)) {
this.isJre11 = true;
- } catch(IllegalArgumentException iae) {
- }
- if (!this.isJre11) {
- try {
- SourceVersion.valueOf("RELEASE_10");
- this.isJre10 = true;
- } catch(IllegalArgumentException iae) {
- }
- }
+ } else if (property.equals(CompilerOptions.VERSION_12)) {
+ this.isJre12 = true;
+ }
}
// Always return false from this processor, because it supports "*".
// The return value does not signify success or failure!
@@ -476,7 +473,7 @@ public class Java9ElementProcessor extends BaseProcessor {
assertNotNull("java.base module null", base);
List<? extends Directive> directives = base.getDirectives();
List<Directive> filterDirective = filterDirective(directives, DirectiveKind.USES);
- assertEquals("incorrect no of uses", this.isJre11? 33 : 34, filterDirective.size());
+ assertEquals("incorrect no of uses", (this.isJre11 || this.isJre12) ? 33 : 34, filterDirective.size());
}
/*
* Test java.base module can be loaded and verify its 'provides' attributes
@@ -530,7 +527,7 @@ public class Java9ElementProcessor extends BaseProcessor {
assertNotNull("java.sql module null", base);
List<? extends Directive> directives = base.getDirectives();
List<Directive> filterDirective = filterDirective(directives, DirectiveKind.REQUIRES);
- assertEquals("Incorrect no of requires", this.isJre11 ? 4 : 3, filterDirective.size());
+ assertEquals("Incorrect no of requires", (this.isJre11 || this.isJre12) ? 4 : 3, filterDirective.size());
RequiresDirective req = null;
for (Directive directive : filterDirective) {
if (((RequiresDirective) directive).getDependency().getQualifiedName().toString().equals("java.logging")) {
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.main/module-info.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.main/module-info.java
new file mode 100644
index 0000000000..a0c0e261a0
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.main/module-info.java
@@ -0,0 +1,6 @@
+module module.main {
+ requires module.readable.one;
+ requires module.readable.two;
+ exports my1.mod;
+}
+
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.main/my1/mod/Main.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.main/my1/mod/Main.java
new file mode 100644
index 0000000000..c8780aa034
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.main/my1/mod/Main.java
@@ -0,0 +1,8 @@
+package my1.mod;
+
+import my1.mod.samePackage.*;
+
+public class Main {
+ public static void main(String argv[]) {
+ }
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.one/module-info.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.one/module-info.java
new file mode 100644
index 0000000000..f334952c59
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.one/module-info.java
@@ -0,0 +1,2 @@
+module module.readable.one {
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.one/my1/mod/samePackage/SomeType.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.one/my1/mod/samePackage/SomeType.java
new file mode 100644
index 0000000000..c06c6e8900
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.one/my1/mod/samePackage/SomeType.java
@@ -0,0 +1,4 @@
+package my1.mod.samePackage;
+
+public class SomeType {
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.two/module-info.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.two/module-info.java
new file mode 100644
index 0000000000..475fe375bb
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.two/module-info.java
@@ -0,0 +1,3 @@
+module module.readable.two {
+ exports my1.mod.samePackage;
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.two/my1/mod/samePackage/SomeType.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.two/my1/mod/samePackage/SomeType.java
new file mode 100644
index 0000000000..9d543b4606
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.two/my1/mod/samePackage/SomeType.java
@@ -0,0 +1,8 @@
+package my1.mod.samePackage;
+
+public class SomeType {
+ public static class NestedClass {
+ }
+ public static int value = 1;
+}
+
diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java12ElementsTests.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java12ElementsTests.java
index 24f27a71de..d1a817a25f 100644
--- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java12ElementsTests.java
+++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java12ElementsTests.java
@@ -50,6 +50,14 @@ public class Java12ElementsTests extends TestCase {
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
internalTestWithBinary(compiler, MODULE_PROC, "12", "testRootElements2", null, "modules3");
}
+ public void testRootElements3Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ internalTestWithBinary(compiler, MODULE_PROC, "12", "testRootElements3", null, "modules4");
+ }
+ public void testRootElements3() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTestWithBinary(compiler, MODULE_PROC, "12", "testRootElements3", null, "modules4");
+ }
protected void internalTestWithBinary(JavaCompiler compiler, String processor, String compliance, String testMethod, String testClass, String resourceArea) throws IOException {
if (!canRunJava12()) {

Back to the top