Accessing source code from Java Annotation Processor

后端 未结 5 1338
悲哀的现实
悲哀的现实 2020-12-04 22:38

I am trying to access the actual original source code of a type from within a Java Annotation Processor. Is this possible somehow? Thanks!

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-04 23:06

    Quick answer is that it's not possible.

    From the Mirror API JavaDoc used in Annotation Processing in Sun's SDK 5:

    The Mirror API is used to model the semantic structure of a program. It provides representations of the entities declared in a program, such as classes, methods, and fields. Constructs below the method level, such as individual statements and expressions, are not represented.

    Java 6 Annotation Processing is based on a new API, but it still doesn't provide any more detail about the code structure.

提交回复
热议问题