Search code examples
javaannotationsjavacannotation-processing

Java annotation processing: Accessing "Element"s of non-annotated classes possible?


Java annotation processing (since Java 6) is a very good concept, because it allows to access lots of information about classes and methods through the Element interface (and others).

But sadly, I had to find out empirically, that non-annotated classes are never passed to a custom annotation processor:

warning: No SupportedAnnotationTypes annotation found on
    my.TESTProcessor, returning an empty set.

Are my findings true? Or can I "trick" the compiler to give my custom annotation processor information about non-annotated classes as well?


Solution

  • Great!

    This gives me really all classes, not just annotated ones:

    @SupportedAnnotationTypes("*")
    

    The spec of that anotation says:

    [...] Finally, "*" by itself represents the set of all annotation types,
    including the empty set. Note that a processor should not claim "*"
    unless it is actually processing all files [...] 
    

    Tested, works!