How can I create an annotation processor that processes a Local Variable?

前端 未结 3 554
故里飘歌
故里飘歌 2020-12-10 15:28

I\'m trying to create an annotation for a local variable. I know that I can\'t retain the annotation in the generated bytecode, but I should be able to have access to the in

相关标签:
3条回答
  • 2020-12-10 15:56

    As of Java 8, local variable annotations are stored in the classfile.

    A standard Java annotation processor does not process the bodies of methods. However, the Checker Framework enables you to write an annotation processor that processes every annotation including on local variables. Its annotation processors can even examine every statement of the program, whether annotated or not.

    0 讨论(0)
  • 2020-12-10 16:06

    Did some quick tests and searched a little, and it's looking like hooking into LOCAL_VARIABLE isn't really supported...yet:

    http://forums.sun.com/thread.jspa?threadID=775449
    http://www.cs.rice.edu/~mgricken/research/laptjavac/
    https://checkerframework.org/jsr308/

    Could be totally wrong, but that's how it's looking...

    0 讨论(0)
  • 2020-12-10 16:13

    It seems that the Type Annotations Specification (JSR 308), will hopefully address this subject in the future (JDK 8 ?).

    0 讨论(0)
提交回复
热议问题