1 Reply Latest reply: Jul 10, 2009 6:06 PM by 843793 RSS

    Compile time Annotation Processing

    843793
      Is it possible to access the source of the file being analysed at compile time?

      Thanks
        • 1. Re: Compile time Annotation Processing
          843793
          Milesy wrote:
          Is it possible to access the source of the file being analysed at compile time?
          If you are naughty, you can try to find the file being processed and read it directly, but that is not supported.

          You can use the javac-specific tree API (http://java.sun.com/javase/6/docs/jdk/api/javac/tree/index.html) to map from a javax.lang.model.Element to a AST representing the source for a method or constructor.

          If you want the source for the purposes of modifying it, the annotation processing API is read-only, but much of the effect of mutating the source can be achieved by generating subclasses or the superclass of the class in question. Check the forum archives for details.