Search

Categories

Links

Referers

Tree API project created on java.net

Sep 19 2005, 12:03:56 AM PDT »Java»Compiler Comments [8]
I have created a Tree API project on java.net.

The Tree API exposes javac's abstract syntax trees through a set of public interfaces. We hope to include this in Mustang in due time.

UPDATE: The exact procedure to get access to the Tree API is as follows:

  1. Go to https://jdk.dev.java.net/
  2. Request the jdk.researcher role on the Membership Request page.
  3. Wait for approval.

You now have access to all the projects under jdk-research including the Tree API.

Post a Comment:
Comments are closed for this entry.
Comments:

Peter, Would it be possible to include Pretty.java or similar serializer in public API? It would help enormously to people who want to manipulate syntax tree and need to serialize it back to text. Thank you Alex

Posted by Alex Roytman on September 22, 2005 at 09:37 PM PDT #

Currently, that's what toString does. We are definitely planning to add a number of utility methods and visitors. But I'm not making any promises yet. However, tree manipulation will not be supported in Mustang. All interfaces are for immutable tree nodes. Javac will not be able to deal with mutated trees and we don't believe it is a good way to rewrite source code. This is why the Jackpot project use a different technique. For more information on the Jackpot project, see: http://weblogs.java.net/blog/tball/archive/2005/06/project_jackpot.html

Posted by Peter von der Ahé on September 22, 2005 at 10:21 PM PDT #

Haven't got the permissions yet to have a look at the Tree API. But just a question on classname resolution... Would that be handled by the Tree itself or would developer intervention be required. For example, if (I'm making assumptions here about the API ;) I were to do: Compiler c = CompilerFactory.getInstance ("javac"); c.parse ("MyClass.java", classpath); CompileTree tree = c.getTree (); Would the classes for all references be resolved by the time I call "getTree" or would I have to resolve them myself? Whilst it wouldn't be the end of the world to have to do it, reference resolution can be tedious, but vital for my purposes ;) Gary

Posted by Gary Bentley on September 25, 2005 at 05:32 PM PDT #

The Tree API will be accessible from JSR 199 implementation classes. The extra API is not a part of JSR 199, however, JSR 199 allows you to get hold of a compiler. The javac implementation of JSR 199 has a few extra methods for parsing and other compiler phases. So resolution will be handled by javac.

Posted by Peter von der Ahé on September 25, 2005 at 05:44 PM PDT #

Will you have to compile the java code as well or will it be possible to just parse it into an AST (although "real" types would be better)? I don't actually have any need to compile the code (in fact compilation may not be desirable) just to be able to access the symbol tree and get the required references. Thanks, Gary

Posted by Gary Bentley on September 25, 2005 at 06:30 PM PDT #

The compiler has several phases, including parser. These phases will be exposed.

Posted by Peter von der Ahé on September 25, 2005 at 06:34 PM PDT #

Peter, If the Tree API is accessible from JSR 199 implementation classes, does this mean that all implementation of the JSR 199 has to be able to provide a tree? Could you please describe how this will be accessible from JSR 199 classes? Thank you.

Posted by Olivier Thomann on October 05, 2005 at 07:26 AM PDT #

JSR 199 has an interface called javax.tools.JavaCompilerTool.CompilationTask.

The javac implementation of this interface has extra methods. So if you know that your JSR 199 implementation is javac, you can cast the CompilationTask to an abstract class with additional methods.

Posted by Peter von der Ahé on October 05, 2005 at 07:44 AM PDT #

Java is a trademark of Sun Microsystems, Inc.
Copyright © 2006,2007 Peter von der Ahé