My Google foo is failing me. If I have some framework that can do code generation based on annotations, and I would like to support both build-time source code generation, so that the developer can compile it in advance, also see what gets generated, and possibly even modify the code, but also offer runtime bytecode generation for more dynamic apps, for example plugin-based apps, can I use ASM for both tasks, or do I really need to program this twice, with two different libraries? If it is possible, a link to an example would be welcome.
Share
Whilst this doesn’t directly answer the question, I recommend using Javassist over ASM.
With Javassist you start out by generating the source code and you simply give it to the Javassist compiler to turn into bytecode, so you now have both available without any extra tricks. Plus, IMHO, generating source code for Javassist is MUCH easier than messing around with bytecode and ASM.