Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the default annotation processors discovery process?

The documentation of Maven Compiler plugin mentions the following:

annotationProcessors:

Names of annotation processors to run. Only applies to JDK 1.6+ If not set, the default annotation processors discovery process applies.

What is the default annotation processors discovery process here? Is there any other way to set up annotation processors than this configuration tag?

I've found that the Getting Started with the Annotation Processing Tool (apt) documentation mentions a default discovery procedure, but it works with factory classes not processors and unfortunately it uses the tools.jar and com.sun packages from the JDK. Is this the default annotation processors discovery process?

like image 728
palacsint Avatar asked Jul 27 '12 09:07

palacsint


People also ask

What is the annotation process?

Annotations provide information to a program at compile time or at runtime based on which the program can take further action. An annotation processor processes these annotations at compile time or runtime to provide functionality such as code generation, error checking, etc.

How do annotation processors work?

As we briefly mentioned, annotations processors are typically used to inspect the codebase against the presence of particular annotations and, depending on use case, to: generate a set of source or resource files. mutate (modify) the existing source code. analyze the exiting source code and generate diagnostic messages.

What is annotation processing in Intellij?

The process of generating code at compile time to handle the annotations is called Annotation Processing. The annotation processor can validate, generate, and modify your code based on the annotations, which help you significantly reduce the amount of code you need to write.


1 Answers

The default way to make an annotation processor available to the compiler is to register it in a file in META-INF/services/javax.annotation.processing.Processor. The file can contain a number of processors: each the fully-qualified class name on its own line, with a newline at the end. The compiler will default to using processors found in this way if none are specified.

like image 53
Daniel Avatar answered Oct 17 '22 06:10

Daniel