Interaction between @Target meta-annotations and fully-qualified types

Alex Buckley alex.buckley at oracle.com
Mon Apr 22 12:33:40 PDT 2013


Thanks Mike, this is a helpful piece of non-normative text for the JLS. 
Note that "AST" and "annotation processing" are not phrases which will 
ever appear in normative JLS text.

I note that a method whose result is 'void' (and hence has no return 
type) cannot allow a solely-TYPE_USE annotation where a METHOD 
annotation previously stood. This is an argument against partitioning 
type annotations and declaration annotations. The code below shows it is 
necessary to add TYPE_USE to METHOD in the annotation type's 
declaration, assuming the annotation type is to be applied widely.

   @MAnno void myMethod1() { ... }   // legal, one method annotation
   @TAnno void myMethod2() { ... }   // illegal
   @MTAnno void myMethod3() { ... }  // legal, one method annotation

Alex

On 4/21/2013 5:04 PM, Michael Ernst wrote:
> 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-experts mailing list