Is it possible to use a bytecode manipulation library like ASM at compile time?
Specifically, I'd like to use Java's annotation processing API to implement boilerplate-heavy methods on annotated classes. Implementing an annotation processor is straightforward enough, but it seems like the .class
files don't yet exist when the Processor
is run. Is there another way?
You might be interested in Javassist ( http://www.jboss.org/javassist ) which can enhance and save classes as a post-compilation step.
This article describes how to save enhanced classes : https://dzone.com/articles/implementing-build-time
in particular, once you have altered a class, you can do something like this:
compiledClass.writeFile("/tmp/modifiedClassesFolder");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With