The JVM Specification defines the format of the class file but does not.Source codeHow to compile it as a class file, so major vendors compile it as a class file in compliance with the specifications when implementing JDK. The following uses Sun JDK for analysis.
The basic process is as follows:
{Java source file} ------- >{analyze and inject to the symbol table (parse and enter)} ------ >{annotation processing )} ---------> {Semantic Analysis and generation of class files (analyse and generate)} --> {0101}
The following describes the processes:
1. Analyze and inject to the symbol table
The analysis process mainly involves lexical and syntax analysis.
The injection process mainly involves inputting the symbol table into the symbol table ., Generally, this includes super classes and interfaces of the class. You can add the default constructor as needed to input the symbols in the class to your own symbol table.
2. Watching
It mainly processes users' own annotation, which may bring about the benefit of generating additional annotations Based on annotation.CodeOr perform some special processing to save some code writing, such as writing the get and set methods. The compilation will be automatically generated after compilation through annotations.
3. Semantic Analysis and generation of class files
It is mainly used to associate elements such as names and expressions with variables, methods, types, and so on. It checks whether the variables have been declared before use, and whether they are generic and type-matched, check that all statements can be reached, and the checked exceptions must be caught or thrown. check whether there is a return value to determine whether there is a return value. Check that the variables do not assign values repeatedly and retrieve useless Code such: if (false ){//....}, there are also generic conversion to common Java types, as well as automatic unpacking and packing conversion. Finally, the class file is generated.