Using the com/sun/tools/javac APIs
Jonathan Gibbons
Jonathan.Gibbons at Sun.COM
Thu Feb 18 09:16:50 PST 2010
Erik,
You should look at the combination of the javax.lang.model API and the
com.sun.source API. The com.sun.source API should give you the hooks
you need to get at the source positions (if any) for the elements found
by the javax.lang.model API.
-- Jon
Erik van Zijst wrote:
> 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.
>
> Cheers,
> Erik
>
>
> 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 https://sorcerer.dev.java.net/ (or for the blog
>> that mentions it:
>> http://weblogs.java.net/blog/kohsuke/archive/2006/09/sorcerer_a_bett.html).
>>
>> 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 com.sun.tools.javac.tree 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