Using the com/sun/tools/javac APIs
Mark Lawrence
breamoreboy at yahoo.co.uk
Wed Feb 24 07:02:09 PST 2010
Sorry to butt in, but I'm looking at using these APIs and have just come
across this and thought it might give us all some pointers.
http://code.google.com/p/smart-codegen/
Regards.
Mark Lawrence
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