java APT(注释处理工具)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5032629/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
APT (Annotation Processing Tool)
提问by Nuwan Arambage
I was trying to find simple example to understand the usage of apt command, but I couldn't find a helpful resource for this.
我试图找到简单的例子来理解 apt 命令的用法,但我找不到有用的资源。
I have referred this Getting Started with the Annotation Processing Tool but I do get a high level understanding. Moreover I want to write a code to test apt command. Can somebody post a simple example or better link to refer?
我已经参考了注释处理工具入门,但我确实得到了高层次的理解。此外,我想编写一个代码来测试 apt 命令。有人可以发布一个简单的例子或更好的链接来参考吗?
回答by kschneid
Here's an example of creating a Note
annotation and associated processor:
这是创建Note
注释和关联处理器的示例:
APT: Compile-Time Annotation Processing with Java
Update. As of Java 1.7:
更新。从 Java 1.7 开始:
JSR 269, also known as the Language Model API, has two basic pieces: an API that models the Java programming language, and an API for writing annotation processors. This functionality is accessed through new options to the javac command; by including JSR 269 support, javac now acts analogously to the apt command in JDK 5.
JSR 269,也称为语言模型 API,有两个基本部分:一个为 Java 编程语言建模的 API,一个用于编写注释处理器的 API。此功能可通过 javac 命令的新选项访问;通过包含 JSR 269 支持,javac 现在的行为类似于 JDK 5 中的 apt 命令。
回答by Colin Pickard
The book "Core Java 2: Advanced features" has a section called The apt Tool for Source-Level Annotation Processingwhich might help you.
“Core Java 2: Advanced features”一书有一节叫做 The apt Tool for Source-Level Annotation Processing可能会对你有所帮助。
Update. As of Java 1.7:
更新。从 Java 1.7 开始:
JSR 269, also known as the Language Model API, has two basic pieces: an API that models the Java programming language, and an API for writing annotation processors. This functionality is accessed through new options to the javac command; by including JSR 269 support, javac now acts analogously to the apt command in JDK 5.
JSR 269,也称为语言模型 API,有两个基本部分:一个为 Java 编程语言建模的 API,一个用于编写注释处理器的 API。此功能可通过 javac 命令的新选项访问;通过包含 JSR 269 支持,javac 现在的行为类似于 JDK 5 中的 apt 命令。