[Checkers] Processing unknown annotations

Michael Ernst mernst at csail.mit.edu
Thu May 29 03:53:12 EDT 2008


Here's another attempt at my reply to the query about processing unknown
annotations.  Is it right now?



> Is there any support for processing unknown annotations?
> In my case I want to allow the analysis of user provided annotations.

This is easy enough to do.  The Custom Checker that is distributed with the
Checker Framework already does this.  For documentation, see


You can also read its code, which may help you with your task.

(Note:  In the next release, the Custom Checker will be renamed to the
Basic Checker.)

> I do not have any idea what SupportedAnnotationTypes and TypeQualifiers
> annotations actually do, so I am concerned if what I want to do is feasible.

In short, you should ignore SupportedAnnotationTypes, and you shouldn't
even write it on your checker; see below my signature for details.
Instead, do one of the following two things:

 * Use @TypeQualifiers to list the annotations that your checker processes,
 * Override the getSupportedTypeQualifiers() method.  This is necessary
   when processing unknown annotations.  You can look at the implementation
   of the Basic Checker for inspiration.


Explanation about SupportedAnnotationTypes:

javax.annotation.processing.SupportedAnnotationTypes is supplied by Sun,
and we have not changed its meaning.  Unfortunately, that meaning is not
well-documented by Sun.  The compiler uses @SupportedAnnotationTypes to
determine whether or not a processor should be invoked on a given file.  If
a file does not contain one of the given annotations, then javac does not
invoke the annotation processor on the file.

Checkers are different:  they should process all files, always.  The
Javadoc [1] suggests that a processor should use


when processing all files, which is exactly what we want.  However, you
don't have to write if you subclass BaseTypeChecker, because
BaseTypeChecker takes care of that for you.  So, don't write
@SupportedAnnotationTypes at all in a checker.

[1] http://java.sun.com/javase/6/docs/api/javax/annotation/processing/Processor.html#getSupportedAnnotationTypes()

More information about the checkers mailing list