I am processing java annotations using the Pluggable Annotation Processing API. Is it somehow possible to also process annotations used inside a method body?
thanks for help. Peter
I am processing java annotations using the Pluggable Annotation Processing API. Is it somehow possible to also process annotations used inside a method body?
thanks for help. Peter
I think, i found the solution. As i thought, it is not possible with the current javac. local annotations are just simple comments and wont be processed by the pluggable annotation processing api. BUT there are interesting efforts in JSR308, handling type annotations that support marvelous things as parameters on type-variables, local variables, annotated-type-checking and casting... and as it looks, it will be incorporated into openJDK 8. nice
In JSR269, the relevant interface would be javax.lang.model.element.VariableElement
, which inherits getAnnotation(Class<A> annotationType)
for accessing such annotations:
for (VariableElement variable : ElementFilter.fieldsIn(methods)) {
final AnnotationType annotation = variable.getAnnotation(AnnotationType.class);
if (annotation != null) {
// ...
}
}