Java 在注释处理期间获取原始注释数据

Java 在注释处理期间获取原始注释数据,java,annotations,annotation-processing,Java,Annotations,Annotation Processing,我正在吃这样的东西 @Value(name="values1", values = { R.string.first, R.string.second, R.string.third }) 这是变异 @Value(name="values2", values = { R.integer.first, R.integer.second, R.integer.third }) R.integer.*和R.string.*只是在相应类中声明的int常量 因此,在注释处理过程中,我不知何故需要获取全

我正在吃这样的东西

@Value(name="values1", values = { R.string.first, R.string.second, R.string.third })
这是变异

@Value(name="values2", values = { R.integer.first, R.integer.second, R.integer.third })
R.integer.*
R.string.*
只是在相应类中声明的int常量

因此,在注释处理过程中,我不知何故需要获取全名(例如“R.integer.first”),而不是获取R.integer.first的实际int值

目前,我只能读取值:

Value debug = e.getAnnotation(Value.class);
String name= debug.name();
int[] values = debug.values();

似乎我找到了答案,所以根据我的观察,您只能访问最终值,因为编译器可能会在编译的早期阶段将常量替换为实际值

在注释中访问数据的机制如下:

for (AnnotationMirror mirror : e.getAnnotationMirrors()) {
    for (ExecutableElement el : mirror.getElementValues().keySet()) {
        info("Element:" + el + " Value:" + elementValues.get(el));
    }
}
其中
e
是通过注释处理器获得的
元素