Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

APT (Annotation Processing Tool)

I was trying to find simple example to understand the usage of apt command, but I couldn't find a helpful resource for this.

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?

like image 724
Nuwan Arambage Avatar asked Feb 17 '11 17:02

Nuwan Arambage


People also ask

What is annotation processing tool?

Annotation processing is a tool built into javac for scanning and processing annotations at compile time. It can create new source files; however, it can't modify existing ones. It's done in rounds. The first round starts when the compilation reaches the pre-compile phase.

How do I run an annotation Processor?

Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processors -> Enable Annotation Processing.

What is process annotation?

"Annotation Processing" is a hook into the compile process of the java compiler, to analyse the source code for user defined annotations and handle then (by producing compiler errors, compiler warning, emitting source code, byte code ...).

What is gradle annotation Processor?

An annotation processor is a class which extends AbstractProcessor (in the package javax. annotation. processing ) providing the functionality needed to generate whatever it needs to generate, such as classes in the case of mapstruct.


2 Answers

Here's an example of creating a Note annotation and associated processor:

APT: Compile-Time Annotation Processing with Java

Update. As of 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.

like image 124
kschneid Avatar answered Sep 30 '22 05:09

kschneid


The book "Core Java 2: Advanced features" has a section called The apt Tool for Source-Level Annotation Processing which might help you.

Update. As of 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.

like image 21
Colin Pickard Avatar answered Sep 30 '22 05:09

Colin Pickard