Suppose a class defines a constant field:
public class Foo {
public static final int CONSTANT_FIELD = 3;
}
And suppose an annotation interface is declared like the following:
public @interface Something {
int value();
}
Finally, suppose the annotation is used as follows:
@Something(Foo.CONSTANT_FIELD)
Question: In an annotation processor, how can I get the element for CONSTANT_FIELD
from its use in setting the value of @Something
?
Edit: Including a concrete example in the question itself.
I have an annotation that gets used like this:
@RuleDependency(recognizer = BQLParser.class,
rule = BQLParser.RULE_statement,
version = 0)
The annotation processor needs to know that RULE_statement
is a constant defined in the BQLParser
class. If I could access the Element
for BQLParser.RULE_statement
directly from setting the rule
property of the annotation, it would eliminate the need for the recognizer
property. This annotation is used thousands of times within real applications, and the recognizer
is always just the declaring type of the rule
constant. Resolving this question would simplify the annotation usage to just this:
@RuleDependency(rule = BQLParser.RULE_statement, version = 0)