Question about type annotations

Julian Bangert bangert at google.com
Tue Oct 18 00:18:40 UTC 2016


Hello (re-sending due to moderation),

I am working on a checker based on the error-prone framework that works
with (Java 8) type annotations. The javac AST seems to be missing
annotation types for generic methods (and constructors on generic types):

// Annotation .java
package test;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;

 @Target({
    ElementType.TYPE_USE,
    ElementType.FIELD,
    ElementType.LOCAL_VARIABLE,
    ElementType.PARAMETER,
    ElementType.METHOD
  })
public interface @Annotation {}


// Generic.java
 package test;
  public class Generic {
      public static <V> void Method(V value) {
      }
  }

// Testcase.java

package test;
import java.util.List;
public class Testcase {
    void test(List<@Annotation String> list, String foo) {
        list.add(foo);
        Generic.<@Annotation String>Method(foo);
    }
}

Now call node.getMethodSelect() on the MethodInvocation AST nodes generated
by this snippet. For the first call site (list.add(foo)),
node.getMethodSelect() returns a JCFieldAccess with type

"(@test.Annotation java.lang.String)boolean" (note the annotation).

When I do the same for Generic.<@Annotation String>Method, I merely get
"(java.lang.String)void".

Is this a bug or intended behaviour? Is there a way to get annotation on
the types (besides implementing my own lookup, which might be
buggy/unelegant).

Regards,
Julian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20161018/55fdad5a/attachment.html>


More information about the compiler-dev mailing list