Programmatically constructing Java code?
<p>I am working on a module where I have to convert a set of logical representations and other data into Java source code. </p>

<p>I would like to be able to first convert them to an intermediary representation of Java elements (classes, methods, etc), and then convert this intermediary representation to an actual String/textfile.</p>

<p>for example, I would like to just be able to construct an element like this:</p>

<pre><code>JavaClass myClass = new JavaClass("MyClass", "MyParent", new String[] {"MyInterface", "MySecondInterface"});
</code></pre>

<p>and then have the toString() method of myClass output something like:</p>

<pre><code>class MyClass extends MyParent implements MyInterface, MySecondInterface { }
</code></pre>

<p>and so on and so forth for variables, methods, statements etc - preferably with formatting. The example is oversimplified just for the sake of demonstration - in reality I would prefer a representation that at least resembles an abstract syntax tree.</p>

<p>I have looked at the com.sun.org.apache.bcel.* package, but since it is meant for bytecode it does not help much here. Transformation frameworks (such as Recoder) also do not seem to be what I am looking for.</p>

<p>Can anyone recommend a framework I can use for this? </p>
