if (owner == null && pathList != null) {
// factor off a typename from the path
TypeGroup typeGroup = getTypeGroup();
Type rootType = typeGroup.match(pathList);
if (rootType == null) {
throw new TypeException("FieldExpression.typeCheck : invalid path " + getPath(pathList.length) + " to static field " + fieldName + getPos());
}
// find out how many of the path elements are included in the type name
String rootTypeName = rootType.getName();
int idx = getPathCount(rootTypeName);
if (idx < pathList.length) {
// create a static field reference using the type name and the first field name and wrap it with
// enough field references to use up all the path
String fieldName = pathList[idx++];
Expression owner = new StaticExpression(rule, Type.UNDEFINED, token, fieldName, rootTypeName);
while (idx < pathList.length) {
owner = new FieldExpression(rule, Type.UNDEFINED, token, pathList[idx++], owner, null);
}
this.owner = owner;
// not strictly necessary?
this.owner.bind();
} else {
// ok this field reference is actually a static reference -- install the one we just created as
// owner and mark this one so it sidesteps any further requests to the owner
this.indirectStatic = new StaticExpression(rule, Type.UNDEFINED, token, this.fieldName, rootTypeName);
// not strictly necessary?
this.indirectStatic.bind();
}
// get rid of the path list now
this.pathList = null;
}
if (indirectStatic != null) {
// this is really a static field reference pointed to by owner so get it to type check
type = Type.dereference(indirectStatic.typeCheck(expected));
return type;
} else {
// ok, type check the owner and then use it to derive the field type
ownerType = Type.dereference(owner.typeCheck(Type.UNDEFINED));
if (ownerType.isUndefined()) {
throw new TypeException("FieldExpresssion.typeCheck : unbound owner type for field " + fieldName + getPos());
}
Class ownerClazz = ownerType.getTargetClass();
Class valueClass = null;
try {
field = lookupField(ownerClazz);
} catch (NoSuchFieldException e) {
throw new TypeException("FieldExpresssion.typeCheck : invalid field reference " + fieldName + getPos());
}
if ((field.getModifiers() & Modifier.STATIC) != 0) {
throw new TypeException("FieldExpresssion.typeCheck : field is static " + fieldName + getPos());
}
valueClass = field.getType();
type = getTypeGroup().ensureType(valueClass);
if (Type.dereference(expected).isDefined() && !expected.isAssignableFrom(type)) {
throw new TypeException("FieldExpresssion.typeCheck : invalid expected type " + expected.getName() + getPos());
}
return type;
}
}