Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjay2018-08-08 07:14:16 +0000
committerJayaprakash Arthanareeswaran2018-08-08 11:42:46 +0000
commita8119f5a19c5e89a1af1d9ee62dbab09a2622af4 (patch)
treeb139d4aa46d9e86c39867663961d797ceb1dbe2b /org.eclipse.jdt.compiler.apt.tests
parent9baccea1e09ccd17f92b0bc90f96b9a3a2cb6cf9 (diff)
downloadeclipse.jdt.core-a8119f5a19c5e89a1af1d9ee62dbab09a2622af4.tar.gz
eclipse.jdt.core-a8119f5a19c5e89a1af1d9ee62dbab09a2622af4.tar.xz
eclipse.jdt.core-a8119f5a19c5e89a1af1d9ee62dbab09a2622af4.zip
Bug 498022 - Annotation Processing: No type annotations returned forI20180810-0320I20180809-2000
annotation values that are arrays of classes Change-Id: I30b8b912e04084cd48eea8a7db72a8385c84f0be Signed-off-by: jay <jarthana@in.ibm.com>
Diffstat (limited to 'org.eclipse.jdt.compiler.apt.tests')
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jarbin235964 -> 238626 bytes
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/annotations/FooBarAnnotation.java9
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java9ElementProcessor.java80
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/targets/model9/q/FooBarAnnotation.java8
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/targets/model9/q/Main.java12
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/targets/model9/q/OtherAnnotatedClass.java4
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/targets/model9/q/SomeAnnotatedClass.java4
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java9ElementsTests.java16
8 files changed, 130 insertions, 3 deletions
diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
index bf811a9fe5..d4769c36c2 100644
--- a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
+++ b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
Binary files differ
diff --git a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/annotations/FooBarAnnotation.java b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/annotations/FooBarAnnotation.java
new file mode 100644
index 0000000000..5175fa1f23
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/annotations/FooBarAnnotation.java
@@ -0,0 +1,9 @@
+package org.eclipse.jdt.compiler.apt.tests.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+@Target(ElementType.TYPE)
+public @interface FooBarAnnotation {
+ Class<?>[] otherClasses() default {};
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java9ElementProcessor.java b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java9ElementProcessor.java
index 8310874eba..7ba4ca5653 100644
--- a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java9ElementProcessor.java
+++ b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java9ElementProcessor.java
@@ -25,6 +25,7 @@ import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.AnnotatedConstruct;
+import javax.lang.model.SourceVersion;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;
@@ -39,6 +40,7 @@ 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.element.VariableElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.NoType;
import javax.lang.model.type.TypeKind;
@@ -381,6 +383,12 @@ public class Java9ElementProcessor extends BaseProcessor {
* Test java.base module can be loaded and verify its exports attributes
*/
public void testModuleJavaBase1() {
+ int modCount = 108;
+ try {
+ SourceVersion.valueOf("RELEASE_10");
+ modCount = 102;
+ } catch(IllegalArgumentException iae) {
+ }
Set<? extends ModuleElement> allModuleElements = _elementUtils.getAllModuleElements();
ModuleElement base = null;
for (ModuleElement moduleElement : allModuleElements) {
@@ -391,7 +399,7 @@ public class Java9ElementProcessor extends BaseProcessor {
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());
+ assertEquals("incorrect no of exports", modCount , filterDirective.size());
ExportsDirective pack = null;
for (Directive directive : filterDirective) {
ModuleElement.ExportsDirective exports = (ExportsDirective) directive;
@@ -584,7 +592,7 @@ public class Java9ElementProcessor extends BaseProcessor {
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());
+ assertEquals("incorrect no of packages", 4, filterElements.size());
// FIXME: Note Javac fails here as well
// PackageElement packageOf = _elementUtils.getPackageOf(mod);
// assertNotNull("package should not be null", packageOf);
@@ -745,6 +753,61 @@ public class Java9ElementProcessor extends BaseProcessor {
}
assertTrue("Exception not thrown", exception);
}
+ public void testBug498022a() {
+ Set<? extends Element> rootElements = roundEnv.getRootElements();
+ TypeElement type = null;
+ for (Element element : rootElements) {
+ if (element.getSimpleName().toString().equals("Main")) {
+ type = (TypeElement) element;
+ break;
+ }
+ }
+ VariableElement field = null;
+ if (type != null) {
+ List<? extends Element> members = _elementUtils.getAllMembers(type);
+ for (Element member : members) {
+ if ("someField".equals(member.getSimpleName().toString())) {
+ field = (VariableElement) member;
+ }
+ }
+ }
+ assertNotNull("field should not be null", field);
+ TypeMirror asType = field.asType();
+ DeclaredType declaredType = (DeclaredType) asType;
+ Element asElement = declaredType.asElement();
+ verifyAnnotations(asElement, new String[] {"@org.eclipse.jdt.compiler.apt.tests.annotations.Type(value=c)"});
+ }
+ public void testBug498022b() {
+ Set<? extends Element> rootElements = roundEnv.getRootElements();
+ TypeElement type = null;
+ TypeElement anotherType = null;
+ for (Element element : rootElements) {
+ if (element.getSimpleName().toString().equals("OtherAnnotatedClass")) {
+ type = (TypeElement) element;
+ } else if (element.getSimpleName().toString().equals("SomeAnnotatedClass")) {
+ anotherType = (TypeElement) element;
+ }
+ }
+ verifyAnnotations(type, new String[] {"@targets.model9.q.FooBarAnnotation()"});
+ verifyAnnotations(anotherType, new String[] {"@targets.model9.q.FooBarAnnotation(otherClasses=[targets.model9.q.OtherAnnotatedClass.class,])"});
+ List<? extends AnnotationMirror> annots = anotherType.getAnnotationMirrors();
+ AnnotationMirror annotationMirror = annots.get(0);
+ Map<? extends ExecutableElement, ? extends AnnotationValue> values = annotationMirror.getElementValues();
+ AnnotationValue value = null;
+ Set<? extends ExecutableElement> keys = values.keySet();
+ for (ExecutableElement executableElement : keys) {
+ if (executableElement.getSimpleName().toString().equals("otherClasses"))
+ value = values.get(executableElement);
+ }
+ assertNotNull("value should not be null", value);
+ @SuppressWarnings("rawtypes")
+ List list = (List) value.getValue();
+ assertEquals("Incorrect no of values", 1, list.size());
+ AnnotationValue annotVal = (AnnotationValue) list.get(0);
+ DeclaredType declaredType = (DeclaredType) annotVal.getValue();
+ TypeElement typeEl = (TypeElement) declaredType.asElement();
+ verifyAnnotations(typeEl, new String[] {"@targets.model9.q.FooBarAnnotation()"});
+ }
private void validateModifiers(ExecutableElement method, Modifier[] expected) {
Set<Modifier> modifiers = method.getModifiers();
List<Modifier> list = new ArrayList<>(modifiers);
@@ -881,7 +944,18 @@ public class Java9ElementProcessor extends BaseProcessor {
buf.append(executableElement.getSimpleName());
buf.append('=');
AnnotationValue value = values.get(executableElement);
- buf.append(value.getValue());
+ if (value.getValue() instanceof List) {
+ buf.append('[');
+ @SuppressWarnings("rawtypes")
+ List list = (List) value.getValue();
+ for (Object obj : list) {
+ buf.append(obj.toString());
+ buf.append(',');
+ }
+ buf.append(']');
+ } else {
+ buf.append(value.getValue());
+ }
}
buf.append(')');
return buf.toString();
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/targets/model9/q/FooBarAnnotation.java b/org.eclipse.jdt.compiler.apt.tests/resources/targets/model9/q/FooBarAnnotation.java
new file mode 100644
index 0000000000..cf2db4292a
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/targets/model9/q/FooBarAnnotation.java
@@ -0,0 +1,8 @@
+package targets.model9.q;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+@Target(ElementType.TYPE)
+public @interface FooBarAnnotation {
+ Class<?>[] otherClasses() default {};
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/targets/model9/q/Main.java b/org.eclipse.jdt.compiler.apt.tests/resources/targets/model9/q/Main.java
new file mode 100644
index 0000000000..0c114a6523
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/targets/model9/q/Main.java
@@ -0,0 +1,12 @@
+package targets.model9.q;
+
+import org.eclipse.jdt.compiler.apt.tests.annotations.Type;
+
+public class Main {
+ @Type("f")
+ public SomeClassWithAnAnnotation someField;
+}
+
+@Type("c")
+class SomeClassWithAnAnnotation {
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/targets/model9/q/OtherAnnotatedClass.java b/org.eclipse.jdt.compiler.apt.tests/resources/targets/model9/q/OtherAnnotatedClass.java
new file mode 100644
index 0000000000..a8bea67bff
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/targets/model9/q/OtherAnnotatedClass.java
@@ -0,0 +1,4 @@
+package targets.model9.q;
+@FooBarAnnotation
+public class OtherAnnotatedClass {
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/targets/model9/q/SomeAnnotatedClass.java b/org.eclipse.jdt.compiler.apt.tests/resources/targets/model9/q/SomeAnnotatedClass.java
new file mode 100644
index 0000000000..0f514930d9
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/targets/model9/q/SomeAnnotatedClass.java
@@ -0,0 +1,4 @@
+package targets.model9.q;
+@FooBarAnnotation(otherClasses=OtherAnnotatedClass.class)
+public class SomeAnnotatedClass {
+}
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
index dd3cc098a4..1ba07fc8c5 100644
--- 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
@@ -379,6 +379,22 @@ public class Java9ElementsTests extends TestCase {
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
internalTest2(compiler, MODULE_PROC, "testTypesImpl", null);
}
+ public void testBug498022a() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest(compiler, MODULE_PROC, "testBug498022a", null, "model9");
+ }
+ public void testBug498022aJavac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ internalTest(compiler, MODULE_PROC, "testBug498022a", null, "model9");
+ }
+ public void testBug498022b() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTest(compiler, MODULE_PROC, "testBug498022b", null, "model9");
+ }
+ public void testBug498022bJavac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ internalTest(compiler, MODULE_PROC, "testBug498022b", null, "model9");
+ }
protected void internalTestWithBinary(JavaCompiler compiler, String processor, String compliance, String testMethod, String testClass, String resourceArea) throws IOException {
if (!canRunJava9()) {
return;

Back to the top