general purpose Java code generator library?
807580Nov 5 2009 — edited Jun 25 2010Is anyone aware of an open source Java code generator library? What I'm looking for is something that will let me write a program which builds up an abstract syntax tree in memory representing one or more classes, and then write it out as valid Java 1.6 source code files.
I have had to write code generators for several projects recently and just slapped them together as quick hacks, writing text out line by line. This works but it's messy and hard to maintain. So I figured there must be a better way.
The open source code generators I have found so far are either designed to be driven by a data model, or produce byte code instead of source code. But in my case there is really no data model (at least not for the generated code) and I want plain text source code that can be viewed and compiled along with everything else.
If nothing like that exists then I may try to build it myself. The Sun JDK includes a com.sun.source.tree package representing the source code AST object model so I could at least use that as a starting point.