private void processAnnotations(RoundEnvironment roundEnv) {
TypeElement processor =
processingEnv.getElementUtils().getTypeElement(Processor.class.getCanonicalName());
TypeElement abstractProcessor =
processingEnv.getElementUtils().getTypeElement(AbstractProcessor.class.getCanonicalName());
for (Element e : roundEnv.getElementsAnnotatedWith(IncrementalAnnotationProcessor.class)) {
if (!checkAnnotatedElement(e, processor)) {
continue;
}
IncrementalAnnotationProcessorType processorType =
e.getAnnotation(IncrementalAnnotationProcessor.class).value();
if (processorType == IncrementalAnnotationProcessorType.DYNAMIC
&& processingEnv.getTypeUtils().isSubtype(e.asType(), abstractProcessor.asType())) {
Element getSupportedOptions =
processingEnv.getElementUtils().getAllMembers((TypeElement) e).stream()
.filter(
method ->
method.getKind() == ElementKind.METHOD
&& method.getSimpleName().contentEquals(GET_SUPPORTED_OPTIONS)
&& ((ExecutableElement) method).getParameters().isEmpty())
.findFirst()
.orElseThrow(AssertionError::new);
if (abstractProcessor.equals(getSupportedOptions.getEnclosingElement())) {
warning(
"Dynamic incremental annotation processor should override "
+ GET_SUPPORTED_OPTIONS
+ "()",
e);
}
}
processors.put(
processingEnv.getElementUtils().getBinaryName((TypeElement) e).toString(), processorType);
}
}