visitReference(that);
}
}
private void visitReference(Tree.Primary that) {
Declaration member;
boolean assigned;
boolean metamodel;
if (that instanceof Tree.MemberOrTypeExpression) {
Tree.MemberOrTypeExpression mte =
(Tree.MemberOrTypeExpression) that;
member = mte.getDeclaration();
assigned = mte.getAssigned();
metamodel = false;
}
else if (that instanceof Tree.MetaLiteral) {
Tree.MetaLiteral ml = (Tree.MetaLiteral) that;
member = ml.getDeclaration();
assigned = false;
metamodel = true;
}
else {
return;
}
//Declaration member = getDeclaration(that.getScope(), that.getUnit(), id, context);
//TODO: check superclass members are not in declaration section!
if (member==declaration &&
member.isDefinedInScope(that.getScope())) {
if (!declared) {
//you are allowed to refer to later
//declarations in a class declaration
//section or interface
if (withinAttributeInitializer &&
member instanceof Value &&
!(((Value) member).isTransient())) {
that.addError("reference to value within its initializer: '" +
member.getName() + "'", 1460);
}
else if (!metamodel && !isForwardReferenceable() && !hasParameter) {
if (declaration.getContainer() instanceof Class) {
that.addError("forward reference to class member in initializer: '" +
member.getName() +
"' is not yet declared (forward references must occur in declaration section)");
}
else {
that.addError("forward reference to local declaration: '" +
member.getName() + "' is not yet declared");
}
}
}
else if (!specified.definitely ||
declaration.isFormal()) {
//you are allowed to refer to formal
//declarations in a class declaration
//section or interface
if (declaration.isFormal()) {
if (!isForwardReferenceable()) {
that.addError("formal member may not be used in initializer: '" +
member.getName() + "'");
}
}
else if (!declaration.isNative() && !metamodel) {
if (!isLate() || !isForwardReferenceable()) {
if (isVariable()) {
that.addError("not definitely initialized: '" +
member.getName() + "'");
}
else {
that.addError("not definitely specified: '" +
member.getName() + "'");
}
}
}
}
if (!assigned && member.isDefault() &&
!isForwardReferenceable()) {
that.addError("default member may not be used in initializer: '" +
member.getName() + "'");
}
if (inAnonFunctionOrComprehension &&
specified.definitely &&
isVariable()) {
that.addError("variable member may not be captured by comprehension or function in extends clause: '"+
member.getName() + "'");
}
}
}