Helping to find the usefulness of a proposal
Mark Mahieu
markmahieu at googlemail.com
Thu Apr 2 06:47:26 PDT 2009
Yep, which is a better option if the code is going to be more than a quick
throwaway.
The advantage with using the javac versions of those types is that you get
familiarity with other APIs you need to interact with when building an
actual prototype...
Mark
2009/4/2 Michael Nascimento <misterm at gmail.com>
> Using JDK 6, you can write an annotation processor for all sources
> that uses the Tree API for that.
>
> Regards,
> Michael Nascimento Santos
> https://genesis.dev.java.net/
> https://jsr-310.dev.java.net/
>
> On Thu, Apr 2, 2009 at 10:25 AM, Mark Mahieu <markmahieu at googlemail.com>
> wrote:
> > Wow.
> >
> >
> http://www.geekherocomic.com/comics-highres/2009-02-25-coding-overkill.png
> >
> >
> > Here are the important bits from my quick hack. Took under half an hour
> to
> > get it finding cases where Auto-assignment Parameters would and wouldn't
> > work across large source trees.
> >
> > Of course, javac makes much more than parsing available if you need it...
> >
> >
> >
> > import com.sun.tools.javac.file.JavacFileManager;
> > import com.sun.tools.javac.parser.JavacParser;
> > import com.sun.tools.javac.parser.ParserFactory;
> > import com.sun.tools.javac.tree.TreeScanner;
> > import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
> > import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
> > import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
> > import com.sun.tools.javac.util.Context;
> > import com.sun.tools.javac.util.List;
> >
> > ...
> >
> > // create a TreeScanner to do your analysis
> > TreeScanner scanner = new TreeScanner() {
> >
> > @Override
> > public void visitMethodDef(JCMethodDecl tree) {
> > // look at a method's parameters
> > for (List<JCVariableDecl> l = params; l.nonEmpty(); l = l.tail) {
> > JCVariableDecl param = l.head;
> > // examine param or whatever
> > }
> > // continue recursively scanning the method body etc
> > super.visitMethodDef(tree);
> > }
> > };
> >
> > ...
> >
> > Context context = new Context();
> > JavacFileManager.preRegister(context);
> > ParserFactory factory = ParserFactory.instance(context);
> >
> > String sourceCode = readSourceFromFile(...);
> >
> > JavacParser parser = (JavacParser) factory.newParser(sourceCode, false,
> > false, false);
> > JCCompilationUnit cu = parser.parseCompilationUnit();
> >
> > // do your analysis
> > scanner.scan(cu);
> >
> >
>
>
More information about the coin-dev
mailing list