javapreprocessoraspectjcompile-time-weaving

AspectJ compile-time weaving - getting output source code?


Is there a way to get source files as a result of AspectJ compilation? So instead of getting bytecode, ajc works as a preprocessor that generates Java sources that can be compiled with javac?


Solution

  • Since version 1.2 AspectJ has been a bytecode transformer, not a source transformer. For any recent version you cannot get sources directly out of AspectJ. You could use a decompiler/disassembler to go from the compiled bytecode back to sources but those sources may not look pretty.

    You don't have to compile your aspects with the rest of your application code if that is your concern (i.e. that you want to build your app with javac)? You can compile your application with javac and then apply the aspects directly to the bytecode that javac produced in a binary weaving step.