如何创建处理局部变量的注释处理器? [英] How can I create an annotation processor that processes a Local Variable?

查看:21
本文介绍了如何创建处理局部变量的注释处理器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为局部变量创建注释.我知道我无法在生成的字节码中保留注释,但是我应该能够在编译时通过执行以下操作来访问信息:

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 information at compile time by doing something like this:

@Target({ElementType.LOCAL_VARIABLE})
@Retention(RetentionPolicy.SOURCE)
public @interface Junk {
  String value();
}

仅当我指定一个 ProcessorFactory 时,它不会被 apt 或 javac 处理,它的支持类型如下:

only, this doesn't get processed by apt, or javac when I specify a ProcessorFactory that has "Junk" in it's supported types in the following:

class JunkTester {
    public static void main(String[] args) {
        @Junk String tmp = "Hello World";
        System.out.println(tmp);
    }
}

然而,当我在 public static

想法和/或解决方法?

推荐答案

进行了一些快速测试并进行了一些搜索,看起来似乎还没有真正支持挂钩 LOCAL_VARIABLE ......

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...

这篇关于如何创建处理局部变量的注释处理器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆