Java Reference
In-Depth Information
we encapsulate it within our own locally defined Field . More interface for querying a Type
about its members is implemented, delegating the reflection to the underlying Class object
that is kept in the Type 's classRep field.
The Class objects are created for declared classes in the preAnalyze() phase and are
queried during the analyze() phase. This is made possible by the CLEmitter 's ability to
create partial class les|class les that dene the headers for methods (but not the bodies)
and the types of fields (but not their initializations). These analysis issues are discussed in
the next two sections.
4.4 Pre-Analysis ofj--Programs
4.4.1 An Introduction to Pre-Analysis
The semantic analysis of j-- (and Java) programs requires two traversals of the AST because
a class name or a member name may be referenced before it is declared in the source
program. The traversals are accomplished by methods (the method preAnalyze() for the
first traversal and the method analyze() for the second), that invoke themselves at the
child nodes for recursively descending the AST to its leaves.
But the first traversal need not traverse the AST as deeply as the second traversal. The
only names that may be referred to before they are declared are type names (that is, class
names in j--) and members.
So preAnalyze() must traverse down the AST only far enough for
Declaring imported type names,
Declaring user-defined class names,
Declaring fields,
Declaring methods (including their signatures the types of their parameters).
For this reason, preAnalyze() need be defined only in the following types of AST nodes:
JCompilationUnit
JClassDeclaration
JFieldDeclaration
JMethodDeclaration
JConstructorDeclaration
So the preAnalyze() phase descends recursively down the AST only as far as the member
declarations, but not into the bodies of methods 3 .
3 Implementing nested classes would require recursing more deeply.
 
Search WWH ::




Custom Search