I have had some success using ASM to modify existing classes at the bytecode level or to generate completely new classes on the fly. The tutorial lets you understand this in a very understandable way.
ASM , like most of these tools, generates bytecode, not the source. The reason for this is because you want to dynamically generate and execute new code using a program, historically there has not been a direct call to the Java compiler. Therefore, it was easier to generate and use bytecode than the original one.
If you need to generate and run the code immediately in your program, I recommend using the bytecode manipulation tool. If you only need a Java source, I would generate my own code generator that accepts my input format and generates code. You may want to find a framework to help you with this, but since the source file is just text, it is usually just as easy to create it especially if you have a custom input format.
Tendayi mawushe
source share