Java Reference
In-Depth Information
((JTypeDecl)
typeDeclaration).preAnalyze(context);
}
}
4.4.3
JClassDeclaration.preAnalyze()
In a class declaration,
preAnalyze()
does the following:
1. It rst creates a new
ClassContext
, whose
surroundingContext
points to the
CompilationUnitContext
.
2. It resolves the class's super type.
3. It creates a new
CLEmitter
instance, which will eventually be converted to the
Class
object for representing the declared class.
4. It adds a class header, defining a name and any modifiers, to this
CLEmitter
instance.
5. It recursively invokes
preAnalyze()
on each of the class' members. This causes eld
declarations, constructors, and method declarations (but with empty bodies) to be
added to the
CLEmitter
instance.
6. If there is no explicit constructor (having no arguments) in the set of members, it adds
the implicit constructor to the
CLEmitter
instance. For example, for the
Factorial
program above, the following implicit constructor is added, even though it is never
used in the
Factorial
program:
publicFactorial(){
super.Factorial();
}
7. Finally, the
CLEmitter
instance produces a
Class
object, and that replaces the
classRep
for the
Type
of the declared class name in the (parent)
ClassContext
.
Notice that this pass need not descend into method bodies. If j--, like full Java, supported
nested classes, then
preAnalyze()
would have to examine all of the statements of every
method body to see if it were a nested class needing pre-analysis.
The code for
JClassDeclaration
's
preAnalyze()
is as follows:
publicvoidpreAnalyze(Contextcontext){
//Constructaclasscontext
this.context=newClassContext(this,context);
//Resolvesuperclass
superType=superType.resolve(this.context);
//Creatingapartialclassinmemorycanresultina
//java.lang.VerifyErrorifthesemanticsbeloware
//violated,sowecan'tdeferthesecheckstoanalyze()
thisType.checkAccess(line,superType);
if(superType.isFinal()){
JAST.compilationUnit.reportSemanticError(line,
"Cannotextendafinaltype:%s",
superType.toString());
}
//Createthe(partial)class
Search WWH ::
Custom Search