Using the com/sun/tools/javac APIs

Erik van Zijst erik.van.zijst at
Thu Feb 18 00:13:42 PST 2010

Hi Brendon,

I have the full source code and I've been step-through debugging the 
various api implementations for a day now, but I just can't fully grok 
it. I'm glad to hear I'm not the only one :)

I hadn't heard about Sourcerer before, but it is indeed doing exactly 
what I'm after (and those icons look familiar!). I'm not rendering HTML, 
but maybe I can use it as a starting point.


Brendon McLean wrote:
> Hi Erik,
> I've dabbled in those APIs as well, and it is some the most
> impenetrable code I've looked at.  You'll obviously need the source
> code as the documentation is almost completely unhelpful, and you'll
> probably need to look at it in a good IDE to hyperlink back and
> forward as you untangle the labyrinth.
> But I would strongly suggest checking out Kohsuke Kawaguchi's
> sourcerer project at (or for the blog
> that mentions it:
> It seems like he's managed to accomplish exactly what you want to do,
> so it would be well worth checking it out.
> Regards, Brendon McLean.
> On 18 Feb 2010, at 8:50 , Erik van Zijst wrote:
>> Hi folks,
>> Not sure if tis is the appropriate mailinglist, but I'm trying to
>> get my head around the various javac API's and I'm having trouble
>> understanding what I can or can not do.
>> I'm parsing and traversing a set of source files using the
>> unsupported API and for every method
>> invocation and type reference, I want to resolve the exact (source)
>> location where that method of type is declared, so that I can
>> render the sources with hyperlinks for full navigation (IDE-style).
>> I'm having limited success. Traversing the JCTree.JCCompilationUnit
>> list after the JavacTask.parse() step does not seems to offer name
>> and type resolving (presumably because the attribution step hasn't
>> run yet?).
>> Traversing the javax.lang.model.element.Elements list from
>> JavacTask.analyze() gives me class and method declarations with the
>> name of the respective java source file (but not their character
>> offset positions).
>> Using the javac APIs, how do I go about matching these sets? Am I
>> overlooking some functionality, or is this a non trivial task?
>> Correct resolution is crucial. For instance, it's important that a
>> call to SubType.finalMethodOnSuperClass() properly links to the
>> declartion of finalMethodOnSuperClass() in the BaseType file
>> (assuming SubType extends BaseType).
>> Cheers, Erik

More information about the compiler-dev mailing list