I'm working on an annotation processor and I would pass to my class a parameter representing the annotation to manage, something like: Class<? extends @interface> annotationClass
Unfortunately this does not compile. The only way I can compile is using a raw type Class
but in this way when I try something like
roundEnvironment.getElementsAnnotatedWith(annotationClass)
the returned type is an Object
instead of a javax.lang.model.element.Element
public Map<ClassName, List<ElementInfo>> initClassesToGenerate(Class annotationClass, ElementKind elementKind, RoundEnvironment roundEnvironment) {
Map<ClassName, List<ElementInfo>> result = new HashMap<>();
// init map
for (Element annotatedElement : roundEnvironment.getElementsAnnotatedWith(annotationClass)) {
TypeElement typeElement = (TypeElement) annotatedElement;
ClassName className = ClassName.get(typeElement);
if (!result.containsKey(className)) {
result.put(className, new ArrayList<>());
}
}
return result;
}