Incremental java compile AKA javac print compile dependencies

Jonathan Gibbons jonathan.gibbons at
Thu May 27 11:33:54 PDT 2010

On 05/27/2010 12:20 AM, Joshua Maurice wrote:
> Thank you again, but do you know any good examples of those APIs? I am 
> unable to quickly find some good documentation or examples on Types, 
> type mirrors, and such.

For docs, start with

Roughly speaking, once you get to the point of being able to call 
parse() and analyze() ...

-- walk the trees with a TreeScanner
     -- you're looking for nodes which reference other classes; this 
mostly means you need to look for declarations and expressions

-- expressions have a type (TypeMirror), from a type you want to get to 
its element.
     -- a type is an "instance", like List<String>, an element is an 
entity in the source and is like a decl of a family of types, like List<T>
     -- move between types and elements using the Types and Elements 
utility APIs

-- from an element, use getEnclosingElement to get to the element that 
you wish to record a dependency on
     -- e.g. your class might use, but you might want to record a 
dependency on class X, not field foo.

-- from an element, if you need to you can get to its tree (via 
Trees.getTree) or its compilation unit (via Trees.getPath)

-- from a compilation unit, you can get the source file

And Robert's your father's brother.

More information about the compiler-dev mailing list