我在编译时使用 APT 处理注释,我需要获取@XmlElement
某些类中注释的值。该类看起来像这样:
public class ComponentConfig {
@XmlElements({
@XmlElement(type = Sample1.class, name = "sample-1-config"),
@XmlElement(type = Sample2.class, name = "sample-2-config"),
@XmlElement(type = Sample3.class, name = "sample-3-config"),
})
//...
}
我想获取 的name
值@XmlElement
,但以下处理器代码无法为我获取它:
List<? extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors();
for (AnnotationMirror mirror : annotationMirrors) {
if (mirror.getAnnotationType().toString().equals(XML_ELEMENT)) {
System.out.println(getAnnotationValueMapValueOfName(mirror));
nodes.add(getAnnotationValueMapValueOfName(mirror));
}
}