可以注解处理器可用于code一代? [英] Can annotation processor be used for code generation?

查看:118
本文介绍了可以注解处理器可用于code一代?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我定义名为注释 @MyAnnotation

Let's say I define an annotation called @MyAnnotation.

有一类 X 被声明为:

@MyAnnotation
class X { .... }

现在在编译时我要检查与 @MyAnnotation 注释的所有类,并做一些code一代需要进行以及编译更多的Java源文件在相同的处理。

Now at compile time I want to inspect all classes annotated with @MyAnnotation and do some code generation to more java source files that need to be compiled as well in the same process.

这可能使用Java注释处理器或其它工具?

Is this possible using java annotation processor or some other tool?

推荐答案

您可以看看在Java APT(注释处理工具)这样的事情。

You may take a look at the Java apt (Annotation Processing Tool) for such a thing.

您可以找到入门页面,和一个不错的文章( 1 ,的 2 ,的 3 )关于如何用它来生成code。

You can find the Getting Started page, and a nice article (1, 2, 3) about how to use that to generate code.

这篇关于可以注解处理器可用于code一代?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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