runt18 / jsr-305

Automatically exported from code.google.com/p/jsr-305
0 stars 0 forks source link

Annotations require @Target for JSR-308 compatibility #25

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi.

I've been using javax.annotation.Nullable and javax.annotation.Nonnull in my 
code, as they're IDE neutral and capable of being recognized by several popular 
tools.

However, Java 1.8 requires that inner-class and qualified type references use 
an annotation syntax which is compatible with it's new JSR-308 support (e.g. A 
"@Nullable MyOuterClass.MyInnerClass" parameter becomes "MyOuterClass.@Nullable 
MyInnerClass").

Doing that with the JSR-305 annotations causes javac to complain "annotation 
type not applicable to this kind of declaration", and Eclipse to complain 
"Annotation types that do not specify explicit target element types cannot be 
applied here".

This is because the JSR-305 annotation definitions lack a declaration of the 
form:

@java.lang.annotation.Target({ java.lang.annotation.ElementType.FIELD, 
java.lang.annotation.ElementType.METHOD, 
java.lang.annotation.ElementType.PARAMETER, 
java.lang.annotation.ElementType.LOCAL_VARIABLE })

While JSR-305 may not currently be moving forward as an official standard, it's 
still of great value to many people as a defacto one, so if there is any way 
@Target could be added in order for that to continue with Java 1.8 until 
something more official comes along, it would be most excellent.

Many thanks for your consideration.

Original issue reported on code.google.com by chris@hubick.com on 3 Jan 2014 at 12:59

GoogleCodeExporter commented 8 years ago
Correction - It appears as though @Target({ TYPE_USE }) is what the null 
annotations are actually required to have in this case, and since TYPE_USE is 
new in Java 1.8, that certainly complicates this request.

Original comment by chris@hubick.com on 3 Jan 2014 at 5:13