我怎样才能创建注释处理器,处理一个局部变量? [英] How can I create an annotation processor that processes a Local Variable?
问题描述
我试图创造一个局部变量的注释。我知道我不能保留在生成的字节code中的注释,但我应该可以做这样的事情有机会获得在编译时的信息:
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();
}
只是,这并不能得到由易处理,或者javac的时候我指定它支持在以下类型有垃圾一ProcessorFactory:
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);
}
}
在我之前移动@Junk标注,它还是会正常工作公共静态
It will however work when I move the @Junk annotation before 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:
<一个href=\"http://forums.sun.com/thread.jspa?threadID=775449\">http://forums.sun.com/thread.jspa?threadID=775449
<一href=\"http://www.cs.rice.edu/~mgricken/research/laptjavac/\">http://www.cs.rice.edu/~mgricken/research/laptjavac/
http://types.cs.washington.edu/jsr308/
可能是完全错误的,但这是它是如何寻找...
Could be totally wrong, but that's how it's looking...
这篇关于我怎样才能创建注释处理器,处理一个局部变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!