[type-annos-observers] Type annotations don't look very Java-like

Alex Buckley alex.buckley at oracle.com
Wed Sep 18 15:27:05 PDT 2013


David,

It looks like there is a problem with how NetBeans handles annotations 
on type names. I confess to not knowing which NetBeans engineer is 
working on type annotations, so please inform them of the problem below.

Timo,

On 9/18/2013 12:01 PM, Timo Kinnunen wrote:
> Alex, there might be bugs or unimplemented changes, but trying it out in
> the latest NetBeans IDE 4.7 Beta, JDK 1.8.0-ea-b106 and the annotation
> @Regarding defined like this:
>
> @Retention(value = RetentionPolicy.RUNTIME)
> @Target(value = {ElementType.TYPE_USE, ElementType.PARAMETER,
> ElementType.FIELD, ElementType.LOCAL_VARIABLE})
> @interface Regarding { }
>
> Then as seen in the Trees (NetBeans development) view, right now you do
> have to write “com.somecompany.AnnotationTestBed.” in front of the
> annotation to modify the modifier into becoming an annotated type instead.
> Specifically, instead of 1xMODIFIER, 1xIDENTIFIER there will be 0xMODIFIER,
> 1xANNOTATED_TYPE.
>
> I don’t know where this change in semantics comes from or what its meaning
> is, but I can see that it’s there. And as long as it is there, it can
> become requirement for using some functionality in any tool that can detect
> its presence.

I'm on JDK 1.8.0-ea-b106. Here's a simplified test case:

--
import java.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
@interface Regarding { }

public class C {
   void m(@Regarding Object oldOne) {}
}
--

javac will emit C.class with a RuntimeVisibleParameterAnnotations 
attribute for the 'm' method, just as it did in JDK7.

Then, if you add ElementType.TYPE_USE to the @Target value:

@Target({ElementType.TYPE_USE, ElementType.PARAMETER})

and recompile, javac will emit C.class with a second attribute, 
RuntimeVisibleTypeAnnotations, for the 'm' method. There are no 
surprises here, and no need for qualified type names.

If you really want to write "java.lang. at Regarding Object oldOne", you 
can, and it's compiled correctly to just RuntimeVisibleTypeAnnotations - 
no RuntimeVisibleParameterAnnotations in sight. But you don't have to.

Alex


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