Using the com/sun/tools/javac APIs
Erik van Zijst
erik.van.zijst at gmail.com
Wed Feb 17 22:50:13 PST 2010
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