注释-生成时读取元素值
|
是否可以在构建时读取注释元素的值?例如,如果我定义了以下注释:
public @interface State {
String stage();
}
并且我在类中注释了一个方法,如下所示:
public class Foo {
@State(stage = \"build\")
public String doSomething() {
return \"doing something\";
}
}
如何在构建时在注释处理器中读取@State注释元素\'stage \'的值?我有一个如下构建的处理器:
@SupportedAnnotationTypes(value = {\"State\"})
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class StageProcessor extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> elementTypes,
RoundEnvironment roundEnv) {
for (Element element : roundEnv.getRootElements()) {
// ... logic to read the value of element \'stage\' from
// annotation \'State\' in here.
}
return true;
}
}
没有找到相关结果
已邀请:
1 个回复
淘圃跺枯替
文件夹中创建一个名为
的文件,该文件列出了注释处理器的名称,每行一个。 编辑:因此,我相信读取批注的代码将类似于...
注释处理器的真实示例可以在这里找到。