Javax AbstractProcessor
Javax abstract processor is used for creating source code from RententionPolicy.SOURCE
For example if we have
@Retention(RententionPolicy.SOURCE)
@Target(ElementType.METHOD)
public @interface MyAnnotation {
}
We can have an abstract processor to apply the process()
method during compile time
@SupportedAnnotationTypes("java.package.MyAnnotation")
@SupportedSourceVersion(SourceVersion.RELEASE_17)
@AutoService(Processor.class)
public class MyAnnotationProcessor extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
return false;
}
}
In here return true
indicating that the processor should stops processing for the next annotation.
Return false
means it should continue to scan for annotation to process.
[!note]
ForRententionPolicy.RUNTIME
we typically use Reflection to process the annotation