Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Arthanareeswaran2017-09-26 01:12:23 -0400
committerJay Arthanareeswaran2017-09-26 01:12:23 -0400
commit6e12fb6ec6e1d5f33bccd05064d28125c2b11ca2 (patch)
treeb13fa9d1c9ed255ba38d91da4dfa91c72c27ea71 /org.eclipse.jdt.compiler.apt.tests
parent0a908cd3dc3279066d94660987f6e5450b72486e (diff)
parente3cdffd4f3b18ecae4adb6ba136baca629984afc (diff)
downloadeclipse.jdt.core-6e12fb6ec6e1d5f33bccd05064d28125c2b11ca2.tar.gz
eclipse.jdt.core-6e12fb6ec6e1d5f33bccd05064d28125c2b11ca2.tar.xz
eclipse.jdt.core-6e12fb6ec6e1d5f33bccd05064d28125c2b11ca2.zip
Merge remote-tracking branch 'origin/BETA_JAVA9'
# Conflicts: # org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java # org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java # org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java # org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java # org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/util/Util.java # org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java Change-Id: Id40b6810011281c7f3d334b53b5e54168ebbc57f
Diffstat (limited to 'org.eclipse.jdt.compiler.apt.tests')
-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.properties4
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/java9/java9api.jarbin0 -> 25089 bytes
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jarbin206442 -> 207081 bytes
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jarbin210595 -> 232966 bytes
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/pom.xml6
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/AnnotationProcessorTests/Bug340635Proc.java10
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/base/XMLConverter.java2
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/elements/ElementProc.java16
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/inherited/ArgsConstructorProcessor.java17
-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/Java8ElementProcessor.java97
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java9ElementProcessor.java829
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.a/abc/internal/A.java3
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.a/abc/internal/TypeInAModule.java5
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.a/abc/internal/pqr/A.java2
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.a/module-info.java7
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.b/abc/A.java3
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.b/module-info.java6
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.b/pqr/ext/B.java2
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/targets/bug520540/GenericType.java13
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/targets/bug521723/Main.java13
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/targets/bug521812/MyEnum.java10
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/targets/model9/X.java40
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/targets/model9/p/A.java3
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/targets/model9a/internal/GenericType.java7
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AllTests.java3
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchDispatchTests.java6
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java201
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/FileManagerTests.java17
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/FilerTests.java2
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java8ElementsTests.java121
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java9ElementsTests.java515
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/NegativeTests.java2
35 files changed, 1904 insertions, 65 deletions
diff --git a/org.eclipse.jdt.compiler.apt.tests/.classpath b/org.eclipse.jdt.compiler.apt.tests/.classpath
index 6d510c6323..2dc14fa091 100644
--- a/org.eclipse.jdt.compiler.apt.tests/.classpath
+++ b/org.eclipse.jdt.compiler.apt.tests/.classpath
@@ -4,7 +4,7 @@
<classpathentry kind="src" output="binprocessors" path="processors"/>
<classpathentry kind="src" output="binprocessors8" path="processors8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="lib" path="rtstubs18.jar"/>
+ <classpathentry kind="lib" path="java9/java9api.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 31d60e1a90..5db66bc805 100644
--- a/org.eclipse.jdt.compiler.apt.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.compiler.apt.tests/META-INF/MANIFEST.MF
@@ -19,3 +19,5 @@ 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: java9/java9api.jar,
+ .
diff --git a/org.eclipse.jdt.compiler.apt.tests/build.properties b/org.eclipse.jdt.compiler.apt.tests/build.properties
index bc8963d977..7df12f4db2 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, 2013 BEA Systems Inc. and others
+# Copyright (c) 2006, 2017 BEA Systems Inc. and others
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
@@ -20,7 +20,9 @@ bin.includes = about.html,\
test.xml,\
META-INF/,\
resources/,\
+ java9/,\
lib/,\
.
src.includes = about.html
compilerArg=-proc:none
+jars.extra.classpath = java9/java9api.jar
diff --git a/org.eclipse.jdt.compiler.apt.tests/java9/java9api.jar b/org.eclipse.jdt.compiler.apt.tests/java9/java9api.jar
new file mode 100644
index 0000000000..fd56ad100e
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/java9/java9api.jar
Binary files differ
diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar
index ed4b4d1a39..69a7439122 100644
--- a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar
+++ b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar
Binary files differ
diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
index 2c4c285f5d..4fc9a5e2e9 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/pom.xml b/org.eclipse.jdt.compiler.apt.tests/pom.xml
index 8afca506e1..5b693ef615 100644
--- a/org.eclipse.jdt.compiler.apt.tests/pom.xml
+++ b/org.eclipse.jdt.compiler.apt.tests/pom.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright (c) 2012, 2016 Eclipse Foundation and others.
+ Copyright (c) 2012, 2017 Eclipse Foundation and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Distribution License v1.0
which accompanies this distribution, and is available at
@@ -34,6 +34,10 @@
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<configuration>
+ <compilerArgs>
+ <args>-endorseddirs</args>
+ <args>${basedir}/lib</args>
+ </compilerArgs>
<dependency-resolution>
<!--
these fragments are assumed to be present during compile and runtime.
diff --git a/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/AnnotationProcessorTests/Bug340635Proc.java b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/AnnotationProcessorTests/Bug340635Proc.java
index ca60bf979f..47ff563fdc 100644
--- a/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/AnnotationProcessorTests/Bug340635Proc.java
+++ b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/AnnotationProcessorTests/Bug340635Proc.java
@@ -1,10 +1,14 @@
/*******************************************************************************
- * Copyright (c) 2015 IBM Corporation and others.
+ * Copyright (c) 2015, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
+ * 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:
* Kevin Pollet - SERLI - (kevin.pollet@serli.com) - initial API and implementation
*******************************************************************************/
@@ -66,7 +70,7 @@ public class Bug340635Proc extends AbstractProcessor {
private class GenericTypeVisitor extends SimpleTypeVisitor6<DeclaredType, Void> {
private final Types types;
-
+ @Deprecated
public GenericTypeVisitor(Types types) {
this.types = types;
}
diff --git a/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/base/XMLConverter.java b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/base/XMLConverter.java
index cb5763507e..37df722348 100644
--- a/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/base/XMLConverter.java
+++ b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/base/XMLConverter.java
@@ -50,7 +50,7 @@ import org.w3c.dom.Node;
public class XMLConverter extends ElementScanner6<Void, Node> implements IXMLNames {
private final Document _doc;
-
+ @Deprecated
private XMLConverter(Document doc) {
_doc = doc;
}
diff --git a/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/elements/ElementProc.java b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/elements/ElementProc.java
index c9f44a33e6..2befc4b28c 100644
--- a/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/elements/ElementProc.java
+++ b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/elements/ElementProc.java
@@ -5,6 +5,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
+ * 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:
* wharley@bea.com - initial API and implementation
* akurtakov@gmail.com - fix compilation with Java 7
@@ -148,6 +152,9 @@ public class ElementProc extends BaseProcessor {
if(!bug300408()) {
return false;
}
+ if (!examineTypesInPackage()) {
+ return false;
+ }
if (!bug467928_enumFields()) {
return false;
@@ -1041,4 +1048,13 @@ public class ElementProc extends BaseProcessor {
}
return true;
}
+ private boolean examineTypesInPackage() {
+ PackageElement pack = _elementUtils.getPackageElement("java.util.concurrent");
+ List<? extends Element> enclosedElements = pack.getEnclosedElements();
+ if (enclosedElements.size() == 0) {
+ reportError("Should find types in package java.util.concurrent");
+ return false;
+ }
+ return true;
+ }
}
diff --git a/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/inherited/ArgsConstructorProcessor.java b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/inherited/ArgsConstructorProcessor.java
index e6e8e4692b..b8aa884386 100644
--- a/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/inherited/ArgsConstructorProcessor.java
+++ b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/inherited/ArgsConstructorProcessor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation and others.
+ * Copyright (c) 2011, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -16,14 +16,20 @@ import java.util.Map.Entry;
import java.util.Set;
import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.annotation.processing.SupportedSourceVersion;
+import javax.lang.model.SourceVersion;
import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
-import javax.annotation.processing.*;
-import javax.lang.model.SourceVersion;
-import javax.lang.model.element.*;
-import javax.lang.model.type.*;
+import javax.lang.model.type.ExecutableType;
+import javax.lang.model.type.TypeKind;
+import javax.lang.model.type.TypeMirror;
+import javax.lang.model.type.TypeVisitor;
import javax.lang.model.util.SimpleTypeVisitor6;
import javax.lang.model.util.Types;
import javax.tools.Diagnostic.Kind;
@@ -155,6 +161,7 @@ public class ArgsConstructorProcessor extends BaseProcessor {
}
private final TypeVisitor<Boolean, List<TypeMirror>> argsVisitor = new SimpleTypeVisitor6<Boolean, List<TypeMirror>>() {
+ @Override
public Boolean visitExecutable(ExecutableType t,
List<TypeMirror> annotatedTypes) {
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 5555121aae..839d9ea2ee 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 +1,2 @@
-org.eclipse.jdt.compiler.apt.tests.processors.elements.Java8ElementProcessor \ No newline at end of file
+org.eclipse.jdt.compiler.apt.tests.processors.elements.Java8ElementProcessor
+org.eclipse.jdt.compiler.apt.tests.processors.elements.Java9ElementProcessor \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java8ElementProcessor.java b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java8ElementProcessor.java
index 077d7079af..078e88f6f5 100644
--- a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java8ElementProcessor.java
+++ b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java8ElementProcessor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013, 2016 IBM Corporation.
+ * Copyright (c) 2013, 2017 IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -17,6 +17,7 @@ import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -75,15 +76,15 @@ import org.eclipse.jdt.compiler.apt.tests.processors.base.BaseProcessor;
@SupportedSourceVersion(SourceVersion.RELEASE_8)
public class Java8ElementProcessor extends BaseProcessor {
- private static final String[] ELEMENT_NAMES = new String[] {"targets.model8.X", "T", "U", "K", "V", "KK", "VV", "KKK", "VVV"};
- private static final String[] TYPE_PARAM_ELEMENTS_Z1 = new String[] {"KK", "VV"};
- private static final String[] TYPE_PARAM_ELEMENTS_Z2 = new String[] {"KKK", "VVV"};
- String simpleName = "filer8";
- String packageName = "targets.filer8";
- int roundNo = 0;
- boolean reportSuccessAlready = true;
+ private static final String[] ELEMENT_NAMES = new String[] {"targets.model8.X", "T", "U", "K", "V", "KK", "VV", "KKK", "VVV"};
+ private static final String[] TYPE_PARAM_ELEMENTS_Z1 = new String[] {"KK", "VV"};
+ private static final String[] TYPE_PARAM_ELEMENTS_Z2 = new String[] {"KKK", "VVV"};
+ String simpleName = "filer8";
+ String packageName = "targets.filer8";
+ int roundNo = 0;
+ boolean reportSuccessAlready = true;
- RoundEnvironment roundEnv = null;
+ protected RoundEnvironment roundEnv = null;
// Always return false from this processor, because it supports "*".
// The return value does not signify success or failure!
@Override
@@ -168,7 +169,9 @@ public class Java8ElementProcessor extends BaseProcessor {
testRepeatedAnnotations25();
testTypeAnnotations26();
testTypeAnnotations27();
- testPackageAnnotations();
+ //testPackageAnnotations();
+ testBug520540();
+ testEnumConstArguments();
}
public void testLambdaSpecifics() {
@@ -320,10 +323,10 @@ public class Java8ElementProcessor extends BaseProcessor {
}
List<? extends VariableElement> params = method.getParameters();
assertEquals("Incorrect no of params for method bar()", 2, params.size());
- VariableElement param = (VariableElement) params.get(0);
+ VariableElement param = params.get(0);
TypeMirror typeMirror = param.asType();
verifyAnnotations(typeMirror, new String[]{"@Type(value=p1)"});
- param = (VariableElement) params.get(1);
+ param = params.get(1);
typeMirror = param.asType();
verifyAnnotations(typeMirror, new String[]{"@Type(value=p2)"});
}
@@ -405,7 +408,7 @@ public class Java8ElementProcessor extends BaseProcessor {
assertNotNull("Method should not be null", method);
List<? extends VariableElement> params = method.getParameters();
assertEquals("Incorrect no of params for method bar()", 2, params.size());
- VariableElement param = (VariableElement) params.get(0);
+ VariableElement param = params.get(0);
TypeMirror typeMirror = param.asType();
verifyAnnotations(typeMirror, new String[]{"@Type(value=p2)"});
assertEquals("Should be an array type", TypeKind.ARRAY, typeMirror.getKind());
@@ -416,7 +419,7 @@ public class Java8ElementProcessor extends BaseProcessor {
typeMirror = ((ArrayType) typeMirror).getComponentType();
verifyAnnotations(typeMirror, new String[]{"@Type(value=p1)"});
- param = (VariableElement) params.get(1);
+ param = params.get(1);
typeMirror = param.asType();
verifyAnnotations(typeMirror, new String[]{});
assertEquals("Should be an array type", TypeKind.ARRAY, typeMirror.getKind());
@@ -538,7 +541,7 @@ public class Java8ElementProcessor extends BaseProcessor {
VariableElement field2 = null;
for (VariableElement member : ElementFilter.fieldsIn(members)) {
if ("_field2".equals(member.getSimpleName().toString())) {
- field2 = (VariableElement) member;
+ field2 = member;
break;
}
}
@@ -599,8 +602,7 @@ public class Java8ElementProcessor extends BaseProcessor {
assertTrue("Found unexpected extra elements", expectedElementNames.isEmpty());
}
- public void testTypeAnnotations12() {
- TypeElement annotatedType = _elementUtils.getTypeElement("targets.model8.X");
+ private void tTypeAnnotations12(TypeElement annotatedType) {
List<? extends Element> members = _elementUtils.getAllMembers(annotatedType);
ExecutableElement bar2 = null;
ExecutableElement constr = null;
@@ -629,6 +631,16 @@ public class Java8ElementProcessor extends BaseProcessor {
type = (ExecutableType) constr2.asType();
verifyAnnotations(type, new String[]{});
}
+
+ public void testTypeAnnotations12() {
+ TypeElement annotatedType = _elementUtils.getTypeElement("targets.model8.X");
+ tTypeAnnotations12(annotatedType);
+ }
+
+ public void testTypeAnnotations12Binary() {
+ TypeElement annotatedType = _elementUtils.getTypeElement("targets.model9.X");
+ tTypeAnnotations12(annotatedType);
+ }
public void testTypeAnnotations13() {
TypeElement annotatedType = _elementUtils.getTypeElement("targets.model8.X");
@@ -637,7 +649,7 @@ public class Java8ElementProcessor extends BaseProcessor {
VariableElement field = null;
for (VariableElement member : ElementFilter.fieldsIn(members)) {
if ("_i".equals(member.getSimpleName().toString())) {
- field = (VariableElement) member;
+ field = member;
break;
}
}
@@ -974,7 +986,9 @@ public class Java8ElementProcessor extends BaseProcessor {
}
}
- public boolean testPackageAnnotations() {
+ // Disabled for now. Javac includes the CLASS element of the package-info in the root element if there's one.
+ // But ECJ includes the Package element.
+ public void testPackageAnnotations() {
if ( roundNo++ == 0) {
this.reportSuccessAlready = false;
try {
@@ -983,20 +997,58 @@ public class Java8ElementProcessor extends BaseProcessor {
e.printStackTrace();
}
System.setProperty(this.getClass().getName(), "Processor did not fully do the job");
- return false;
} else {
this.reportSuccessAlready = true;
PackageElement packageEl = null;
for (Element element : roundEnv.getRootElements()) {
if (element.getKind() == ElementKind.PACKAGE) {
packageEl = (PackageElement) element;
+ } else {
+ System.out.println(element);
}
}
assertNotNull("Package element should not be null", packageEl);
assertEquals("Incorrect package name", simpleName, packageEl.getSimpleName().toString());
assertEquals("Incorrect package name", packageName, packageEl.getQualifiedName().toString());
assertFalse("Package should not be unnamed", packageEl.isUnnamed());
- return false;
+ }
+ }
+ public void testBug520540() {
+ PackageElement packageElement = _elementUtils.getPackageElement("targets.bug520540");
+ assertNotNull("package element should not be null", packageElement);
+ List<? extends Element> enclosedElements = packageElement.getEnclosedElements();
+ assertEquals("Incorrect no of elements", 5, enclosedElements.size());
+ List<String> typeElements = new ArrayList<>();
+ for (Element element : enclosedElements) {
+ if (element instanceof TypeElement) {
+ typeElements.add(((TypeElement) element).getQualifiedName().toString());
+ }
+ }
+ String[] types = new String[] { "targets.bug520540.GenericType", "targets.bug520540.MyEnum",
+ "targets.bug520540.TypeEx", "targets.bug520540.TypeA", "targets.bug520540.AnnotB" };
+ for (String string : types) {
+ typeElements.remove(string);
+ }
+ assertEquals("found incorrect types", 0, typeElements.size());
+ }
+ public void testEnumConstArguments() {
+ TypeElement annotatedType = _elementUtils.getTypeElement("targets.bug521812.MyEnum");
+ List<? extends Element> enclosedElements = annotatedType.getEnclosedElements();
+ ExecutableElement constr = null;
+ for (Element element : enclosedElements) {
+ if (element.getSimpleName().toString().equals("<init>")) {
+ constr = (ExecutableElement) element;
+ }
+ }
+ assertNotNull("constructor should not be null", constr);
+ List<? extends VariableElement> parameters = constr.getParameters();
+ ExecutableType asType = (ExecutableType) constr.asType();
+ List<? extends TypeMirror> parameterTypes = asType.getParameterTypes();
+ assertEquals("param count and param type count should be same", parameters.size(), parameterTypes.size());
+ for(int i = 0; i < parameters.size(); i++) {
+ VariableElement param = parameters.get(i);
+ TypeMirror asType2 = param.asType();
+ assertEquals("Parameter type should be same", param.asType(), asType2);
}
}
private void createPackageBinary() throws IOException {
@@ -1077,11 +1129,12 @@ public class Java8ElementProcessor extends BaseProcessor {
Type[] annots = construct.getAnnotationsByType(Type.class);
assertEquals(msg + "Incorrect no of annotations", 1, annots.length);
- annot = (Type) annots[0];
+ annot = annots[0];
assertSame(msg + "Invalid annotation type" , Type.class, annots[0].annotationType());
assertEquals(msg + "Invalid annotation value", value, annot.value());
}
+ @Override
public void reportError(String msg) {
throw new AssertionFailedError(msg);
}
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
new file mode 100644
index 0000000000..6f0d9224bf
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java9ElementProcessor.java
@@ -0,0 +1,829 @@
+/*******************************************************************************
+ * Copyright (c) 2017 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * 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.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.Messager;
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.lang.model.AnnotatedConstruct;
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.AnnotationValue;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.ModuleElement;
+import javax.lang.model.element.ModuleElement.Directive;
+import javax.lang.model.element.ModuleElement.DirectiveKind;
+import javax.lang.model.element.ModuleElement.ExportsDirective;
+import javax.lang.model.element.ModuleElement.ProvidesDirective;
+import javax.lang.model.element.ModuleElement.RequiresDirective;
+import javax.lang.model.element.PackageElement;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.type.DeclaredType;
+import javax.lang.model.type.NoType;
+import javax.lang.model.type.TypeKind;
+import javax.lang.model.type.TypeMirror;
+
+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.Java9ElementProcessor to the command line.
+ * @since 3.13 BETA_JAVA9
+ */
+@SupportedAnnotationTypes("*")
+public class Java9ElementProcessor extends BaseProcessor {
+ boolean reportSuccessAlready = true;
+ RoundEnvironment roundEnv = null;
+ Messager _messager = null;
+ @Override
+ public synchronized void init(ProcessingEnvironment processingEnv) {
+ super.init(processingEnv);
+ _typeUtils = processingEnv.getTypeUtils();
+ _messager = processingEnv.getMessager();
+ }
+ // 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 (!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 {
+ testModuleAnnotation1();
+ testModuleElement1();
+ testModuleElement2();
+ testModuleElement3();
+ testModuleElement4();
+ testModuleElement5();
+ testModuleElement6();
+ testModuleElement7();
+ testModuleJavaBase1();
+ testModuleJavaBase2();
+ testModuleJavaBase3();
+ testModuleJavaBase4();
+ testModuleJavaBase5();
+ testModuleTypeMirror1();
+ testModuleTypeMirror2();
+ testModuleJavaSql1();
+ testSourceModule1();
+ testSourceModule2();
+ testRootElements1();
+ testRootElements2();
+ testUnnamedModule1();
+ testUnnamedModule2();
+ testUnnamedModule3();
+ testUnnamedModule4();
+ testUnnamedModule5();
+ }
+
+ private Element getRoot(Element elem) {
+ Element enclosingElement = elem.getEnclosingElement();
+ while (enclosingElement != null) {
+ if (enclosingElement instanceof ModuleElement) {
+ return enclosingElement;
+ }
+ enclosingElement = enclosingElement.getEnclosingElement();
+ }
+ return enclosingElement;
+ }
+
+ public void testRootElements1() {
+ Set<? extends Element> rootElements = this.roundEnv.getRootElements();
+ int typeCount = 0;
+ int moduleCount = 0;
+ List<String> types = new ArrayList<>();
+ List<String> modules = new ArrayList<>();
+ for (Element element : rootElements) {
+ Element root = getRoot(element);
+ if (element instanceof ModuleElement) {
+ ModuleElement mod = (ModuleElement) element;
+ moduleCount++;
+ modules.add(mod.getQualifiedName().toString());
+ assertNull("module should not have an enclosing element", root);
+ } else {
+ if (element instanceof TypeElement) {
+ typeCount++;
+ types.add(((TypeElement) element).getQualifiedName().toString());
+ }
+ assertTrue("Should be a module element", (root instanceof ModuleElement));
+ assertFalse("should be a named module", ((ModuleElement) root).isUnnamed());
+ }
+ }
+ Collections.sort(types, (x, y) -> x.compareTo(y));
+ Collections.sort(modules, (x, y) -> x.compareTo(y));
+ assertEquals("incorrect no of modules in root elements", 2, moduleCount);
+ assertEquals("incorrect modules among root elements", "[mod.a, mod.b]", modules.toString());
+ assertEquals("incorrect no of types in root elements", 5, typeCount);
+ assertEquals("incorrect types among root elements",
+ "[abc.A, abc.internal.A, abc.internal.TypeInAModule, abc.internal.pqr.A, pqr.ext.B]",
+ types.toString());
+ }
+ // Test the types part of root elements get the modules right
+ public void testRootElements2() {
+ Set<? extends Element> rootElements = this.roundEnv.getRootElements();
+ TypeElement type = null;
+ ModuleElement modFromRoot = null;
+ for (Element element : rootElements) {
+ if (element instanceof TypeElement && ((TypeElement) element).getSimpleName().toString().equals("TypeInAModule")) {
+ type = (TypeElement) element;
+ }
+ if (element instanceof ModuleElement && ((ModuleElement) element).getQualifiedName().toString().equals("mod.a")) {
+ modFromRoot = (ModuleElement) element;
+ }
+ }
+ assertNotNull("type should not be null", type);
+ assertNotNull("module from root elements should not be null", modFromRoot);
+ ModuleElement module = _elementUtils.getModuleOf(type);
+ assertNotNull("type's module should not be null", module);
+ assertEquals("modules should be equals", module, modFromRoot);
+ }
+ /*
+ * Test module element can be retrieved and
+ * annotations on module declarations can be retrieved
+ */
+ public void testModuleAnnotation1() {
+ CharSequence name = "mod.a";
+ ModuleElement mod = _elementUtils.getModuleElement(name);
+ assertNotNull("Module element should not be null", mod);
+ List<? extends AnnotationMirror> annotationMirrors = mod.getAnnotationMirrors();
+ assertNotNull("Should not be null", annotationMirrors);
+ verifyAnnotations(mod, new String[]{"@java.lang.Deprecated()"});
+ List<? extends Element> enclosedElements = mod.getEnclosedElements();
+ PackageElement pack = null;
+ for (Element element : enclosedElements) {
+ if (element instanceof PackageElement) {
+ pack = (PackageElement) element;
+ break;
+ }
+ }
+ assertNotNull("Package not found", pack);
+ Element elem = pack.getEnclosingElement();
+ assertNotNull("Parent not found", elem);
+ assertTrue("Parent should be a module", (elem instanceof ModuleElement));
+ assertEquals("Incorrect module element", "mod.a", ((ModuleElement) elem).getQualifiedName().toString());
+ }
+ /*
+ * Test module element can be retrieved and attributed are
+ * verified against declaration
+ */
+ public void testModuleElement1() {
+ CharSequence name = "mod.a";
+ ModuleElement mod = _elementUtils.getModuleElement(name);
+ assertEquals("incorrect name", "mod.a", mod.getQualifiedName().toString());
+ assertEquals("incorrect name", "mod.a", mod.getQualifiedName().toString());
+ List<? extends Element> enclosedElements = mod.getEnclosedElements();
+ PackageElement pack = null;
+ for (Element element : enclosedElements) {
+ if (element instanceof PackageElement && ((PackageElement) element).getQualifiedName().toString().equals("abc.internal")) {
+ pack = (PackageElement) element;
+ break;
+ }
+ }
+ assertNotNull("Package not found", pack);
+ Element elem = pack.getEnclosingElement();
+ assertNotNull("Parent not found", elem);
+ assertTrue("Parent should be a module", (elem instanceof ModuleElement));
+ assertEquals("Incorrect module element", "mod.a", ((ModuleElement) elem).getQualifiedName().toString());
+ }
+ /*
+ * Test type elements can be retrieved from Elements API with and without
+ * the context of the module the type is in.
+ */
+ public void testModuleElement2() {
+ CharSequence name = "mod.a";
+ ModuleElement mod = _elementUtils.getModuleElement(name);
+ TypeElement typeElement = _elementUtils.getTypeElement(mod, "abc.internal.TypeInAModule");
+ assertNotNull("Type should not be null", typeElement);
+ typeElement = _elementUtils.getTypeElement("abc.internal.TypeInAModule");
+ assertNotNull("Type should not be null", typeElement);
+ ModuleElement m = _elementUtils.getModuleOf(typeElement);
+ assertEquals("modules should be same", mod, m);
+ ModuleElement mElement = _elementUtils.getModuleOf(typeElement);
+ assertNotNull("module should not be null", mElement);
+ assertEquals("Incorrect module element", "mod.a", mElement.getQualifiedName().toString());
+ }
+ /*
+ * Test binary modules from JRT system can be loaded and its attributes
+ * as expected
+ */
+ public void testModuleElement3() {
+ Set<? extends ModuleElement> allModuleElements = _elementUtils.getAllModuleElements();
+ ModuleElement base = null;
+ ModuleElement compiler = null;
+ for (ModuleElement moduleElement : allModuleElements) {
+ if (moduleElement.getQualifiedName().toString().equals("java.base")) {
+ base = moduleElement;
+ }
+ if (moduleElement.getQualifiedName().toString().equals("java.compiler")) {
+ compiler = moduleElement;
+ }
+ }
+ assertNotNull("java.base module null", base);
+ assertNotNull("java.compiler module null", compiler);
+ assertNull("Enclosing element should be null", base.getEnclosingElement());
+ assertEquals("Incorrect element kind", ElementKind.MODULE, base.getKind());
+ assertFalse("Should be named", base.isUnnamed());
+ assertFalse("Should not be open", base.isOpen());
+
+ }
+ /*
+ * Test packages can be retrieved with the Elements API with and without
+ * the context of its module.
+ */
+ public void testModuleElement4() {
+ CharSequence name = "mod.a";
+ ModuleElement mod = _elementUtils.getModuleElement(name);
+ PackageElement pElement = _elementUtils.getPackageElement("abc.internal");
+ assertNotNull("Package should not be null", pElement);
+ pElement = _elementUtils.getPackageElement(mod, "abc.internal");
+ assertNotNull("Package should not be null", pElement);
+ ModuleElement mElement = _elementUtils.getModuleOf(pElement);
+ assertNotNull("module should not be null", mElement);
+ assertEquals("Incorrect module element", "mod.a", mElement.getQualifiedName().toString());
+ assertEquals("Modules should be same", mod, mElement);
+ }
+ /*
+ * Test packages can be retrieved with Elements API and they contain
+ * the right module element.
+ */
+ public void testModuleElement5() {
+ CharSequence name = "mod.a";
+ ModuleElement mod = _elementUtils.getModuleElement(name);
+ Set<? extends PackageElement> allPackageElements = _elementUtils.getAllPackageElements("abc.internal.pqr");
+ assertEquals("Incorrect no of packages", 1, allPackageElements.size());
+ PackageElement pElement = null;
+ for (PackageElement packageElement : allPackageElements) {
+ pElement = packageElement;
+ }
+ assertNotNull("Package should not be null", pElement);
+ ModuleElement mElement = _elementUtils.getModuleOf(pElement);
+ assertNotNull("module should not be null", mElement);
+ assertEquals("Incorrect module element", "mod.a", mElement.getQualifiedName().toString());
+ assertEquals("Modules should be same", mod, mElement);
+
+ allPackageElements = _elementUtils.getAllPackageElements("abc");
+ assertEquals("Incorrect no of packages", 2, allPackageElements.size());
+ List<ModuleElement> mods = new ArrayList<>();
+ for (PackageElement packageElement : allPackageElements) {
+ mElement = _elementUtils.getModuleOf(packageElement);
+ mods.add(mElement);
+ }
+ assertEquals("incorrect no of modules", 2, mods.size());
+ mods.remove(mod);
+ mod = _elementUtils.getModuleElement("mod.b");
+ assertNotNull("mod b should not be null", mod);
+ mods.remove(mod);
+ assertEquals("incorrect no of modules", 0, mods.size());
+ }
+ /*
+ * Test type elements can be loaded and contain the correct module
+ * elements
+ */
+ public void testModuleElement6() {
+ CharSequence name = "mod.a";
+ ModuleElement mod = _elementUtils.getModuleElement(name);
+ Set<? extends TypeElement> typeElements = _elementUtils.getAllTypeElements("abc.internal.A");
+ assertNotNull("Type should not be null", typeElements);
+ assertEquals("Incorrect no of types", 1, typeElements.size());
+ TypeElement tElement = null;
+ for (TypeElement typeElement : typeElements) {
+ tElement = typeElement;
+ }
+ assertNotNull("Package should not be null", tElement);
+ ModuleElement mElement = _elementUtils.getModuleOf(tElement);
+ assertNotNull("module should not be null", mElement);
+ assertEquals("Incorrect module element", "mod.a", mElement.getQualifiedName().toString());
+ assertEquals("Modules should be same", mod, mElement);
+ }
+ /*
+ * Test that a module not part of the root modules can NOT be retrieved.
+ */
+ public void testModuleElement7() {
+ // test that a random module from system unrelated to the module we are compiling is not loaded by the compiler
+ Set<? extends ModuleElement> allModuleElements = _elementUtils.getAllModuleElements();
+ ModuleElement mod = null;
+ for (ModuleElement moduleElement : allModuleElements) {
+ if (moduleElement.getQualifiedName().toString().equals("java.desktop")) {
+ mod = moduleElement;
+ }
+ }
+ assertNull("module java.desktop should not be found", mod);
+ }
+ /*
+ * Test java.base module can be loaded and verify its exports attributes
+ */
+ public void testModuleJavaBase1() {
+ Set<? extends ModuleElement> allModuleElements = _elementUtils.getAllModuleElements();
+ ModuleElement base = null;
+ for (ModuleElement moduleElement : allModuleElements) {
+ if (moduleElement.getQualifiedName().toString().equals("java.base")) {
+ base = moduleElement;
+ }
+ }
+ assertNotNull("java.base module null", base);
+ List<? extends Directive> directives = base.getDirectives();
+ List<Directive> filterDirective = filterDirective(directives, DirectiveKind.EXPORTS);
+ assertEquals("incorrect no of exports", 108 , filterDirective.size());
+ ExportsDirective pack = null;
+ for (Directive directive : filterDirective) {
+ ModuleElement.ExportsDirective exports = (ExportsDirective) directive;
+ if (exports.getPackage().getQualifiedName().toString().equals("sun.reflect.annotation")) {
+ pack = exports;
+ break;
+ }
+ }
+ assertNotNull("Package export not found", pack);
+ List<? extends ModuleElement> targetModules = pack.getTargetModules();
+ assertEquals("incorrect no of targets", 1, targetModules.size());
+ ModuleElement mod = targetModules.get(0);
+ assertEquals("incorrect module element", "jdk.compiler", mod.getQualifiedName().toString());
+ }
+ /*
+ * Test java.base module can be loaded and verify its requires attributes
+ */
+ public void testModuleJavaBase2() {
+ Set<? extends ModuleElement> allModuleElements = _elementUtils.getAllModuleElements();
+ ModuleElement base = null;
+ for (ModuleElement moduleElement : allModuleElements) {
+ if (moduleElement.getQualifiedName().toString().equals("java.base")) {
+ base = moduleElement;
+ }
+ }
+ assertNotNull("java.base module null", base);
+ List<? extends Directive> directives = base.getDirectives();
+ List<Directive> filterDirective = filterDirective(directives, DirectiveKind.REQUIRES);
+ assertEquals("Incorrect no of requires", 0, filterDirective.size());
+ }
+ /*
+ * Test java.base module can be loaded and verify its 'opens' attributes
+ */
+ public void testModuleJavaBase3() {
+ Set<? extends ModuleElement> allModuleElements = _elementUtils.getAllModuleElements();
+ ModuleElement base = null;
+ for (ModuleElement moduleElement : allModuleElements) {
+ if (moduleElement.getQualifiedName().toString().equals("java.base")) {
+ base = moduleElement;
+ }
+ }
+ assertNotNull("java.base module null", base);
+ List<? extends Directive> directives = base.getDirectives();
+ List<Directive> filterDirective = filterDirective(directives, DirectiveKind.OPENS);
+ assertEquals("incorrect no of opens", 0 , filterDirective.size());
+ }
+ /*
+ * Test java.base module can be loaded and verify its 'uses' attributes
+ */
+ public void testModuleJavaBase4() {
+ Set<? extends ModuleElement> allModuleElements = _elementUtils.getAllModuleElements();
+ ModuleElement base = null;
+ for (ModuleElement moduleElement : allModuleElements) {
+ if (moduleElement.getQualifiedName().toString().equals("java.base")) {
+ base = moduleElement;
+ }
+ }
+ assertNotNull("java.base module null", base);
+ List<? extends Directive> directives = base.getDirectives();
+ List<Directive> filterDirective = filterDirective(directives, DirectiveKind.USES);
+ assertEquals("incorrect no of uses", 34 , filterDirective.size());
+ }
+ /*
+ * Test java.base module can be loaded and verify its 'provides' attributes
+ */
+ public void testModuleJavaBase5() {
+ Set<? extends ModuleElement> allModuleElements = _elementUtils.getAllModuleElements();
+ ModuleElement base = null;
+ for (ModuleElement moduleElement : allModuleElements) {
+ if (moduleElement.getQualifiedName().toString().equals("java.base")) {
+ base = moduleElement;
+ }
+ }
+ assertNotNull("java.base module null", base);
+ List<? extends Directive> directives = base.getDirectives();
+ List<Directive> filterDirective = filterDirective(directives, DirectiveKind.PROVIDES);
+ assertEquals("incorrect no of provides", 1 , filterDirective.size());
+ ProvidesDirective provides = (ProvidesDirective) filterDirective.get(0);
+ assertEquals("incorrect service name", "java.nio.file.spi.FileSystemProvider", provides.getService().getQualifiedName().toString());
+ List<? extends TypeElement> implementations = provides.getImplementations();
+ assertEquals("incorrect no of implementations", 1 , implementations.size());
+ TypeElement typeElement = implementations.get(0);
+ assertEquals("incorrect implementation name", "jdk.internal.jrtfs.JrtFileSystemProvider", typeElement.getQualifiedName().toString());
+ }
+ public void testModuleTypeMirror1() {
+ ModuleElement base = _elementUtils.getModuleElement("java.base");
+ assertNotNull("java.base module null", base);
+ TypeMirror asType = base.asType();
+ assertNotNull("module type should not be null", asType);
+ assertEquals("incorrect type kind", TypeKind.MODULE, asType.getKind());
+ assertEquals("must be a NoType", (asType instanceof NoType));
+ }
+ public void testModuleTypeMirror2() {
+ ModuleElement base = _elementUtils.getModuleElement("mod.a");
+ assertNotNull("mod.a module null", base);
+ TypeMirror asType = base.asType();
+ assertNotNull("module type should not be null", asType);
+ verifyAnnotations(asType, new String[]{});
+ }
+ /*
+ * Test java.sql module can be loaded and verify its requires attributes
+ */
+ public void testModuleJavaSql1() {
+ Set<? extends ModuleElement> allModuleElements = _elementUtils.getAllModuleElements();
+ ModuleElement base = null;
+ for (ModuleElement moduleElement : allModuleElements) {
+ if (moduleElement.getQualifiedName().toString().equals("java.sql")) {
+ base = moduleElement;
+ break;
+ }
+ }
+ assertNotNull("java.sql module null", base);
+ List<? extends Directive> directives = base.getDirectives();
+ List<Directive> filterDirective = filterDirective(directives, DirectiveKind.REQUIRES);
+ assertEquals("Incorrect no of requires", 3, filterDirective.size());
+ RequiresDirective req = null;
+ for (Directive directive : filterDirective) {
+ if (((RequiresDirective) directive).getDependency().getQualifiedName().toString().equals("java.logging")) {
+ req = (RequiresDirective) directive;
+ break;
+ }
+ }
+ assertNotNull("dependency on java.logging not found", req);
+ assertTrue("dependency should be transitive", req.isTransitive());
+ }
+ /*
+ * Test a source module can be retrieved and verify its requires attributes
+ */
+ public void testSourceModule1() {
+ ModuleElement mod = _elementUtils.getModuleElement("mod.a");
+ assertNotNull("mod.a module null", mod);
+ List<? extends Directive> directives = mod.getDirectives();
+ List<Directive> filterDirective = filterDirective(directives, DirectiveKind.REQUIRES);
+ assertEquals("Incorrect no of requires", 3, filterDirective.size());
+ RequiresDirective reqCompiler = null;
+ RequiresDirective reqSql = null;
+ for (Directive directive : filterDirective) {
+ if (((RequiresDirective) directive).getDependency().getQualifiedName().toString().equals("java.compiler")) {
+ reqCompiler = (RequiresDirective) directive;
+ }
+ if (((RequiresDirective) directive).getDependency().getQualifiedName().toString().equals("java.sql")) {
+ reqSql = (RequiresDirective) directive;
+ }
+ }
+ assertNotNull("dependency on java.sql not found", reqSql);
+ assertNotNull("dependency on java.sql not found", reqCompiler);
+ assertTrue("dependency should be transitive", reqSql.isTransitive());
+ assertTrue("dependency should be transitive", reqCompiler.isTransitive());
+ }
+ /*
+ * Test a source module can be retrieved and verify its requires attributes
+ */
+ public void testSourceModule2() {
+ ModuleElement mod = _elementUtils.getModuleElement("mod.b");
+ assertNotNull("mod.b module null", mod);
+ List<? extends Directive> directives = mod.getDirectives();
+ List<Directive> filterDirective = filterDirective(directives, DirectiveKind.REQUIRES);
+ assertEquals("Incorrect no of requires", 2, filterDirective.size());
+ RequiresDirective reqCompiler = null;
+ RequiresDirective reqSql = null;
+ RequiresDirective reqA = null;
+ for (Directive directive : filterDirective) {
+ if (((RequiresDirective) directive).getDependency().getQualifiedName().toString().equals("java.compiler")) {
+ reqCompiler = (RequiresDirective) directive;
+ }
+ if (((RequiresDirective) directive).getDependency().getQualifiedName().toString().equals("java.sql")) {
+ reqSql = (RequiresDirective) directive;
+ }
+ if (((RequiresDirective) directive).getDependency().getQualifiedName().toString().equals("mod.a")) {
+ reqA = (RequiresDirective) directive;
+ }
+ }
+ assertNull("dependency on java.sql should not be visible", reqSql);
+ assertNull("dependency on java.compiler should not be visible", reqCompiler);
+ assertNotNull("dependency on mod.a not found", reqA);
+ assertFalse("dependency should not be transitive", reqA.isTransitive());
+ }
+ public void testUnnamedModule1() {
+ Set<? extends Element> rootElements = this.roundEnv.getRootElements();
+ ModuleElement mod = null;
+ for (Element element : rootElements) {
+ if (element instanceof TypeElement) {
+ mod = _elementUtils.getModuleOf(element);
+ break;
+ }
+ }
+ assertNotNull("module should not be null", mod);
+ assertTrue("module should be unnamed", mod.isUnnamed());
+ List<? extends Element> enclosedElements = mod.getEnclosedElements();
+ List<? extends Directive> directives = mod.getDirectives();
+ assertEquals("incorrect no of directives", 0, directives.size());
+ List<Element> filterElements = filterElements(enclosedElements, ElementKind.PACKAGE);
+ assertEquals("incorrect no of packages", 3, filterElements.size());
+ // FIXME: Note Javac fails here as well
+// PackageElement packageOf = _elementUtils.getPackageOf(mod);
+// assertNotNull("package should not be null", packageOf);
+ }
+ public void testUnnamedModule2() {
+ Set<? extends PackageElement> allPackageElements = _elementUtils.getAllPackageElements("targets.model9.p");
+ assertEquals("incorrect no of packages", 1, allPackageElements.size());
+ TypeElement typeElement =_elementUtils.getTypeElement("targets.model9.p.A");
+ assertNotNull("Type should not be null", typeElement);
+ ModuleElement m = _elementUtils.getModuleOf(typeElement);
+ assertEquals("module should be unnamed", "", m.getQualifiedName().toString());
+ }
+ public void testUnnamedModule3() {
+ Set<? extends Element> rootElements = this.roundEnv.getRootElements();
+ ModuleElement moduleElement = _elementUtils.getModuleElement("");
+ assertNotNull("module should not be null", moduleElement);
+ ModuleElement mod = null;
+ for (Element element : rootElements) {
+ if (element instanceof TypeElement) {
+ mod = (ModuleElement) element.getEnclosingElement().getEnclosingElement();
+ break;
+ }
+ }
+ assertEquals("modules should be equal", mod, moduleElement);
+ assertNotNull("module should not be null", mod);
+ List<Element> filterElements = filterElements(mod.getEnclosedElements(), ElementKind.PACKAGE);
+ assertEquals("incorrect no of packages", 1, filterElements.size());
+ }
+ public void testUnnamedModule4() {
+ ModuleElement moduleElement = _elementUtils.getModuleElement("");
+ assertNotNull("module should not be null", moduleElement);
+ List<Element> filterElements = filterElements(moduleElement.getEnclosedElements(), ElementKind.PACKAGE);
+ PackageElement pack = (PackageElement) filterElements.get(0);
+ assertEquals("incorect package", "targets.model9a.internal", pack.getQualifiedName().toString());
+ List<? extends Element> enclosedElements = pack.getEnclosedElements();
+ assertEquals("incorrect no of types", 2, enclosedElements.size());
+ }
+ public void testUnnamedModule5() {
+ ModuleElement moduleElement = _elementUtils.getModuleElement("");
+ assertNotNull("module should not be null", moduleElement);
+ List<Element> filterElements = filterElements(moduleElement.getEnclosedElements(), ElementKind.PACKAGE);
+ PackageElement pack = (PackageElement) filterElements.get(0);
+ assertEquals("incorect package", "targets.model9x", pack.getQualifiedName().toString());
+ List<? extends Element> enclosedElements = pack.getEnclosedElements();
+ assertEquals("incorrect no of types", 1, enclosedElements.size());
+ }
+ public void testBug521723() {
+ // private int foo1(int i) { return i; }
+ // default int foo2(int i) {return foo(i); }
+ // public default void foo3() {}
+ // static void foo4() {}
+ // private static void foo5() {}
+ // public static void foo6() {}
+ Modifier[] f1 = new Modifier[] {Modifier.PRIVATE};
+ Modifier[] f2 = new Modifier[] {Modifier.PUBLIC, Modifier.DEFAULT};
+ Modifier[] f3 = f2;
+ Modifier[] f4 = new Modifier[] {Modifier.STATIC, Modifier.PUBLIC};
+ Modifier[] f5 = new Modifier[] {Modifier.PRIVATE, Modifier.STATIC};
+ Modifier[] f6 = f4;
+ Set<? extends Element> rootElements = roundEnv.getRootElements();
+ TypeElement t = null;
+ for (Element element : rootElements) {
+ if (element instanceof TypeElement) {
+ if (((TypeElement) element).getQualifiedName().toString().equals("targets.bug521723.I")) {
+ t = (TypeElement) element;
+ }
+ }
+ }
+ assertNotNull("type should not be null", t);
+ List<? extends Element> enclosedElements = t.getEnclosedElements();
+ for (Element element : enclosedElements) {
+ if (element instanceof ExecutableElement) {
+ String string = element.getSimpleName().toString();
+ if (string.equals("foo1")) {
+ validateModifiers((ExecutableElement) element, f1);
+ } else if (string.equals("foo2")) {
+ validateModifiers((ExecutableElement) element, f2);
+ } else if (string.equals("foo3")) {
+ validateModifiers((ExecutableElement) element, f3);
+ } else if (string.equals("foo4")) {
+ validateModifiers((ExecutableElement) element, f4);
+ } else if (string.equals("foo5")) {
+ validateModifiers((ExecutableElement) element, f5);
+ } else if (string.equals("foo6")) {
+ validateModifiers((ExecutableElement) element, f6);
+ }
+ }
+ }
+
+ }
+ private void validateModifiers(ExecutableElement method, Modifier[] expected) {
+ Set<Modifier> modifiers = method.getModifiers();
+ List<Modifier> list = new ArrayList<>(modifiers);
+ for (Modifier modifier : expected) {
+ list.remove(modifier);
+ }
+ assertTrue("modifiers still present: " + list.toString(), list.isEmpty());
+ }
+ protected <E extends Element> List<Element> filterElements(Iterable<? extends E> list, ElementKind kind) {
+ List<Element> elements = new ArrayList<>();
+ for (Element e : list) {
+ if (e.getKind() == kind)
+ elements.add(e);
+ }
+ return elements;
+ }
+ protected <D extends Directive> List<Directive> filterDirective(Iterable<? extends Directive> list, DirectiveKind kind) {
+ List<Directive> directives = new ArrayList<>();
+ for (Directive d : list) {
+ if (d.getKind() == kind)
+ directives.add(d);
+ }
+ return directives;
+ }
+
+ @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();
+ }
+ 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 void verifyAnnotations(AnnotatedConstruct construct, String[] annots) {
+ List<? extends AnnotationMirror> annotations = construct.getAnnotationMirrors();
+ assertEquals("Incorrect no of annotations", annots.length, annotations.size());
+ for(int i = 0, length = annots.length; i < length; i++) {
+ AnnotationMirror mirror = annotations.get(i);
+ assertEquals("Invalid annotation value", annots[i], getAnnotationString(mirror));
+ }
+ }
+
+ private String getAnnotationString(AnnotationMirror annot) {
+ DeclaredType annotType = annot.getAnnotationType();
+ TypeElement type = (TypeElement) annotType.asElement();
+ StringBuffer buf = new StringBuffer("@" + type.getQualifiedName());
+ Map<? extends ExecutableElement, ? extends AnnotationValue> values = annot.getElementValues();
+ Set<? extends ExecutableElement> keys = values.keySet();
+ buf.append('(');
+ for (ExecutableElement executableElement : keys) { // @Marker3()
+ buf.append(executableElement.getSimpleName());
+ buf.append('=');
+ AnnotationValue value = values.get(executableElement);
+ buf.append(value.getValue());
+ }
+ buf.append(')');
+ return buf.toString();
+ }
+ 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/modules/mod.a/abc/internal/A.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.a/abc/internal/A.java
new file mode 100644
index 0000000000..53aac786d8
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.a/abc/internal/A.java
@@ -0,0 +1,3 @@
+package abc.internal;
+public class A extends TypeInAModule {
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.a/abc/internal/TypeInAModule.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.a/abc/internal/TypeInAModule.java
new file mode 100644
index 0000000000..948e3e98f3
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.a/abc/internal/TypeInAModule.java
@@ -0,0 +1,5 @@
+package abc.internal;
+
+@java.lang.Deprecated()
+public class TypeInAModule {
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.a/abc/internal/pqr/A.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.a/abc/internal/pqr/A.java
new file mode 100644
index 0000000000..657fc3cbc9
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.a/abc/internal/pqr/A.java
@@ -0,0 +1,2 @@
+package abc.internal.pqr;
+public class A {}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.a/module-info.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.a/module-info.java
new file mode 100644
index 0000000000..77d0566384
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.a/module-info.java
@@ -0,0 +1,7 @@
+@java.lang.Deprecated()
+module mod.a {
+ exports abc.internal;
+
+ requires transitive java.compiler;
+ requires transitive java.sql;
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.b/abc/A.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.b/abc/A.java
new file mode 100644
index 0000000000..a00a9cf09e
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.b/abc/A.java
@@ -0,0 +1,3 @@
+package abc;
+class A {
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.b/module-info.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.b/module-info.java
new file mode 100644
index 0000000000..fcc6ca1420
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.b/module-info.java
@@ -0,0 +1,6 @@
+@java.lang.Deprecated()
+module mod.b {
+ exports pqr.ext;
+
+ requires mod.a;
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.b/pqr/ext/B.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.b/pqr/ext/B.java
new file mode 100644
index 0000000000..8f93ceb50c
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules/mod.b/pqr/ext/B.java
@@ -0,0 +1,2 @@
+package pqr.ext;
+public class B {}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/targets/bug520540/GenericType.java b/org.eclipse.jdt.compiler.apt.tests/resources/targets/bug520540/GenericType.java
new file mode 100644
index 0000000000..cb269aded3
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/targets/bug520540/GenericType.java
@@ -0,0 +1,13 @@
+package targets.bug520540;
+@org.eclipse.jdt.compiler.apt.tests.annotations.Type()
+public class GenericType<T> {
+}
+enum MyEnum{
+ m1, m2;
+}
+class TypeEx extends Exception {
+}
+interface TypeA {
+}
+@interface AnnotB {
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/targets/bug521723/Main.java b/org.eclipse.jdt.compiler.apt.tests/resources/targets/bug521723/Main.java
new file mode 100644
index 0000000000..c729b78786
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/targets/bug521723/Main.java
@@ -0,0 +1,13 @@
+package targets.bug521723;
+
+public class Main {
+}
+
+interface I {
+ private int foo1(int i) { return i; }
+ default int foo2(int i) {return foo1(i); }
+ public default void foo3() {}
+ static void foo4() {}
+ private static void foo5() {}
+ public static void foo6() {}
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/targets/bug521812/MyEnum.java b/org.eclipse.jdt.compiler.apt.tests/resources/targets/bug521812/MyEnum.java
new file mode 100644
index 0000000000..66b5b94582
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/targets/bug521812/MyEnum.java
@@ -0,0 +1,10 @@
+package targets.bug521812;
+
+@org.eclipse.jdt.compiler.apt.tests.annotations.Type
+enum MyEnum {
+ A(1), B(2);
+
+ MyEnum(int v) { this.v = v; }
+ public int value() { return v; }
+ final int v;
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/targets/model9/X.java b/org.eclipse.jdt.compiler.apt.tests/resources/targets/model9/X.java
new file mode 100644
index 0000000000..812e6e67a4
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/targets/model9/X.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2017 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package targets.model9;
+
+import org.eclipse.jdt.compiler.apt.tests.annotations.Type;
+import org.eclipse.jdt.compiler.apt.tests.annotations.Type1;
+import org.eclipse.jdt.compiler.apt.tests.annotations.Type$1;
+import org.eclipse.jdt.compiler.apt.tests.annotations.Type.One;
+
+@Type("c")
+public class X extends @Type("s") Object implements @Type("i1") I, @Type("i2") J {
+ @Type("f") String _field = null;
+ @Type("f1") X _field1 = null;
+ @Type("f1") X _field11 = null;
+ @Type$1 @One String _field2 = null;
+ X _field3 = null;
+ int _i = 10;
+ public void noAnnotationHere() {
+ }
+ @Deprecated @Type("m") String foo() {
+ return null;
+ }
+ void bar(@Type("p1") String p1, @Type("p2") String p2) {}
+ public void bar2(@Type("receiver") X this) {}
+ // Static methods and top level constructors do not have receivers
+ public static void main(String[] args) {}
+ @Type("constr1") public X(){}
+ @Type1("constr2") public X(int i){}
+}
+
+interface I {}
+interface J {}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/targets/model9/p/A.java b/org.eclipse.jdt.compiler.apt.tests/resources/targets/model9/p/A.java
new file mode 100644
index 0000000000..c23bbb3a67
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/targets/model9/p/A.java
@@ -0,0 +1,3 @@
+package targets.model9.p;
+public class A {
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/targets/model9a/internal/GenericType.java b/org.eclipse.jdt.compiler.apt.tests/resources/targets/model9a/internal/GenericType.java
new file mode 100644
index 0000000000..aa1f699ab6
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/targets/model9a/internal/GenericType.java
@@ -0,0 +1,7 @@
+package targets.model9a.internal;
+public class GenericType<T> {
+}
+
+enum MyEnum{
+ m1, m2;
+} \ 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 c897d8345b..80c1046aa3 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2014 IBM, BEA Systems, Inc. and others
+ * Copyright (c) 2006, 2017 IBM, BEA Systems, Inc. and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -31,6 +31,7 @@ public class AllTests extends TestCase {
suite.addTestSuite(ModelUtilTests.class);
suite.addTestSuite(NegativeTests.class);
suite.addTestSuite(Java8ElementsTests.class);
+ suite.addTestSuite(Java9ElementsTests.class);
suite.addTestSuite(AnnotationProcessorTests.class);
return suite;
}
diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchDispatchTests.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchDispatchTests.java
index 4bc6be4c76..548cce1528 100644
--- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchDispatchTests.java
+++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchDispatchTests.java
@@ -95,7 +95,7 @@ public class BatchDispatchTests extends TestCase {
* when called from Eclipse compiler
* @throws IOException
*/
- public void testProcessorArgumentsWithEclipseCompiler() throws IOException {
+ public void _testProcessorArgumentsWithEclipseCompiler() throws IOException {
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
internalTestProcessorArguments(compiler);
}
@@ -120,7 +120,7 @@ public class BatchDispatchTests extends TestCase {
* Read annotation values and generate a class using Eclipse compiler
* @throws IOException
*/
- public void testCompilerOneClassWithEclipseCompiler() throws IOException {
+ public void _testCompilerOneClassWithEclipseCompiler() throws IOException {
// Eclipse compiler
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
internalTestGenerateClass(compiler);
@@ -152,7 +152,7 @@ public class BatchDispatchTests extends TestCase {
* Verify that if a type has two annotations, both processors are run.
* @throws IOException
*/
- public void testTwoAnnotations() throws IOException {
+ public void _testTwoAnnotations() throws IOException {
File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "dispatch");
File inputFile = BatchTestUtils.copyResource("targets/dispatch/TwoAnnotations.java", targetFolder);
assertNotNull("No input file", inputFile);
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 443ea10ef2..7bed895965 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
@@ -1,9 +1,13 @@
/*******************************************************************************
- * Copyright (c) 2007, 2015 BEA Systems, Inc.
+ * Copyright (c) 2007, 2017 BEA Systems, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
+ *
+ * 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:
* wharley@bea.com - initial API and implementation
@@ -13,9 +17,6 @@
package org.eclipse.jdt.compiler.apt.tests;
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.Platform;
-
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
@@ -26,6 +27,10 @@ import java.io.Reader;
import java.io.StringWriter;
import java.net.URL;
import java.nio.charset.Charset;
+import java.nio.file.DirectoryStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@@ -36,6 +41,10 @@ import javax.tools.JavaCompiler;
import javax.tools.JavaCompiler.CompilationTask;
import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
+import javax.tools.StandardLocation;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Platform;
/**
* Helper class to support compilation and results checking for tests running in batch mode.
@@ -46,8 +55,8 @@ public class BatchTestUtils {
// relative to plugin directory
private static final String PROCESSOR_JAR_NAME = "lib/apttestprocessors.jar";
private static final String JLS8_PROCESSOR_JAR_NAME = "lib/apttestprocessors8.jar";
- private static String _processorJarPath;
- private static String _jls8ProcessorJarPath;
+ public static String _processorJarPath;
+ public static String _jls8ProcessorJarPath;
// locations to copy and generate files
private static String _tmpFolder;
@@ -58,7 +67,7 @@ public class BatchTestUtils {
private static File _tmpSrcDir;
private static String _tmpBinFolderName;
private static File _tmpBinDir;
- private static String _tmpGenFolderName;
+ public static String _tmpGenFolderName;
private static File _tmpGenDir;
/**
@@ -93,6 +102,11 @@ public class BatchTestUtils {
System.err.println("Compilation failed: " + errorOutput);
junit.framework.TestCase.assertTrue("Compilation failed : " + errorOutput, false);
}
+ try {
+ manager.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
public static void compileTree(JavaCompiler compiler, List<String> options, File targetFolder) {
@@ -108,6 +122,66 @@ public class BatchTestUtils {
compileTree(compiler, options, targetFolder, useJLS8Processors, null);
}
+ public static void compileInModuleMode(JavaCompiler compiler, List<String> options, String processor,
+ File targetFolder, DiagnosticListener<? super JavaFileObject> listener, boolean multiModule) {
+ StandardJavaFileManager manager = compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
+ Iterable<? extends File> location = manager.getLocation(StandardLocation.CLASS_PATH);
+ // create new list containing inputfile
+ List<File> files = new ArrayList<File>();
+ findFilesUnder(targetFolder, files);
+ Iterable<? extends JavaFileObject> units = manager.getJavaFileObjectsFromFiles(files);
+ StringWriter stringWriter = new StringWriter();
+ PrintWriter printWriter = new PrintWriter(stringWriter);
+
+ List<String> copyOptions = new ArrayList<>();
+ copyOptions.add("-processor");
+ copyOptions.add(processor);
+ copyOptions.add("-A" + processor);
+ copyOptions.add("-d");
+ copyOptions.add(_tmpBinFolderName);
+ copyOptions.add("-s");
+ copyOptions.add(_tmpGenFolderName);
+ addModuleProcessorPath(copyOptions, getSrcFolderName(), multiModule);
+ copyOptions.add("-XprintRounds");
+ CompilationTask task = compiler.getTask(printWriter, manager, listener, copyOptions, null, units);
+ Boolean result = task.call();
+
+ if (!result.booleanValue()) {
+ String errorOutput = stringWriter.getBuffer().toString();
+ System.err.println("Compilation failed: " + errorOutput);
+ junit.framework.TestCase.assertTrue("Compilation failed : " + errorOutput, false);
+ }
+ List<String> classes = new ArrayList<>();
+ try {
+ System.clearProperty(processor);
+ copyOptions = new ArrayList<>();
+ copyOptions.addAll(options);
+ copyOptions.add("-cp");
+ copyOptions.add(_jls8ProcessorJarPath + File.pathSeparator + _tmpGenFolderName);
+ copyOptions.add("--processor-module-path");
+ copyOptions.add(_jls8ProcessorJarPath);
+ copyOptions.add("--module-path");
+ copyOptions.add(_tmpBinFolderName);
+ classes.add("java.base/java.lang.Object"); // This is required to make sure BTB for Object is fully populated.
+ findClassesUnderModules(Paths.get(_tmpBinFolderName), classes);
+ manager.setLocation(StandardLocation.CLASS_PATH, location);
+ task = compiler.getTask(printWriter, manager, listener, copyOptions, classes, null);
+ result = task.call();
+ if (!result.booleanValue()) {
+ String errorOutput = stringWriter.getBuffer().toString();
+ System.err.println("Compilation failed: " + errorOutput);
+ junit.framework.TestCase.assertTrue("Compilation failed : " + errorOutput, false);
+ }
+ } catch (IOException e) {
+ // print the stack just in case.
+ e.printStackTrace();
+ }
+ try {
+ manager.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
public static void compileTree(JavaCompiler compiler, List<String> options,
File targetFolder, boolean useJLS8Processors,
DiagnosticListener<? super JavaFileObject> listener) {
@@ -134,6 +208,65 @@ public class BatchTestUtils {
System.err.println("Compilation failed: " + errorOutput);
junit.framework.TestCase.assertTrue("Compilation failed : " + errorOutput, false);
}
+ try {
+ manager.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ /*
+ * First compiles the given files without processor, then processes them
+ * with the just compiled binaries.
+ */
+ public static void compileTreeAndProcessBinaries(JavaCompiler compiler, List<String> options, String processor,
+ File targetFolder, DiagnosticListener<? super JavaFileObject> listener) {
+ StandardJavaFileManager manager = compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
+ Iterable<? extends File> location = manager.getLocation(StandardLocation.CLASS_PATH);
+ // create new list containing inputfile
+ List<File> files = new ArrayList<File>();
+ findFilesUnder(targetFolder, files);
+ Iterable<? extends JavaFileObject> units = manager.getJavaFileObjectsFromFiles(files);
+ StringWriter stringWriter = new StringWriter();
+ PrintWriter printWriter = new PrintWriter(stringWriter);
+ List<String> copyOptions = new ArrayList<>();
+ copyOptions.addAll(options);
+ copyOptions.add("-d");
+ copyOptions.add(_tmpBinFolderName);
+ copyOptions.add("-s");
+ copyOptions.add(_tmpGenFolderName);
+ addProcessorPaths(copyOptions, true, true);
+ options.add("-XprintRounds");
+ CompilationTask task = compiler.getTask(printWriter, manager, listener, copyOptions, null, units);
+ Boolean result = task.call();
+
+ if (!result.booleanValue()) {
+ String errorOutput = stringWriter.getBuffer().toString();
+ System.err.println("Compilation failed: " + errorOutput);
+ junit.framework.TestCase.assertTrue("Compilation failed : " + errorOutput, false);
+ }
+ List<String> classes = new ArrayList<>();
+ try {
+ System.clearProperty(processor);
+ copyOptions = new ArrayList<>();
+ copyOptions.addAll(options);
+ copyOptions.add("-cp");
+ copyOptions.add(_tmpBinFolderName + File.pathSeparator + _jls8ProcessorJarPath + File.pathSeparator + _tmpGenFolderName);
+ copyOptions.add("-processorpath");
+ copyOptions.add(_jls8ProcessorJarPath);
+ classes.add("java.lang.Object"); // This is required to make sure BTB for Object is fully populated.
+ findClassesUnder(Paths.get(_tmpBinFolderName), null, classes, null);
+ manager.setLocation(StandardLocation.CLASS_PATH, location);
+ task = compiler.getTask(printWriter, manager, listener, copyOptions, classes, null);
+ result = task.call();
+ if (!result.booleanValue()) {
+ String errorOutput = stringWriter.getBuffer().toString();
+ System.err.println("Compilation failed: " + errorOutput);
+ junit.framework.TestCase.assertTrue("Compilation failed : " + errorOutput, false);
+ }
+ } catch (IOException e) {
+ // print the stack just in case.
+ e.printStackTrace();
+ }
}
/**
@@ -182,7 +315,11 @@ public class BatchTestUtils {
StringWriter writer = new StringWriter();
CompilationTask task = compiler.getTask(writer, manager, diagnosticListener, options, null, units);
Boolean result = task.call();
-
+ try {
+ manager.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
return result.booleanValue();
}
@@ -206,6 +343,37 @@ public class BatchTestUtils {
}
}
+ protected static void findClassesUnderModules(Path modulePath, List<String> classes) throws IOException {
+ try (DirectoryStream<Path> stream = Files.newDirectoryStream(modulePath)) {
+ for (Path entry : stream) {
+ if (Files.isDirectory(entry)) {
+ findClassesUnder(entry, entry, classes, entry.getFileName().toString());
+ }
+ }
+ }
+ }
+ protected static void findClassesUnder(Path root, Path folder, List<String> classes, String moduleName) throws IOException {
+ if (folder == null)
+ folder = root;
+ try (DirectoryStream<Path> stream = Files.newDirectoryStream(folder)) {
+ for (Path entry : stream) {
+ if (Files.isDirectory(entry)) {
+ findClassesUnder(root, entry, classes, moduleName);
+ } else {
+ String fileName = entry.getFileName().toString();
+ if (fileName.endsWith(".class") && !fileName.startsWith("module-info")) {
+ String className = root.relativize(entry).toString();
+ className = className.substring(0, className.indexOf(".class"));
+ className = className.replace(File.separatorChar, '.');
+ if (moduleName != null) {
+ className = moduleName + "/" + className;
+ }
+ classes.add(className);
+ }
+ }
+ }
+ }
+ }
/** @return the name of the folder where class files will be saved */
public static String getBinFolderName() {
return _tmpBinFolderName;
@@ -278,14 +446,11 @@ public class BatchTestUtils {
if (c == null) {
junit.framework.TestCase.assertTrue("Eclipse compiler is not available", false);
}
- int compilerCounter = 0;
for (JavaCompiler javaCompiler : javaCompilerLoader) {
- compilerCounter++;
if (c.isInstance(javaCompiler)) {
_eclipseCompiler = javaCompiler;
}
}
- junit.framework.TestCase.assertEquals("Only one compiler available", 1, compilerCounter);
junit.framework.TestCase.assertNotNull("No Eclipse compiler found", _eclipseCompiler);
}
@@ -298,6 +463,16 @@ public class BatchTestUtils {
options.add("-processorpath");
options.add(path);
}
+ private static void addModuleProcessorPath(List<String> options, String srcFolderName, boolean multiModule) {
+ options.add("--processor-module-path");
+ options.add(_jls8ProcessorJarPath);
+ options.add("--module-path");
+ options.add(_jls8ProcessorJarPath);
+ if (multiModule) {
+ options.add("--module-source-path");
+ options.add(srcFolderName);
+ }
+ }
public static void tearDown() {
new File(_processorJarPath).deleteOnExit();
@@ -372,6 +547,10 @@ public class BatchTestUtils {
contents = TestUtils.convertToIndependentLineDelimiter(contents);
srcBytes = contents.getBytes();
}
+ writeFile(dest, srcBytes);
+ }
+
+ public static void writeFile(File dest, byte[] srcBytes) throws IOException {
File destFolder = dest.getParentFile();
if (!destFolder.exists()) {
diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/FileManagerTests.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/FileManagerTests.java
index 36b7079a58..a0fd12eb81 100644
--- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/FileManagerTests.java
+++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/FileManagerTests.java
@@ -5,6 +5,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
+ * 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:
* wharley@bea.com - initial API and implementation
* IBM Corporation - fixed a resource leak warning
@@ -25,6 +29,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Set;
+import javax.lang.model.SourceVersion;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
@@ -167,6 +172,7 @@ public class FileManagerTests extends TestCase {
}
public void testBug460085() {
+ if (isOnJRE9()) return;
try {
boolean found = false;
EclipseFileManager fileManager = null;
@@ -183,10 +189,17 @@ public class FileManagerTests extends TestCase {
fileManager.close();
assertTrue("rt.jar not found", found);
} catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ fail(e.getMessage());
}
}
+ private boolean isOnJRE9() {
+ try {
+ SourceVersion.valueOf("RELEASE_9");
+ } catch(IllegalArgumentException iae) {
+ return false;
+ }
+ return true;
+ }
public void testBug466878_getResource_defaultPackage() throws Exception {
EclipseFileManager fileManager = new EclipseFileManager(Locale.getDefault(), Charset.defaultCharset());
diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/FilerTests.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/FilerTests.java
index 120cd119e5..6b4680d494 100644
--- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/FilerTests.java
+++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/FilerTests.java
@@ -48,7 +48,7 @@ public class FilerTests extends TestCase {
* Attempt to read various elements of the Element hierarchy.
* @throws IOException
*/
- public void testElementWithEclipseCompiler() throws IOException {
+ public void _testElementWithEclipseCompiler() throws IOException {
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
internalTestCreateResource(compiler, false);
}
diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java8ElementsTests.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java8ElementsTests.java
index c098bea7b1..b2b88767b5 100644
--- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java8ElementsTests.java
+++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java8ElementsTests.java
@@ -20,12 +20,12 @@ import javax.lang.model.SourceVersion;
import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
+import org.eclipse.jdt.internal.compiler.tool.EclipseCompiler;
+
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
-import org.eclipse.jdt.internal.compiler.tool.EclipseCompiler;
-
public class Java8ElementsTests extends TestCase {
private static final String JAVA8_ANNOTATION_PROC = "org.eclipse.jdt.compiler.apt.tests.processors.elements.Java8ElementProcessor";
@@ -60,7 +60,9 @@ public class Java8ElementsTests extends TestCase {
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
internalTest(compiler, JAVA8_ANNOTATION_PROC, "testTypeAnnotations");
}
- public void _testTypeAnnotationsWithJavac() throws Exception {
+ public void testTypeAnnotationsWithJavac() throws Exception {
+ if (!canRunJava9())
+ return;
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
internalTest(compiler, JAVA8_ANNOTATION_PROC, "testTypeAnnotations");
}
@@ -76,7 +78,9 @@ public class Java8ElementsTests extends TestCase {
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
internalTest(compiler, JAVA8_ANNOTATION_PROC, "testTypeAnnotations2");
}
- public void _testTypeAnnotations2WithJavac() throws Exception {
+ public void testTypeAnnotations2WithJavac() throws Exception {
+ if (!canRunJava9())
+ return;
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
internalTest(compiler, JAVA8_ANNOTATION_PROC, "testTypeAnnotations2");
}
@@ -84,7 +88,9 @@ public class Java8ElementsTests extends TestCase {
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
internalTest(compiler, JAVA8_ANNOTATION_PROC, "testTypeAnnotations3");
}
- public void _testTypeAnnotations3WithJavac() throws Exception {
+ public void testTypeAnnotations3WithJavac() throws Exception {
+ if (!canRunJava9())
+ return;
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
internalTest(compiler, JAVA8_ANNOTATION_PROC, "testTypeAnnotations3");
}
@@ -92,7 +98,9 @@ public class Java8ElementsTests extends TestCase {
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
internalTest(compiler, JAVA8_ANNOTATION_PROC, "testTypeAnnotations4");
}
- public void _testTypeAnnotations4WithJavac() throws Exception {
+ public void testTypeAnnotations4WithJavac() throws Exception {
+ if (!canRunJava9())
+ return;
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
internalTest(compiler, JAVA8_ANNOTATION_PROC, "testTypeAnnotations4");
}
@@ -100,7 +108,9 @@ public class Java8ElementsTests extends TestCase {
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
internalTest(compiler, JAVA8_ANNOTATION_PROC, "testTypeAnnotations5");
}
- public void _testTypeAnnotations5WithJavac() throws Exception {
+ public void testTypeAnnotations5WithJavac() throws Exception {
+ if (!canRunJava9())
+ return;
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
internalTest(compiler, JAVA8_ANNOTATION_PROC, "testTypeAnnotations5");
}
@@ -108,7 +118,9 @@ public class Java8ElementsTests extends TestCase {
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
internalTest(compiler, JAVA8_ANNOTATION_PROC, "testTypeAnnotations6");
}
- public void _testTypeAnnotations6WithJavac() throws Exception { // Disabled for now. Javac 8b108 drops annotations arrays preceding varargs.
+ public void testTypeAnnotations6WithJavac() throws Exception { // Disabled for now. Javac 8b108 drops annotations arrays preceding varargs.
+ if (!canRunJava9())
+ return;
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
internalTest(compiler, JAVA8_ANNOTATION_PROC, "testTypeAnnotations6");
}
@@ -148,7 +160,9 @@ public class Java8ElementsTests extends TestCase {
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
internalTest(compiler, JAVA8_ANNOTATION_PROC, "testTypeAnnotations11");
}
- public void _testTypeAnnotations11WithJavac() throws Exception {
+ public void testTypeAnnotations11WithJavac() throws Exception {
+ if (!canRunJava9())
+ return;
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
internalTest(compiler, JAVA8_ANNOTATION_PROC, "testTypeAnnotations11");
}
@@ -160,6 +174,10 @@ public class Java8ElementsTests extends TestCase {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
internalTest(compiler, JAVA8_ANNOTATION_PROC, "testTypeAnnotations12");
}
+ public void _testTypeAnnotations12Binary() throws Exception { // FIXME: disabled after 3 consecutive failures on hudson, which could not be reproduced locally
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTestWithBinary(compiler, JAVA8_ANNOTATION_PROC, "testTypeAnnotations12Binary", null, "model9");
+ }
public void testTypeAnnotations13() throws Exception {
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
internalTest(compiler, JAVA8_ANNOTATION_PROC, "testTypeAnnotations13");
@@ -297,11 +315,56 @@ public class Java8ElementsTests extends TestCase {
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
internalTest(compiler, JAVA8_ANNOTATION_PROC, "testPackageAnnotations", null, "filer8");
}
- public void testPackageAnnotationsWithJavac() throws Exception {
+ // See Java8ElementProcessor.testPackageAnnotations()
+ public void _testPackageAnnotationsWithJavac() throws Exception {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
internalTest(compiler, JAVA8_ANNOTATION_PROC, "testPackageAnnotations", null, "filer8");
}
-
+ public void testBug520540a() throws Exception {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest(compiler, JAVA8_ANNOTATION_PROC, "testBug520540", null, "bug520540");
+ }
+ public void testBug520540aJavac() throws Exception {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ internalTest(compiler, JAVA8_ANNOTATION_PROC, "testBug520540", null, "bug520540");
+ }
+ public void testBug520540b() throws Exception {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "bug520540");
+ BatchTestUtils.copyResources("targets/bug520540", targetFolder);
+ List<String> options = new ArrayList<String>();
+ options.add("-cp");
+ options.add(BatchTestUtils._tmpGenFolderName + File.pathSeparatorChar + BatchTestUtils._jls8ProcessorJarPath);
+ options.add("-processor");
+ options.add(JAVA8_ANNOTATION_PROC);
+ options.add("-A" + JAVA8_ANNOTATION_PROC);
+ options.add("-AtestBug520540");
+ options.add("-1.8");
+ boolean success = BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, null, true, false);
+ assertEquals(true, success);
+ assertEquals("succeeded", System.getProperty(JAVA8_ANNOTATION_PROC));
+ }
+ public void testBug520540bJavac() throws Exception {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "bug520540");
+ BatchTestUtils.copyResources("targets/bug520540", targetFolder);
+ List<String> options = new ArrayList<String>();
+ options.add("-cp");
+ options.add(BatchTestUtils._tmpGenFolderName + File.pathSeparatorChar + BatchTestUtils._jls8ProcessorJarPath);
+ options.add("-processorpath");
+ options.add(" ");
+ options.add("-processor");
+ options.add(JAVA8_ANNOTATION_PROC);
+ options.add("-A" + JAVA8_ANNOTATION_PROC);
+ options.add("-AtestBug520540");
+ boolean success = BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, null, true, false);
+ assertEquals(true, success);
+ assertEquals("succeeded", System.getProperty(JAVA8_ANNOTATION_PROC));
+ }
+ public void testEnumConstArgumentsBinary() throws Exception {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTestWithBinary(compiler, JAVA8_ANNOTATION_PROC, "testEnumConstArguments", null, "bug521812");
+ }
private void internalTest(JavaCompiler compiler, String processor, String testMethod) throws IOException {
internalTest(compiler, processor, testMethod, null);
}
@@ -334,6 +397,34 @@ public class Java8ElementsTests extends TestCase {
// if not, it will set it to an error value.
assertEquals("succeeded", System.getProperty(processor));
}
+ private void internalTestWithBinary(JavaCompiler compiler, String processor, String testMethod, String testClass, String resourceArea) throws IOException {
+ if (!canRunJava8()) {
+ return;
+ }
+ System.clearProperty(processor);
+ File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", resourceArea);
+ if (testClass == null || testClass.equals("")) {
+ BatchTestUtils.copyResources("targets/" + resourceArea, targetFolder);
+ } else {
+ BatchTestUtils.copyResource("targets/" + 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("-1.8");
+ }
+ BatchTestUtils.compileTreeAndProcessBinaries(compiler, options, processor, targetFolder, null);
+
+ // 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 canRunJava8() {
try {
SourceVersion.valueOf("RELEASE_8");
@@ -342,6 +433,14 @@ public class Java8ElementsTests extends TestCase {
}
return true;
}
+ public boolean canRunJava9() {
+ try {
+ SourceVersion.valueOf("RELEASE_9");
+ } catch(IllegalArgumentException iae) {
+ return false;
+ }
+ return true;
+ }
@Override
protected void tearDown() throws Exception {
super.tearDown();
diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java9ElementsTests.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java9ElementsTests.java
new file mode 100644
index 0000000000..a3e2659e04
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java9ElementsTests.java
@@ -0,0 +1,515 @@
+/*******************************************************************************
+ * Copyright (c) 2017 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * 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 Java9ElementsTests extends TestCase {
+ private static final String MODULE_PROC = "org.eclipse.jdt.compiler.apt.tests.processors.elements.Java9ElementProcessor";
+
+ public void testRootElements1Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ System.out.println("No system java compiler available");
+ return;
+ }
+ internalTest2(compiler, MODULE_PROC, "testRootElements1", null);
+ }
+ public void testRootElements1() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest2(compiler, MODULE_PROC, "testRootElements1", null);
+ }
+
+ public void testRootElements2Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ System.out.println("No system java compiler available");
+ return;
+ }
+ internalTest2(compiler, MODULE_PROC, "testRootElements2", null);
+ }
+ public void testRootElements2() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest2(compiler, MODULE_PROC, "testRootElements2", null);
+ }
+
+ public void testAnnotations1Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ System.out.println("No system java compiler available");
+ return;
+ }
+ internalTest2(compiler, MODULE_PROC, "testModuleAnnotation1", null);
+ }
+ public void testAnnotations1() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest2(compiler, MODULE_PROC, "testModuleAnnotation1", null);
+ }
+
+ public void testModuleElement1Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ System.out.println("No system java compiler available");
+ return;
+ }
+ internalTest2(compiler, MODULE_PROC, "testModuleElement1", null);
+ }
+ public void testModuleElement1() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest2(compiler, MODULE_PROC, "testModuleElement1", null);
+ }
+
+ public void testModuleElement2Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ System.out.println("No system java compiler available");
+ return;
+ }
+ internalTest2(compiler, MODULE_PROC, "testModuleElement2", null);
+ }
+ public void testModuleElement2() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest2(compiler, MODULE_PROC, "testModuleElement2", null);
+ }
+
+ public void testModuleElement3Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ System.out.println("No system java compiler available");
+ return;
+ }
+ internalTest2(compiler, MODULE_PROC, "testModuleElement3", null);
+ }
+ public void testModuleElement3() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest2(compiler, MODULE_PROC, "testModuleElement3", null);
+ }
+ public void testModuleElement4Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ System.out.println("No system java compiler available");
+ return;
+ }
+ internalTest2(compiler, MODULE_PROC, "testModuleElement4", null);
+ }
+ public void testModuleElement4() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest2(compiler, MODULE_PROC, "testModuleElement4", null);
+ }
+
+ public void testModuleElement5Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ System.out.println("No system java compiler available");
+ return;
+ }
+ internalTest2(compiler, MODULE_PROC, "testModuleElement5", null);
+ }
+ public void testModuleElement5() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest2(compiler, MODULE_PROC, "testModuleElement5", null);
+ }
+
+ public void testModuleElement6Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ System.out.println("No system java compiler available");
+ return;
+ }
+ internalTest2(compiler, MODULE_PROC, "testModuleElement6", null);
+ }
+ public void testModuleElement6() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest2(compiler, MODULE_PROC, "testModuleElement6", null);
+ }
+
+ public void testModuleElement7Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ System.out.println("No system java compiler available");
+ return;
+ }
+ internalTest2(compiler, MODULE_PROC, "testModuleElement7", null);
+ }
+ public void testModuleElement7() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest2(compiler, MODULE_PROC, "testModuleElement7", null);
+ }
+
+ public void testModuleJavaBase1Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ System.out.println("No system java compiler available");
+ return;
+ }
+ internalTest2(compiler, MODULE_PROC, "testModuleJavaBase1", null);
+ }
+ public void testModuleJavaBase1() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest2(compiler, MODULE_PROC, "testModuleJavaBase1", null);
+ }
+
+
+ public void testModuleJavaBase2Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ System.out.println("No system java compiler available");
+ return;
+ }
+ internalTest2(compiler, MODULE_PROC, "testModuleJavaBase2", null);
+ }
+ public void testModuleJavaBase2() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest2(compiler, MODULE_PROC, "testModuleJavaBase2", null);
+ }
+
+
+ public void testModuleJavaBase3Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ System.out.println("No system java compiler available");
+ return;
+ }
+ internalTest2(compiler, MODULE_PROC, "testModuleJavaBase3", null);
+ }
+ public void testModuleJavaBase3() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest2(compiler, MODULE_PROC, "testModuleJavaBase3", null);
+ }
+
+ public void testModuleJavaBase4Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ System.out.println("No system java compiler available");
+ return;
+ }
+ internalTest2(compiler, MODULE_PROC, "testModuleJavaBase4", null);
+ }
+ public void testModuleJavaBase4() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest2(compiler, MODULE_PROC, "testModuleJavaBase4", null);
+ }
+
+ public void testModuleJavaBase5Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ System.out.println("No system java compiler available");
+ return;
+ }
+ internalTest2(compiler, MODULE_PROC, "testModuleJavaBase5", null);
+ }
+ public void testModuleJavaBase5() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest2(compiler, MODULE_PROC, "testModuleJavaBase5", null);
+ }
+
+ public void testModuleTypeMirror1Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ System.out.println("No system java compiler available");
+ return;
+ }
+ internalTest2(compiler, MODULE_PROC, "testModuleTypeMirror1", null);
+ }
+ public void testModuleTypeMirror1() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest2(compiler, MODULE_PROC, "testModuleTypeMirror1", null);
+ }
+
+ public void testModuleTypeMirror2Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ System.out.println("No system java compiler available");
+ return;
+ }
+ internalTest2(compiler, MODULE_PROC, "testModuleTypeMirror2", null);
+ }
+ public void testModuleTypeMirror2() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest2(compiler, MODULE_PROC, "testModuleTypeMirror2", null);
+ }
+
+ public void testModuleJavaSql1Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ System.out.println("No system java compiler available");
+ return;
+ }
+ internalTest2(compiler, MODULE_PROC, "testModuleJavaSql1", null);
+ }
+ public void testModuleJavaSql1() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest2(compiler, MODULE_PROC, "testModuleJavaSql1", null);
+ }
+
+ public void testSourceModule1Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ System.out.println("No system java compiler available");
+ return;
+ }
+ internalTest2(compiler, MODULE_PROC, "testSourceModule1", null);
+ }
+ public void testSourceModule1() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest2(compiler, MODULE_PROC, "testSourceModule1", null);
+ }
+
+ public void testSourceModule2Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ System.out.println("No system java compiler available");
+ return;
+ }
+ internalTest2(compiler, MODULE_PROC, "testSourceModule2", null);
+ }
+ public void testSourceModule2() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest2(compiler, MODULE_PROC, "testSourceModule2", null);
+ }
+ public void testUnnamedModule1Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ System.out.println("No system java compiler available");
+ return;
+ }
+ internalTest(compiler, MODULE_PROC, "testUnnamedModule1", null, "model9");
+ }
+ public void testUnnamedModule1() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest(compiler, MODULE_PROC, "testUnnamedModule1", null, "model9");
+ }
+ public void testUnnamedModule2Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ System.out.println("No system java compiler available");
+ return;
+ }
+ internalTest(compiler, MODULE_PROC, "testUnnamedModule2", null, "model9");
+ }
+ public void testUnnamedModule2() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest(compiler, MODULE_PROC, "testUnnamedModule2", null, "model9");
+ }
+ public void testUnnamedModule3Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ System.out.println("No system java compiler available");
+ return;
+ }
+ internalTest(compiler, MODULE_PROC, "testUnnamedModule3", null, "model9a");
+ }
+ public void testUnnamedModule3() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest(compiler, MODULE_PROC, "testUnnamedModule3", null, "model9a");
+ }
+ public void testUnnamedModule4Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ System.out.println("No system java compiler available");
+ return;
+ }
+ internalTest(compiler, MODULE_PROC, "testUnnamedModule4", null, "model9a");
+ }
+ public void testUnnamedModule4() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest(compiler, MODULE_PROC, "testUnnamedModule4", null, "model9a");
+ }
+ public void testUnnamedModule5Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ System.out.println("No system java compiler available");
+ return;
+ }
+ internalTest(compiler, MODULE_PROC, "testUnnamedModule5", null, new String[] {
+ "targets/model9x/X.java",
+ "package targets.model9x;\n" +
+ "public class X {\n" +
+ " X(final int j) {\n" +
+ " j = 4;\n" +
+ " }\n" +
+ "}\n"
+ });
+ }
+ public void testUnnamedModule5() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest(compiler, MODULE_PROC, "testUnnamedModule5", null, new String[] {
+ "targets/model9x/X.java",
+ "package targets.model9x;\n" +
+ "public class X {\n" +
+ " X(final int j) {\n" +
+ " j = 4;\n" +
+ " }\n" +
+ "}\n"
+ });
+ }
+ public void testBug521723() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTestWithBinary(compiler, MODULE_PROC, "9", "testBug521723", null, "bug521723");
+ }
+ public void testBug521723Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ internalTestWithBinary(compiler, MODULE_PROC, "9", "testBug521723", null, "bug521723");
+ }
+
+ protected void internalTestWithBinary(JavaCompiler compiler, String processor, String compliance, String testMethod, String testClass, String resourceArea) throws IOException {
+ if (!canRunJava9()) {
+ return;
+ }
+ System.clearProperty(processor);
+ File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", resourceArea);
+ if (testClass == null || testClass.equals("")) {
+ BatchTestUtils.copyResources("targets/" + resourceArea, targetFolder);
+ } else {
+ BatchTestUtils.copyResource("targets/" + 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.compileTreeAndProcessBinaries(compiler, options, processor, targetFolder, null);
+
+ // 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));
+ }
+ private void internalTest(JavaCompiler compiler, String processor, String testMethod, String testClass, String[] source) throws IOException {
+ if (!canRunJava9()) {
+ return;
+ }
+ if ((source.length % 2) != 0) return;
+
+ File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName());
+ for(int i = 0; i < source.length;) {
+ File targetFile = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), source[i++]);
+ BatchTestUtils.writeFile(targetFile, source[i++].getBytes());
+ }
+
+ List<String> options = new ArrayList<String>();
+ options.add("-processor");
+ options.add(MODULE_PROC);
+ options.add("-A" + processor);
+ options.add("-A" + testMethod);
+ if (compiler instanceof EclipseCompiler) {
+ options.add("-9");
+ }
+ BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, null, true, 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));
+ }
+ private void internalTest(JavaCompiler compiler, String processor, String testMethod, String testClass, String resourceArea) throws IOException {
+ internalTest(compiler, processor, testMethod, testClass, resourceArea, false);
+ }
+ private void internalTest(JavaCompiler compiler, String processor, String testMethod, String testClass, String resourceArea, boolean continueWithErrors) throws IOException {
+ if (!canRunJava9()) {
+ return;
+ }
+ System.clearProperty(processor);
+ File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", resourceArea);
+ if (testClass == null || testClass.equals("")) {
+ BatchTestUtils.copyResources("targets/" + resourceArea, targetFolder);
+ } else {
+ BatchTestUtils.copyResource("targets/" + resourceArea + "/" + testClass, targetFolder);
+ }
+
+
+ List<String> options = new ArrayList<String>();
+ options.add("-A" + processor);
+ options.add("-A" + testMethod);
+ if (compiler instanceof EclipseCompiler) {
+ options.add("-9");
+ }
+ if (continueWithErrors) {
+ BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, null, true, true);
+ } else {
+ BatchTestUtils.compileTree(compiler, options, targetFolder, 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));
+ }
+ /*
+ * Tests are run in multi-module mode
+ */
+ private void internalTest2(JavaCompiler compiler, String processor, String testMethod, String testClass) throws IOException {
+ if (!canRunJava9()) {
+ return;
+ }
+ System.clearProperty(MODULE_PROC);
+ File srcRoot = TestUtils.concatPath(BatchTestUtils.getSrcFolderName());
+ BatchTestUtils.copyResources("mod_locations/modules", srcRoot);
+
+ List<String> options = new ArrayList<String>();
+ options.add("-processor");
+ options.add(MODULE_PROC);
+ options.add("-A" + MODULE_PROC);
+ options.add("-A" + testMethod);
+ if (compiler instanceof EclipseCompiler) {
+ options.add("-9");
+ }
+ BatchTestUtils.compileInModuleMode(compiler, options, MODULE_PROC, srcRoot, null, true);
+ assertEquals("succeeded", System.getProperty(MODULE_PROC));
+ }
+ public boolean canRunJava9() {
+ try {
+ SourceVersion.valueOf("RELEASE_9");
+ } 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.tests/src/org/eclipse/jdt/compiler/apt/tests/NegativeTests.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/NegativeTests.java
index a447230251..665ffa15d4 100644
--- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/NegativeTests.java
+++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/NegativeTests.java
@@ -184,7 +184,7 @@ public class NegativeTests extends TestCase {
/*
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=328575
*/
- public void testNegativeModel10WithEclipseCompiler() throws IOException {
+ public void _testNegativeModel10WithEclipseCompiler() throws IOException {
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
System.clearProperty(NEGATIVEMODELPROCNAME);
System.clearProperty(INHERITED_PROCNAME);

Back to the top