I'm writing an annotation processor which needs to collect all the classes with a certain annotation in the current module and write a class referencing each of them.
To simplify a bit, given these source files:
src/main/java/org/example/A.java@Annotation
class A {}
src/main/java/org/example/B.java
@Annotation
class B {}
I want to generate a class:
target/generated-sources/org/example/Module.javaclass Module {
String getModuleClasses() {
return Arrays.asList(
"org.example.A",
"org.example.B"
);
}
}
This works from Maven, but when I modify class A
, IntelliJ gives my annotation processor a RoundEnvironment
with A
as the single root element.
I understand Gradle supports incremental compilation with
aggregating annotation processors
by passing a fake RoundEnvironment
with all the sources matching the annotations to the annotation processor, but IntelliJ doesn't seem to have anything similar. (Except maybe for Gradle projects?)
What would be the best way to find both classes when IntelliJ compiles only class A
?
Maybe the annotator could keep a list of annotated classes: read the list from a resource file in the first round, in each round remove from the list root elements and add to the list elements which are annotated, and write the list back to the resource file in the final round?