Should @SupportedAnnotationTypes handle TYPE_USE?

B. Blaser bsrbnd at gmail.com
Mon Sep 24 22:05:31 UTC 2018


Hi,

I noted that the annotation processor [1] isn't run if
@SupportedAnnotationTypes ({"TA"}) is used instead of ({"*"}) because
annotations on TYPE_USE don't seem to be handled when selecting
processors.

Is this normal or should we add something like below (to be completed)?
The documentation [2] isn't clear about that.

Thanks,
Bernard

[1] http://mail.openjdk.java.net/pipermail/compiler-dev/2018-September/012467.html
[2] http://hg.openjdk.java.net/jdk/jdk/file/11b9d3a6f31c/src/java.compiler/share/classes/javax/annotation/processing/SupportedAnnotationTypes.java#l33


diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java
b/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java
@@ -954,9 +954,14 @@
             return super.visitExecutable(e, p);
         }

-        void addAnnotations(Element e, Set<TypeElement> p) {
-            for (AnnotationMirror annotationMirror :
-                     elements.getAllAnnotationMirrors(e) ) {
+        @Override @DefinedBy(Api.LANGUAGE_MODEL)
+        public Set<TypeElement> visitVariable(VariableElement e,
Set<TypeElement> p) {
+            new ComputeTypeAnnos().visit(e.asType(), p);
+            return super.visitVariable(e, p);
+        }
+
+        void addAnnotations(java.util.List<? extends
AnnotationMirror> annos, Set<TypeElement> p) {
+            for (AnnotationMirror annotationMirror : annos ) {
                 Element e2 = annotationMirror.getAnnotationType().asElement();
                 p.add((TypeElement) e2);
             }
@@ -964,9 +969,18 @@

         @Override @DefinedBy(Api.LANGUAGE_MODEL)
         public Set<TypeElement> scan(Element e, Set<TypeElement> p) {
-            addAnnotations(e, p);
+            addAnnotations(elements.getAllAnnotationMirrors(e), p);
             return super.scan(e, p);
         }
+
+        private class ComputeTypeAnnos extends
SimpleTypeVisitor9<Void, Set<TypeElement>> {
+            @Override @DefinedBy(Api.LANGUAGE_MODEL)
+            public Void
visitDeclared(javax.lang.model.type.DeclaredType t, Set<TypeElement>
p) {
+                addAnnotations(t.getAnnotationMirrors(), p);
+                return super.visitDeclared(t, p);
+            }
+            // TODO ...
+        }
     }

     private boolean callProcessor(Processor proc,


More information about the compiler-dev mailing list