我有兩個註解:如何從使用註釋處理進行編譯中排除Java類?
@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
annotaion複製課程(在someMethod
方法之前)到@AnotherAnn
。
E.q.註釋處理後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代碼,給一些更多的細節。 –
你有沒有找到解決你的問題。我對它很感興趣。 – Abdullah
不幸的是沒有 – Alexiuscrow