@SupportedAnnotationTypes({"com.tg.annotation.Table", "com.tg.annotation.Test"})
public class TgDaoGenerateProcessor extends AbstractProcessor {
private Messager messager;
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
messager = processingEnv.getMessager();
}
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
messager.printMessage(Diagnostic.Kind.NOTE, "annotations size " + annotations.size());
}
In my project have a class annotated @Table
and a class annotated @Test
I clean output directory and build in Intellij, output two lines:
annotations size 2
annotations size 0
why have two lines? what have javac done?
And if I rebuild it nothing is printed. I guess I don't modify source code so javac will not generate new .class
. If I modify a class annotated with @Table
and rebuild, the output is: annotations size 1
. APT get @Table
info, can't get @Test
annotated class info, because i don't modify class annotated @Test
?
I want to get class info annotated @Table
and @Test
and use those to generate an xml file. Give a example:class A annotated @Table
and class B annotated @Test
and APT will get class A's and B's fields and methods , then write them into a new file. So if only modify class A , to change some fields and methods.Build and the APT Processor can't get class B that annotated @Test
, missing those info I can't generate a latest xml file. Sure, I clean output directory and rebuild, it will work, but nobody willing to do that right. So change anyone class, how to make APT Processor can get all class info.