Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Arthanareeswaran2019-03-01 06:57:36 -0500
committerJay Arthanareeswaran2019-03-02 03:23:21 -0500
commitfe1552846fcd781adf7c2d1952ab882767e9125c (patch)
treea4e0c6f078cf612dbbec860692f577769c7efc36
parent4e22de6b5c96cb008d4a18fa7ee6a605ce7e9a06 (diff)
downloadeclipse.jdt.core-fe1552846fcd781adf7c2d1952ab882767e9125c.tar.gz
eclipse.jdt.core-fe1552846fcd781adf7c2d1952ab882767e9125c.tar.xz
eclipse.jdt.core-fe1552846fcd781adf7c2d1952ab882767e9125c.zip
Bug 544936 - RoundEnvImpl#getRootElements() does not include include
binary modules Change-Id: I7f845d3ceb6894bcefe6296ae9c9ec5bb9625a4d Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/.classpath2
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/build.properties5
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jarbin246813 -> 257099 bytes
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/lib/java10api.jar (renamed from org.eclipse.jdt.compiler.apt.tests/java10/java10api.jar)bin109915 -> 109915 bytes
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors8/META-INF/services/javax.annotation.processing.Processor3
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java12ElementProcessor.java345
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.main/lang/MOD/Main.java8
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.main/module-info.java5
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.one/lang/MOD/same/SomeType.java7
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.one/module-info.java3
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.two/lang/MOD/same/SomeType.java4
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.two/module-info.java2
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.main/module-info.java5
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.main/my/mod/Main.java10
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.readable.one/module-info.java3
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.readable.one/my/mod/same/SomeType.java7
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.readable.two/module-info.java2
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AllTests.java1
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java11
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java12ElementsTests.java109
-rw-r--r--org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/RoundEnvImpl.java12
-rw-r--r--org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ModuleElementImpl.java20
23 files changed, 553 insertions, 13 deletions
diff --git a/org.eclipse.jdt.compiler.apt.tests/.classpath b/org.eclipse.jdt.compiler.apt.tests/.classpath
index 3592a9572a..8102373411 100644
--- a/org.eclipse.jdt.compiler.apt.tests/.classpath
+++ b/org.eclipse.jdt.compiler.apt.tests/.classpath
@@ -16,7 +16,7 @@
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="lib" path="java10/java10api.jar"/>
+ <classpathentry kind="lib" path="lib/java10api.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/org.eclipse.jdt.compiler.apt.tests/META-INF/MANIFEST.MF b/org.eclipse.jdt.compiler.apt.tests/META-INF/MANIFEST.MF
index cd2f132a06..f08a46a4dd 100644
--- a/org.eclipse.jdt.compiler.apt.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.compiler.apt.tests/META-INF/MANIFEST.MF
@@ -19,6 +19,6 @@ Export-Package: org.eclipse.jdt.compiler.apt.tests,
org.eclipse.jdt.compiler.apt.tests.processors.visitors
Import-Package: org.eclipse.jdt.internal.compiler.tool;resolution:=optional
Eclipse-BundleShape: dir
-Bundle-ClassPath: java10/java10api.jar,
+Bundle-ClassPath: lib/java10api.jar,
.
Automatic-Module-Name: org.eclipse.jdt.compiler.apt.tests
diff --git a/org.eclipse.jdt.compiler.apt.tests/build.properties b/org.eclipse.jdt.compiler.apt.tests/build.properties
index e872602914..e9a85ccd3b 100644
--- a/org.eclipse.jdt.compiler.apt.tests/build.properties
+++ b/org.eclipse.jdt.compiler.apt.tests/build.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2006, 2018 BEA Systems Inc. and others
+# Copyright (c) 2006, 2019 BEA Systems Inc. and others
#
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
@@ -23,9 +23,8 @@ bin.includes = about.html,\
test.xml,\
META-INF/,\
resources/,\
- java10/,\
lib/,\
.
src.includes = about.html
compilerArg=-proc:none
-jars.extra.classpath = java10/java10api.jar
+jars.extra.classpath = lib/java10api.jar
diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
index 363e26f2b8..e18d62ebc3 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/java10/java10api.jar b/org.eclipse.jdt.compiler.apt.tests/lib/java10api.jar
index 464b69134f..464b69134f 100644
--- a/org.eclipse.jdt.compiler.apt.tests/java10/java10api.jar
+++ b/org.eclipse.jdt.compiler.apt.tests/lib/java10api.jar
Binary files differ
diff --git a/org.eclipse.jdt.compiler.apt.tests/processors8/META-INF/services/javax.annotation.processing.Processor b/org.eclipse.jdt.compiler.apt.tests/processors8/META-INF/services/javax.annotation.processing.Processor
index 8b8bccf832..4d8344550a 100644
--- a/org.eclipse.jdt.compiler.apt.tests/processors8/META-INF/services/javax.annotation.processing.Processor
+++ b/org.eclipse.jdt.compiler.apt.tests/processors8/META-INF/services/javax.annotation.processing.Processor
@@ -1,3 +1,4 @@
org.eclipse.jdt.compiler.apt.tests.processors.elements.Java8ElementProcessor
org.eclipse.jdt.compiler.apt.tests.processors.elements.Java9ElementProcessor
-org.eclipse.jdt.compiler.apt.tests.processors.elements.Java11ElementProcessor \ No newline at end of file
+org.eclipse.jdt.compiler.apt.tests.processors.elements.Java11ElementProcessor
+org.eclipse.jdt.compiler.apt.tests.processors.elements.Java12ElementProcessor \ No newline at end of file
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
new file mode 100644
index 0000000000..8fcd6b1817
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java12ElementProcessor.java
@@ -0,0 +1,345 @@
+/*******************************************************************************
+ * Copyright (c) 2019 IBM Corporation.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.jdt.compiler.apt.tests.processors.elements;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.annotation.processing.Filer;
+import javax.annotation.processing.Messager;
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.ModuleElement;
+import javax.lang.model.element.PackageElement;
+import javax.lang.model.element.TypeElement;
+
+import org.eclipse.jdt.compiler.apt.tests.processors.base.BaseProcessor;
+
+/**
+ * A processor that explores the java 9 specific elements and validates the lambda and
+ * type annotated elements. To enable this processor, add
+ * -Aorg.eclipse.jdt.compiler.apt.tests.processors.elements.Java11ElementProcessor to the command line.
+ * @since 3.14
+ */
+@SupportedAnnotationTypes("*")
+public class Java12ElementProcessor extends BaseProcessor {
+ boolean reportSuccessAlready = true;
+ RoundEnvironment roundEnv = null;
+ Messager _messager = null;
+ Filer _filer = null;
+ boolean isBinaryMode = false;
+ @Override
+ public synchronized void init(ProcessingEnvironment processingEnv) {
+ super.init(processingEnv);
+ _elementUtils = processingEnv.getElementUtils();
+ _messager = processingEnv.getMessager();
+ _filer = processingEnv.getFiler();
+ }
+ // Always return false from this processor, because it supports "*".
+ // The return value does not signify success or failure!
+ @Override
+ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+ if (roundEnv.processingOver()) {
+ return false;
+ }
+
+ this.roundEnv = roundEnv;
+ Map<String, String> options = processingEnv.getOptions();
+ if (!options.containsKey(this.getClass().getName())) {
+ // Disable this processor unless we are intentionally performing the test.
+ return false;
+ } else {
+ try {
+ if (options.containsKey("binary")) {
+ this.isBinaryMode = true;
+ }
+ if (!invokeTestMethods(options)) {
+ testAll();
+ }
+ if (this.reportSuccessAlready) {
+ super.reportSuccess();
+ }
+ } catch (AssertionFailedError e) {
+ super.reportError(getExceptionStackTrace(e));
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+ return false;
+ }
+
+ private boolean invokeTestMethods(Map<String, String> options) throws Throwable {
+ Method testMethod = null;
+ Set<String> keys = options.keySet();
+ boolean testsFound = false;
+ for (String option : keys) {
+ if (option.startsWith("test")) {
+ try {
+ testMethod = this.getClass().getDeclaredMethod(option, new Class[0]);
+ if (testMethod != null) {
+ testsFound = true;
+ testMethod.invoke(this, new Object[0]);
+ }
+ } catch (InvocationTargetException e) {
+ throw e.getCause();
+ } catch (Exception e) {
+ super.reportError(getExceptionStackTrace(e));
+ }
+ }
+ }
+ return testsFound;
+ }
+
+ public void testAll() throws AssertionFailedError, IOException {
+ testRootElements1();
+ }
+
+ public void testRootElements1() 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", 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()));
+ }
+
+ public void testRootElements2() 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", this.isBinaryMode ? 2 : 3, modules.size());
+ assertEquals("incorrect modules among root elements", "[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);
+ if (!this.isBinaryMode) {
+ assertNotNull("module should not be null", mod3);
+ assertEquals("Incorrect enclosed packages", "[]", getElementsAsString(mod3.getEnclosedElements()));
+ }
+ }
+ private Element getRoot(Element elem) {
+ Element enclosingElement = elem.getEnclosingElement();
+ while (enclosingElement != null) {
+ if (enclosingElement instanceof ModuleElement) {
+ return enclosingElement;
+ }
+ enclosingElement = enclosingElement.getEnclosingElement();
+ }
+ return enclosingElement;
+ }
+
+ @Override
+ public void reportError(String msg) {
+ throw new AssertionFailedError(msg);
+ }
+ private String getExceptionStackTrace(Throwable t) {
+ StringBuffer buf = new StringBuffer(t.getMessage());
+ StackTraceElement[] traces = t.getStackTrace();
+ for (int i = 0; i < traces.length; i++) {
+ StackTraceElement trace = traces[i];
+ buf.append("\n\tat " + trace);
+ if (i == 12)
+ break; // Don't dump all stacks
+ }
+ return buf.toString();
+ }
+ protected String getElementsAsString(List<? extends Element> list) {
+ StringBuilder builder = new StringBuilder("[");
+ for (Element element : list) {
+ if (element instanceof PackageElement) {
+ builder.append(((PackageElement) element).getQualifiedName());
+ } else if (element instanceof ModuleElement) {
+ builder.append(((ModuleElement) element).getQualifiedName());
+ } else if (element instanceof TypeElement) {
+ builder.append(((TypeElement) element).getQualifiedName());
+ } else {
+ builder.append(element.getSimpleName());
+ }
+ builder.append(", ");
+ }
+ builder.append("]");
+ return builder.toString();
+ }
+ public void assertModifiers(Set<Modifier> modifiers, String[] expected) {
+ assertEquals("Incorrect no of modifiers", modifiers.size(), expected.length);
+ Set<String> actual = new HashSet<String>(expected.length);
+ for (Modifier modifier : modifiers) {
+ actual.add(modifier.toString());
+ }
+ for(int i = 0, length = expected.length; i < length; i++) {
+ boolean result = actual.remove(expected[i]);
+ if (!result) reportError("Modifier not present :" + expected[i]);
+ }
+ if (!actual.isEmpty()) {
+ reportError("Unexpected modifiers present:" + actual.toString());
+ }
+ }
+ public void assertTrue(String msg, boolean value) {
+ if (!value) reportError(msg);
+ }
+ public void assertFalse(String msg, boolean value) {
+ if (value) reportError(msg);
+ }
+ public void assertSame(String msg, Object obj1, Object obj2) {
+ if (obj1 != obj2) {
+ reportError(msg + ", should be " + obj1.toString() + " but " + obj2.toString());
+ }
+ }
+ public void assertNotSame(String msg, Object obj1, Object obj2) {
+ if (obj1 == obj2) {
+ reportError(msg + ", " + obj1.toString() + " should not be same as " + obj2.toString());
+ }
+ }
+ public void assertNotNull(String msg, Object obj) {
+ if (obj == null) {
+ reportError(msg);
+ }
+ }
+ public void assertNull(String msg, Object obj) {
+ if (obj != null) {
+ reportError(msg);
+ }
+ }
+ public void assertEquals(String message, Object expected, Object actual) {
+ if (equalsRegardingNull(expected, actual)) {
+ return;
+ } else {
+ reportError(message + ", expected " + expected.toString() + " but was " + actual.toString());
+ }
+ }
+
+ public void assertEquals(String message, Object expected, Object alternateExpected, Object actual) {
+ if (equalsRegardingNull(expected, actual) || equalsRegardingNull(alternateExpected, actual)) {
+ return;
+ } else {
+ reportError(message + ", expected " + expected.toString() + " but was " + actual.toString());
+ }
+ }
+
+ static boolean equalsRegardingNull(Object expected, Object actual) {
+ if (expected == null) {
+ return actual == null;
+ }
+ return expected.equals(actual);
+ }
+
+ public void assertEquals(String msg, int expected, int actual) {
+ if (expected != actual) {
+ StringBuffer buf = new StringBuffer();
+ buf.append(msg);
+ buf.append(", expected " + expected + " but was " + actual);
+ reportError(buf.toString());
+ }
+ }
+ public void assertEquals(Object expected, Object actual) {
+ if (expected != actual) {
+
+ }
+ }
+ private class AssertionFailedError extends Error {
+ private static final long serialVersionUID = 1L;
+
+ public AssertionFailedError(String msg) {
+ super(msg);
+ }
+ }
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.main/lang/MOD/Main.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.main/lang/MOD/Main.java
new file mode 100644
index 0000000000..c11e8d9972
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.main/lang/MOD/Main.java
@@ -0,0 +1,8 @@
+package lang.MOD;
+
+class MyClass { static int meth(lang.MOD.same.SomeType arg) { return arg.value; } }
+
+public class Main {
+ public static void main(String argv[]) {
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.main/module-info.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.main/module-info.java
new file mode 100644
index 0000000000..fd0dc7b74d
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.main/module-info.java
@@ -0,0 +1,5 @@
+module module.main {
+ requires module.readable.one;
+ requires module.readable.two;
+ exports lang.MOD;
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.one/lang/MOD/same/SomeType.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.one/lang/MOD/same/SomeType.java
new file mode 100644
index 0000000000..f7b1468bfa
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.one/lang/MOD/same/SomeType.java
@@ -0,0 +1,7 @@
+package lang.MOD.same;
+
+public class SomeType {
+ public static class NestedClass {
+ }
+ public static int value = 1;
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.one/module-info.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.one/module-info.java
new file mode 100644
index 0000000000..c0dc95931d
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.one/module-info.java
@@ -0,0 +1,3 @@
+module module.readable.one {
+ exports lang.MOD.same to module.main;
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.two/lang/MOD/same/SomeType.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.two/lang/MOD/same/SomeType.java
new file mode 100644
index 0000000000..33a983543d
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.two/lang/MOD/same/SomeType.java
@@ -0,0 +1,4 @@
+package lang.MOD.same;
+
+public class SomeType {
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.two/module-info.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.two/module-info.java
new file mode 100644
index 0000000000..df9b457d55
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.two/module-info.java
@@ -0,0 +1,2 @@
+module module.readable.two {
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.main/module-info.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.main/module-info.java
new file mode 100644
index 0000000000..b755208a1b
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.main/module-info.java
@@ -0,0 +1,5 @@
+module module.main {
+ requires module.readable.one;
+ requires module.readable.two;
+ exports my.mod;
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.main/my/mod/Main.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.main/my/mod/Main.java
new file mode 100644
index 0000000000..b60ff762a8
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.main/my/mod/Main.java
@@ -0,0 +1,10 @@
+package my.mod;
+
+import java.io.PrintStream;
+
+class MyClass { static int meth(my.mod.same.SomeType arg) { return arg.value; } }
+
+public class Main {
+ public static void main(String argv[]) {
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.readable.one/module-info.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.readable.one/module-info.java
new file mode 100644
index 0000000000..75fa2b7cc1
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.readable.one/module-info.java
@@ -0,0 +1,3 @@
+module module.readable.one {
+ exports my.mod.same to module.main;
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.readable.one/my/mod/same/SomeType.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.readable.one/my/mod/same/SomeType.java
new file mode 100644
index 0000000000..8315b02925
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.readable.one/my/mod/same/SomeType.java
@@ -0,0 +1,7 @@
+package my.mod.same;
+
+public class SomeType {
+ public static class NestedClass {
+ }
+ public static int value = 1;
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.readable.two/module-info.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.readable.two/module-info.java
new file mode 100644
index 0000000000..df9b457d55
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.readable.two/module-info.java
@@ -0,0 +1,2 @@
+module module.readable.two {
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AllTests.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AllTests.java
index 9491959c63..413a63d6bc 100644
--- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AllTests.java
+++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AllTests.java
@@ -36,6 +36,7 @@ public class AllTests extends TestCase {
suite.addTestSuite(Java8ElementsTests.class);
suite.addTestSuite(Java9ElementsTests.class);
suite.addTestSuite(Java11ElementsTests.class);
+ suite.addTestSuite(Java12ElementsTests.class);
suite.addTestSuite(AnnotationProcessorTests.class);
return suite;
}
diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java
index 576b5f57c5..6399b841e3 100644
--- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java
+++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java
@@ -31,6 +31,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.ServiceLoader;
@@ -122,11 +123,11 @@ public class BatchTestUtils {
}
public static void compileInModuleMode(JavaCompiler compiler, List<String> options, String processor,
- File targetFolder, DiagnosticListener<? super JavaFileObject> listener, boolean multiModule) {
+ File targetFolder, DiagnosticListener<? super JavaFileObject> listener, boolean multiModule) throws IOException {
compileInModuleMode(compiler, options, processor, targetFolder, listener, multiModule, true);
}
public static void compileInModuleMode(JavaCompiler compiler, List<String> options, String processor,
- File targetFolder, DiagnosticListener<? super JavaFileObject> listener, boolean multiModule, boolean processBinariesAgain) {
+ File targetFolder, DiagnosticListener<? super JavaFileObject> listener, boolean multiModule, boolean processBinariesAgain) throws IOException {
StandardJavaFileManager manager = compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
Iterable<? extends File> location = manager.getLocation(StandardLocation.CLASS_PATH);
// create new list containing inputfile
@@ -145,7 +146,7 @@ public class BatchTestUtils {
copyOptions.add(_tmpBinFolderName);
copyOptions.add("-s");
copyOptions.add(_tmpGenFolderName);
- addModuleProcessorPath(copyOptions, getSrcFolderName(), multiModule);
+ addModuleProcessorPath(copyOptions, targetFolder.getAbsolutePath(), multiModule);
copyOptions.add("-XprintRounds");
CompilationTask task = compiler.getTask(printWriter, manager, listener, copyOptions, null, units);
Boolean result = task.call();
@@ -154,6 +155,8 @@ public class BatchTestUtils {
String errorOutput = stringWriter.getBuffer().toString();
System.err.println("Compilation failed: " + errorOutput);
junit.framework.TestCase.assertTrue("Compilation failed : " + errorOutput, false);
+ } else {
+ junit.framework.TestCase.assertEquals("succeeded", System.getProperty(processor));
}
if (!processBinariesAgain) {
return;
@@ -164,6 +167,7 @@ public class BatchTestUtils {
System.clearProperty(processor);
copyOptions = new ArrayList<>();
copyOptions.addAll(options);
+ copyOptions.add("-Abinary");
copyOptions.add("-cp");
copyOptions.add(_jls8ProcessorJarPath + File.pathSeparator + _tmpGenFolderName);
copyOptions.add("--processor-module-path");
@@ -257,6 +261,7 @@ public class BatchTestUtils {
System.clearProperty(processor);
copyOptions = new ArrayList<>();
copyOptions.addAll(options);
+ copyOptions.add("-Abinary");
copyOptions.add("-cp");
copyOptions.add(_tmpBinFolderName + File.pathSeparator + _jls8ProcessorJarPath + File.pathSeparator + _tmpGenFolderName);
copyOptions.add("-processorpath");
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
new file mode 100644
index 0000000000..24f27a71de
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java12ElementsTests.java
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * Copyright (c) 2019 IBM Corporation.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.jdt.compiler.apt.tests;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.lang.model.SourceVersion;
+import javax.tools.JavaCompiler;
+import javax.tools.ToolProvider;
+
+import org.eclipse.jdt.internal.compiler.tool.EclipseCompiler;
+
+import junit.framework.TestCase;
+
+public class Java12ElementsTests extends TestCase {
+ private static final String MODULE_PROC = "org.eclipse.jdt.compiler.apt.tests.processors.elements.Java12ElementProcessor";
+
+ public void testRootElements1Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ internalTestWithBinary(compiler, MODULE_PROC, "12", "testRootElements1", null, "modules2");
+ }
+ public void testRootElements1() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTestWithBinary(compiler, MODULE_PROC, "12", "testRootElements1", null, "modules2");
+ }
+ public void testRootElements2Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ internalTestWithBinary(compiler, MODULE_PROC, "12", "testRootElements2", null, "modules3");
+ }
+ public void testRootElements2() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTestWithBinary(compiler, MODULE_PROC, "12", "testRootElements2", null, "modules3");
+ }
+
+ protected void internalTestWithBinary(JavaCompiler compiler, String processor, String compliance, String testMethod, String testClass, String resourceArea) throws IOException {
+ if (!canRunJava12()) {
+ return;
+ }
+ System.clearProperty(processor);
+ File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "mod_locations", resourceArea);
+ if (testClass == null || testClass.equals("")) {
+ BatchTestUtils.copyResources("mod_locations/" + resourceArea, targetFolder);
+ } else {
+ BatchTestUtils.copyResource("mod_locations/" + resourceArea + "/" + testClass, targetFolder);
+ }
+
+
+ List<String> options = new ArrayList<String>();
+ options.add("-A" + processor);
+ options.add("-A" + testMethod);
+ options.add("-processor");
+ options.add(processor);
+ // Javac 1.8 doesn't (yet?) support the -1.8 option
+ if (compiler instanceof EclipseCompiler) {
+ options.add("-" + compliance);
+ } else {
+ options.add("-source");
+ options.add(compliance);
+ }
+ BatchTestUtils.compileInModuleMode(compiler, options, processor, targetFolder, null, true);
+ // If it succeeded, the processor will have set this property to "succeeded";
+ // if not, it will set it to an error value.
+ assertEquals("succeeded", System.getProperty(processor));
+ }
+ public boolean canRunJava12() {
+ try {
+ SourceVersion.valueOf("RELEASE_12");
+ } catch(IllegalArgumentException iae) {
+ return false;
+ }
+ return true;
+ }
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ BatchTestUtils.init();
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/RoundEnvImpl.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/RoundEnvImpl.java
index 185dfd8f8a..00afab42dd 100644
--- a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/RoundEnvImpl.java
+++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/RoundEnvImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2017 IBM Corporation and others.
+ * Copyright (c) 2005, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* IBM Corporation - Fix for bug 328575
@@ -34,6 +38,7 @@ import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding;
import org.eclipse.jdt.internal.compiler.lookup.Binding;
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
+import org.eclipse.jdt.internal.compiler.lookup.ModuleBinding;
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
@@ -235,6 +240,11 @@ public class RoundEnvImpl implements RoundEnvironment
throw new IllegalArgumentException("Top-level type binding could not be converted to element: " + typeBinding); //$NON-NLS-1$
}
elements.add(element);
+ ModuleBinding binding = typeBinding.module();
+ if (binding != null) {
+ Element m = _factory.newElement(binding);
+ elements.add(m);
+ }
}
}
_rootElements = elements;
diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ModuleElementImpl.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ModuleElementImpl.java
index adda859990..e6e473e91c 100644
--- a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ModuleElementImpl.java
+++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ModuleElementImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2018 IBM Corporation and others.
+ * Copyright (c) 2018, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,11 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*
@@ -90,8 +94,18 @@ public class ModuleElementImpl extends ElementImpl implements ModuleElement {
for (PackageBinding p : packs) {
if (p == null)
continue;
- if (!p.hasCompilationUnit(true))
+ if (p instanceof SplitPackageBinding) {
+ // select from incarnations the unique package containing CUs, if any:
+ for (PackageBinding incarnation : ((SplitPackageBinding) p).incarnations) {
+ if (incarnation.enclosingModule == module && incarnation.hasCompilationUnit(true)) {
+ unique.add(getModulesPackageBinding(p));
+ }
+ }
continue;
+ } else {
+ if (!p.hasCompilationUnit(true))
+ continue;
+ }
unique.add(getModulesPackageBinding(p));
}
if (module.isUnnamed()) {

Back to the top