Annotation element values

Alex Buckley alex.buckley at oracle.com
Fri Jan 3 10:54:27 PST 2014


On 12/24/2013 4:53 AM, Mohan Radhakrishnan wrote:
> Tried to subscribe using
> http://mail.openjdk.java.net/mailman/listinfo/type-annotations-dev

Your confirmation mail (the one you send in response to the challenge) 
was received by the list, but for some reason it was not processed. I 
have subscribed you by hand - you should have received a welcome mail.

> I could compile the processor code with b113. But with b120 it doesn't.

Please be more specific. The code below compiled with b113 but does not 
compile with b120? What compile-time error is given?

> Is this code supposed to print the annotation element values ? I am also
> trying to get the annotations applied on the bound 'Integer'.

You are calling typeParameterElement.getAnnotationMirrors(), which 
returns annotations that are directly present on the element. But the 
element - the declaration of a type parameter called T - is completely 
unannotated, so there are no element values to print out.

As for the bound Integer, you are calling 
typeMirror.getAnnotationsByType(...) in the right way. I would expect to 
see @TypeUse(2) and @TypeUse(3) in the output.

Alex

> --------------Source--------------
>     @TypeUse(value = 0) @TypeUse(value = 1)class Test1< T extends
> @TypeUse(value = 2) @TypeUse(value = 3) Integer> {
>
>          /**
>           * A type annotation is permitted in front of a constructor
> declaration, where declaration annotations are already
>           permitted.
>           */
>          @TypeUse(value = 0) <S> Test1(String s){
>
>          }
>      }
>
> }
>
> --------------------Processor code---------------------------
>
> for (TypeParameterElement typeParameterElement : ((TypeElement)
> e).getTypeParameters()) {
>
>              for( AnnotationMirror am  :
> typeParameterElement.getAnnotationMirrors() ){
>
>                  System.out.println( "Annotation [" + am + "] [" +
> typeParameterElement  + "]");
>
>                  for(Map.Entry< ? extends ExecutableElement, ? extends
> AnnotationValue> m : am.getElementValues().entrySet()){
>
>                      System.out.println( "[" + m.getKey() +"][" +
> m.getValue() + "]");
>
>                  }
>
>              }
>
>              for (TypeMirror typeMirror :
> typeParameterElement.getBounds()) {
>
>                  System.out.println( "Annotation [" +
> Arrays.asList(typeMirror.getAnnotationsByType(RepeatableAnnotation.TypeUse.class))
> + "] [" + typeMirror  + "]");
>
>              }
>          }
>      }
>
> Thanks.
>


More information about the type-annotations-dev mailing list