Java Reference
In-Depth Information
if(targetinstanceofJVariable&&
((JVariable)target).iDefn()instanceof
TypeNameDefn){
JAST.compilationUnit.
reportSemanticError(line(),
"Non-staticfield"+fieldName+
"cannotbereferencedfromastatic
context");
}
}
}
}
returnthis;
}
After
reclassifying
any
ambiguous
part
and
making
that
the
target,
analysis
of
a
JFieldSelection
proceeds as follows:
1. It analyzes the target and determines the target's type.
2. It then considers the special case where the target is an array and the field is
length
.
In this case, the type of the \eld selection" is
Type.INT
5
.
3. Otherwise, it ensures that the target is not a primitive and determines whether or not
it can nd a eld of the appropriate name in the target's type. If it cannot, then an
error is reported.
4. Otherwise, it checks to make sure the field is accessible to this region, a non-static field
is not referenced from a static context, and then returns the analyzed field selection
sub-tree.
Analyzing messages expressions is similar, but with the added complication of argu-
ments.
Analyzing a Message Expression
After reclassifying any
AmbiguousName
, analyzing a
JMessageExpression
proceeds as fol-
lows.
1. It analyzes the arguments to the message and constructs an array of their types.
2. It determines the surrounding, defining class (for determining access).
3. It analyzes the target to which the message is being sent.
4. It takes the message name and the array of argument types and looks for a matching
method dened in the target's type. In j--, argument types must match exactly. If no
such method is found, it reports an error.
5. Otherwise, the target class and method are checked for accessibility, a non-static
method is now allowed to be referenced from a static context, and the method's
return type becomes the type of the message expression.
publicJExpressionanalyze(Contextcontext){
//Reclassifytheambiguouspart
5
This is a Java language hack;
length
is not really a field but an operation on arrays.
Search WWH ::
Custom Search