After the source files have been parsed, and their symbols entered in the symbol table, the top level classes and some other items end up on JavaCompiler's "to do" list.
For each entry on the "to do" list, JavaCompiler
processes it as follows:
Some parts of the compilation involve modifying the parse tree, so a copy of the root of the tree is kept prior to such manipulation.
Note: this copy is just used to check whether the class is one of those found in a compilation unit on the command line (i.e. in rootClasses).
The top level classes are "attributed", using
Attr,
meaning that names and other elements within the parse tree are resolved
and associated with the corresponding types and symbols. Many semantic
errors may be detected here, either by Attr
, or by
Check.
While attributing the tree, class files will be read as necessary. In addition, if a class is required, and a source file for the class is found that is newer than the class file, the source file will be automatically parsed and put on the "to do" list. This is done by registering JavaCompiler as an implementation of Attr.SourceCompleter.
Note: there is a hidden option -attrparseonly
which can be used to skip
the rest of the processing for this file. In so doing, it "breaks" the
protocol use to save and restore the source file used to report error
messages (Log.useSource). There is a "try finally" block which
could reasonably be used/extended to restore the source file correctly.
If there are no errors so far, flow analysis will be done for the class, using Flow. Flow analysis is used to check for definite assignment to variables, and unreachable statements, which may result in additional errors.
Note: flow analysis can be suppressed with the hidden
option -relax
.
Lower
is defined to return a list of trees for the translated classes
and all the translated inner classes.Lower
returns a non-empty list, there is an assertion that
the list has a single element, in which case, code is generated, using
Gen,
and the resulting code is written out using
ClassWriter.
Note that Enter will have processed all other TopLevel putting the individual classes that it finds there on the "to do" (and not the TopLevel node itself.)
-stubs
option,
-s
option
Lower
is defined to return a list of trees for the translated classes
and all the translated inner classes.
Note: see also the use of Lower
earlier in the loop, when processing
TopLevel trees.
Lower
-printflat
option, the source of the class is printed.