I’m trying to create an annotation for a local variable. I know that I can’t retain the annotation in the generated bytecode, but I should be able to have access to the information at compile time by doing something like this:
@Target({ElementType.LOCAL_VARIABLE})
@Retention(RetentionPolicy.SOURCE)
public @interface Junk {
String value();
}
only, this doesn’t get processed by apt, or javac when I specify a ProcessorFactory that has “Junk” in it’s supported types in the following:
class JunkTester {
public static void main(String[] args) {
@Junk String tmp = "Hello World";
System.out.println(tmp);
}
}
It will however work when I move the @Junk annotation before public static
Thoughts and or workarounds?
Did some quick tests and searched a little, and it’s looking like hooking into
LOCAL_VARIABLEisn’t really supported…yet:http://forums.sun.com/thread.jspa?threadID=775449
http://www.cs.rice.edu/~mgricken/research/laptjavac/
https://checkerframework.org/jsr308/
Could be totally wrong, but that’s how it’s looking…