[type-annos-observers] Interaction between @Target meta-annotations and fully-qualified types

Michael Ernst mernst at cs.washington.edu
Sun Apr 21 17:04:56 PDT 2013


Dear Type Annotations experts,

I recently added the following example to the JSR 308 (Type
Annotations) specification, and thought that I would pass it along to
ensure this is the anticipated behavior.

Suppose you have these definitions:

  @Target({TYPE_USE}) @interface TAnno { }
  @Target({METHOD}) @interface MAnno { }
  @Target({METHOD, TYPE_USE}) @interface MTAnno { }
  @Target({FIELD}) @interface FAnno { }
  @Target({FIELD, TYPE_USE}) @interface FTAnno { }

For each of the below examples, a comment states whether the syntax is
legal or illegal.  For each legal source-code annotation, the comment
states how many annotations appear in the AST during annotation
processing and in the classfile.

  @FAnno Object field4;              // legal, one field annotation
  @TAnno Object field5;              // legal, one type annotation
  @FTAnno Object field6;             // legal, one field annotation and one type annotation
  @FAnno java.lang.Object field7;    // legal, one field annotation
  @TAnno java.lang.Object field8;    // illegal
  @FTAnno java.lang.Object field9;   // legal, one field annotation
  java.lang. @FAnno Object field10;  // illegal
  java.lang. @TAnno Object field11;  // legal, one type annotation
  java.lang. @FTAnno Object field12  // legal, one type annotation

  @MAnno void myMethod1() { ... }                // legal, one method annotation
  @TAnno void myMethod2() { ... }                // illegal
  @MTAnno void myMethod3() { ... }               // legal, one method annotation
  @MAnno Object myMethod4() { ... }              // legal, one method annotation
  @TAnno Object myMethod5() { ... }              // legal, one type annotation
  @MTAnno Object myMethod6() { ... }             // legal, one method annotation and one type annotation
  @MAnno java.lang.Object myMethod7() { ... }    // legal, one method annotation
  @TAnno java.lang.Object myMethod8() { ... }    // illegal
  @MTAnno java.lang.Object myMethod9() { ... }   // legal, one method annotation
  java.lang. @MAnno Object myMethod10() { ... }  // illegal
  java.lang. @TAnno Object myMethod11() { ... }  // legal, one type annotation
  java.lang. @MTAnno Object myMethod12() { ... } // legal, one type annotation


		    -Mike


More information about the type-annotations-spec-observers mailing list