Annotation Processor - How to get the Class it is processing

来源:互联网 发布:杭州海关大数据 编辑:程序博客网 时间:2024/04/28 09:27

You are unable to access the Class the Annotation Processor is processing because the Class has not been compiled yet. Instead Java offers the analogous Elements api for reflection-style inspection of the input source.

The Element (which you found by using roundEnv.getRootElements()) has much more information about the class being compiled than just its name. A ton of useful information can be found by using the ElementVisitors:


http://stackoverflow.com/questions/18034626/annotation-processor-how-to-get-the-class-it-is-processing


自己出现的问题跟这个差不多,想访问Annotation Processor生成的java文件中的类。

最后解决办法:就是生成类中必须实现某个接口,而这个接口本身是已经存在的。然后调用这个接口就可以实现了。

0 0
原创粉丝点击