The default implementation is to get the value from the annotation, SupportedOptions, and the value is a character array, such as: class SzzTestProcessor extends AbstractProcessor /generated-sources/Īnnotation and annotation processor are separate modules. This is the core abstract class of the annotation processor. Determine whether all annotation processors have completed execution, and if not, continue with the annotation processing with the next annotation processor (return to step 1).Generate the corresponding class and write it to the file.Loop through the annotation element to find the class, method, or attribute that was modified by the annotation.The compiler starts executing the unexecuted annotation processor. Build an annotation processor in the Java compiler.The Processing Steps of Annotation Processor This process continues until no new files are generated during the processing phase. If any files are generated during this process, another round will begin with the generated files as input. Each annotation processor is called on the corresponding source in turn. Each round starts with the compiler searching for annotations in the source file and selecting the appropriate annotation processor (AbstractProcessor) for those annotations. The annotation processing process requires multiple rounds to complete. AbstractProcessor helps us write most of the processes, so we only need to implement this abstract class to define an annotation processor. All the logic we need to process annotations at compile time needs to implement this Processor interface. One of the most critical classes in the annotation processing flow at compile time is the Processor, which is the interface of the annotation processor. How do these compile-time annotations work? How do they automatically generate code? Annotation Processor Annotation Processing Flow Most of the annotations we usually use are annotations at runtime, such as and compile-time annotations we usually use include and compile-time annotations are used to automatically generate code, thus improving coding efficiency and avoiding heavy use of Reflection at runtime by using Reflection at compile time to generate auxiliary classes and methods for use at runtime.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |