【发布时间】:2015-08-23 19:19:11
【问题描述】:
我有两个注释:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Ann {
public String description() default "AAA";
public String template() default "BBB";
}
和
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface AnotherAnn {
public String text() default "Text";
}
带有注释方法的简单类:
public class App {
@Ann(description = "Desc", template = "Templ")
public void someMethod(){}
}
我想创建App 类的新副本并将复制类中的@Ann 注释(在someMethod 方法之前)替换为@AnotherAnn。
方程注解处理后App类的副本:
public class AppCopy {
@AnotherAnn(text = "Text")
public void someMethod(){}
}
然后我应该将App 类排除在编译之外。
处理器:
@SupportedAnnotationTypes("alexiuscrow.annotation.Ann")
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class Proc extends AbstractProcessor {
public Proc() {
super();
}
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
/* TODO CREATE COPY & EXCLUDE ORIGINAL */
return true;
}
}
我该怎么做?
【问题讨论】:
-
把你正在尝试的java代码,提供更多细节。
-
您找到解决问题的方法了吗?我对它很感兴趣。
标签: java annotations annotation-processing