我有以下课程:
public class Start extends PlacePresenter {
@NameToken("startPage")
public interface MyProxy extends ProxyPlace {
}
}
在注释处理器中,我使用@NameToken注释了元素,即MyProxy。
@Override
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
for (Element annotatedElement : roundEnv.getElementsAnnotatedWith(NameToken.class)) {
TypeElement typeElement = (TypeElement) annotatedElement;
// typeElement is MyProxy
}
}
如何定义MyProxy类的元素,即Start
?
答案 0 :(得分:0)
包含的类将由调用Element
返回的annotatedElement.getEnclosingElement()
表示:
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (Element annotatedElement : roundEnv.getElementsAnnotatedWith(NameToken.class)) {
System.out.println(annotatedElement.getEnclosingElement()); // prints "Start"
}
return true;
}