processing of annotations inside a method body

∥☆過路亽.° 提交于 2019-12-12 08:28:21

问题


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


回答1:


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




回答2:


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) {
        // ...
    }
}


来源:https://stackoverflow.com/questions/7809943/processing-of-annotations-inside-a-method-body

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!