I'm looking for a framework to generate Java source files.
Something like the following API:
X clazz = Something.createClass("package name", "class name");
clazz.addSuperInterface("interface name");
clazz.addMethod("method name", returnType, argumentTypes, ...);
File targetDir = ...;
clazz.generate(targetDir);
Then, a java source file sould be found in a subdirectory of the target directory.
Does anyone know such a framework?
EDIT:
- I really need the source files.
- I also would like to fill out the code of the methods.
- I'm looking for a high-level abstraction, not direct bytecode manipulation/generation.
- I also need the "structure of the class" in a tree of objects.
- The problem domain is general: to generate a large amount of very different classes, without a "common structure".
SOLUTIONS
I have posted 2 answers based in your answers... with CodeModel and with Eclipse JDT.
I have used CodeModel in my solution, :-)