I would like to transform java source code at compile time just before passing the source code to the compiler. In other word I would like to create a preprocessor able to transform
"bla bla bla"
into any other code such as:
new MyClass("bla", 3)
My actual motivation is to do string encryption, as explained here
Some people suggest writing custom annotation processors but as far as I understand annotations:
- they can be used to generate new class file, but not to transform existing code before being passed to compiler
- they seem to work at package, class or method level, but not method body/implementation.
Some people suggest using frameworks like Spoon or ObjectsWeb ASM, but these frameworks seem complicated to learn and deploy on an existing code base.
I thrive to find a simple example of java code preprocessing for both approaches.
Does anybody see any smart way of doing code transform, without completely changing an existing large code base with multiple ivy module? Annotations seem to be the best way, but I don't understand how to do that.