简体   繁体   English

注释处理器以添加方法调用

[英]Annotation Processor to add a method call

I am writing an annotation processor, and I need TreeTranslator.visitIdent to place a static method call. 我正在编写注释处理器,并且需要TreeTranslator.visitIdent放置静态方法调用。 I think I should use TreeMaker.Call , or TreeMaker.Create , or should I use JCMethodInvocation? 我想应该使用TreeMaker.CallTreeMaker.Create ,还是应该使用JCMethodInvocation? I couldn't find any example of how to use it. 我找不到如何使用它的任何示例。 Can anybody help me with that? 有人可以帮我吗?

At the time your annotation processor is running, the class being inspected exists in source form only. 在注释处理器运行时,要检查的类仅以源形式存在。 Thus you can't call methods on it. 因此,您无法在其上调用方法。

Also, Annotation Processors can't directly modify the class being compiled. 同样,注释处理器不能直接修改正在编译的类。 Instead, you should create a new class: 相反,您应该创建一个新类:

Filer filer = env.getFiler();
PrintWriter pw = filer.createSourceFile("com.example.MyClass");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM