In another post (Scala, Maven, and preprocessors) I asked about preprocessing Java and Scala using a tool like m4. I need to add __FILE__ and __LINE__ capabilities (please, no “use cases” questions). Someone suggested checking out Java compiler plugins (javax.annotation.processing.Processor).
How would one go about doing this using special annotations (@File, @Line, or @FileLine maybe)? Any examples similar to this would be greatly appreciated.
In a comment on your previous question you mentioned http://www.gallot.be/?p=85, which uses a javaagent. It should be relatively easy to modify that code to run the same transformation in a preprocessing step. You would need to extract the
CodeLocationClassAdapterinto its own toplevel class and call it like this for each of your class files: