Sve*_*uer 3 java annotations annotation-processing
我有以下注释:
@Target(ElementType.METHOD)
public @interface MyAnn {
}
Run Code Online (Sandbox Code Playgroud)
以及用以下注释的方法@MyAnn:
@MyAnn
Object myMehtod(Object x) {
...
}
Run Code Online (Sandbox Code Playgroud)
使用 Java 注释处理器,我得到的注释元素为:
Element annotatedElement // = myMehtod
Run Code Online (Sandbox Code Playgroud)
这是我的解决方案:
ExecutableType executableType = (ExecutableType)annotatedElement.asType();
List<? extends TypeMirror> parameters = executableType.getParameterTypes();
TypeMirror param1 = parameters.get(0);
DeclaredType declaredType = (DeclaredType)param1;
List<? extends AnnotationMirror> anns = ((TypeElement)declaredType.asElement()).getAnnotationMirrors( );
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2276 次 |
| 最近记录: |