[JSR308] Javac Processor API

Tom Ball Tom.Ball at Sun.COM
Thu Mar 1 16:22:18 EST 2007


Niko Matsakis wrote:
> Hello,
> 
> It may be better to wait to pose this question until the reference 
> implementation is available, but I am wondering whether JSR308 is 
> considering any change in the scheduling of Annotation Processors within 
> Javac.  In the official document, it seems that no major changes are 
> planned to the A.P. interface.
> 
> As I understand the javac code --- and my understanding may well be 
> limited --- compilation currently takes place in four "main" stages: 
> Parsing, Annotation Processing, Attribution, Flow Checking.  These 
> stages are then followed by desugaring and code generation.

Your list of phases is incomplete.  Between parsing and annotation 
processing, the symbol (element) table is built.  That is easy to miss 
in the javac source, since the phase is internally called "enter".  All 
class elements are created, along with member element initializers which 
get invoked on demand.  Since all symbols have types, those get created, 
too.  The model is "raw" at this point as there has been no type checks 
run yet, so basically you have a good model with compilable source code, 
but a flawed model if the source has attribution-level failures.

> My concern is that if annotation processors using the Tree API attempt 
> to check the additional type annotations, they will run before any 
> attribution of the parse trees is done.  As a result, these processors 
> have no access to higher-level semantic information (in fact, there are 
> no accessors for this kind of information in the Tree API).  For 
> example, if they see an expression like "foo.bar", they do not know 
> whether foo is a local variable or a field, or what the type of "bar" 
> is.  It seems that even the most rudimentary type systems will require 
> the ability to trace a field reference to its definition.

You are right -- as you have described it, annotation processing 
wouldn't work since its API is based on elements.

If you have doubts regarding my assertions, I recommend writing a simple 
annotation processor which dumps the information passed to it.

Tom



More information about the JSR308 mailing list