sciencething.org

Home

GeekThings

What's This?

JavaAST is a library that allows you to parse java source files into an abstract syntax tree, manipulate or create java abstract syntax trees, and generate java source files from an abstract syntax tree. The parser was generated by javacc, included in this distribution, and the Java 1.5 grammar by Sreenivasa Viswanadha.

The distribution comes as a Netbeans project but also includes a simple ant build file, package.xml, that builds a zip file distribution containing the jar and the javadocs.

This should be considered alpha software. It has been tested to the extent that it can parse and regurgitate all the java source I've tried it on so far, including a god many codelines which use most if not all Java 1.5 features. The convenience constructors, and factory methods for building java from scratch have had no testing yet.

The abstract syntax tree generated by JavaAST is designed to be dead simple in pattern. There are no visitors, as I consider visitors highly overrated and mostly just pointless obfuscation. Each node in the syntax tree is a struct, with public member variables. Encapsulation is usually a good thing, but in this case would make working with ASTs awkward and long winded.

JavaAST has no licence. You may do with it what you will. Needless to say, I am not responsible for any damage from use of this software either direct or indirect. It is offered with no warrantee. All that being said I hope that it useful, and will endeavor to repair any bugs pointed out to me.

I'd be delighted to receive comments, bug reports, bug fixes and can be reached at britt@sciencething.org

December 31, 2006

What's New:

All nodes in the AST now implement clone(). This is useful for parsing a source file and processing it in more than one way in the same program.

A subset of comments are now captured. More will follow, but JavaAST will never capture all comments.

January 2, 2007