this.fieldName = fieldName;
}
@Override
public void handleCall(final CallWriter writer, final Context context, Statement statement) {
final MetaField field;
if (fieldName.equals("this")) {
// TODO this is a workaround to access the enclosing instance of a type
field = new BuildMetaField(null, null, Scope.Private, statement.getType(), "this");
}
else {
field = statement.getType().getDeclaredField(fieldName);
}
if (field == null) {
throw new UndefinedFieldException(fieldName, statement.getType());
}
final String currCallString = writer.getCallString();
writer.reset();
statement = new VariableReference() {
@Override
public String getName() {
return field.getName();
}
@Override
public Statement getValue() {
return null;
}
@Override
public String generate(Context context) {
return currCallString + "." + getName();
}
@Override
public MetaClass getType() {
return field.getType();
}
};
nextOrReturn(writer, context, statement);
}