There are two main goals of the annotation processing environment - analysis and code generation.
Analysis allows you to expand the capabilities of the java compiler by analyzing program elements as they are compiled, possibly adding additional restrictions, checks and error messages and warnings about violations of these restrictions.
Code generation allows you to generate additional additional code from signals in your existing handwritten code, mostly (though not exclusively) with annotations.
Some examples include Dagger , which is a system for analyzing dependencies at compile time, error messages and warnings that typically occur at runtime instead during compilation of code. The dagger also generates all the code that would normally be executed by reflection, or by manually writing a glue code that provides significant performance benefits (in some cases), as well as infrastructure code that is available for end-to-end debugging, etc.
Another example is the Checker Framework , which evaluates a lot of checks of your code, including zero security, etc.
The third Auto-Value example is designed to make small types of values ββalmost trivial to write.
One of the conditions for which the annotation processing environment is definitely not suitable is a mutation of the existing code in place or a change in the code that is currently in the process of compilation. Although some projects do this, they do not actually use the annotation processor APIs, but rather for internal compiler types. Although this is clearly possible, it is potentially fragile and may not work reliably from version to version or compiler to compiler, requiring special handling for each version and compiler provider.
source share