Expression receiver = createFieldHelperReceiver();
if (fn.isStatic()) {
receiver = new PropertyExpression(receiver, "class");
}
String method = Traits.helperSetterName(fn);
MethodCallExpression mce = new MethodCallExpression(
receiver,
method,
new ArgumentListExpression(super.transform(rightExpression))
);
mce.setSourcePosition(exp);
mce.setImplicitThis(false);
return mce;
}
}
Expression leftTransform = transform(leftExpression);
Expression rightTransform = transform(rightExpression);
Expression ret =
exp instanceof DeclarationExpression ?new DeclarationExpression(
leftTransform, operation, rightTransform
):
new BinaryExpression(leftTransform, operation, rightTransform);
ret.setSourcePosition(exp);
ret.copyNodeMetaData(exp);
return ret;
} else if (exp instanceof StaticMethodCallExpression) {
StaticMethodCallExpression call = (StaticMethodCallExpression) exp;
ClassNode ownerType = call.getOwnerType();
if (traitClass.equals(ownerType)) {
MethodCallExpression result = new MethodCallExpression(
new VariableExpression(weaved),
call.getMethod(),
transform(call.getArguments())
);
result.setSafe(false);
result.setImplicitThis(false);
result.setSpreadSafe(false);
result.setSourcePosition(call);
return result;
}
} else if (exp instanceof MethodCallExpression) {
MethodCallExpression call = (MethodCallExpression) exp;
Expression obj = call.getObjectExpression();
if (call.isImplicitThis() || "this".equals(obj.getText())) {
return transformMethodCallOnThis(call);
} else if ("super".equals(obj.getText())) {
return transformSuperMethodCall(call);
}
} else if (exp instanceof FieldExpression) {
FieldNode field = ((FieldExpression) exp).getField();
MethodCallExpression mce = new MethodCallExpression(
createFieldHelperReceiver(),
Traits.helperGetterName(field),
ArgumentListExpression.EMPTY_ARGUMENTS
);
mce.setSourcePosition(exp);
mce.setImplicitThis(false);
return mce;
} else if (exp instanceof VariableExpression) {
VariableExpression vexp = (VariableExpression) exp;
Variable accessedVariable = vexp.getAccessedVariable();
if (accessedVariable instanceof FieldNode) {
FieldNode fn = (FieldNode) accessedVariable;
Expression receiver = createFieldHelperReceiver();
if (fn.isStatic()) {
receiver = new PropertyExpression(createFieldHelperReceiver(), "class");
}
MethodCallExpression mce = new MethodCallExpression(
receiver,
Traits.helperGetterName((FieldNode) accessedVariable),
ArgumentListExpression.EMPTY_ARGUMENTS
);
mce.setSourcePosition(exp);
mce.setImplicitThis(false);
return mce;
} else if (accessedVariable instanceof PropertyNode) {
String propName = accessedVariable.getName();
if (knownFields.contains(propName)) {
String method = Traits.helperGetterName(new FieldNode(propName, 0, ClassHelper.OBJECT_TYPE, weavedType, null));
MethodCallExpression mce = new MethodCallExpression(
createFieldHelperReceiver(),
method,
ArgumentListExpression.EMPTY_ARGUMENTS
);
mce.setSourcePosition(exp);
mce.setImplicitThis(false);
return mce;
} else {
return new PropertyExpression(
new VariableExpression(weaved),
accessedVariable.getName()
);
}
} else if (accessedVariable instanceof DynamicVariable) {
return new PropertyExpression(
new VariableExpression(weaved),
accessedVariable.getName()
);
}
if (vexp.isThisExpression()) {
VariableExpression res = new VariableExpression(weaved);
res.setSourcePosition(exp);
return res;
}
if (vexp.isSuperExpression()) {
throwSuperError(vexp);
}
} else if (exp instanceof PropertyExpression) {
PropertyExpression pexp = (PropertyExpression) exp;
Expression object = pexp.getObjectExpression();
if (pexp.isImplicitThis() || "this".equals(object.getText())) {
String propName = pexp.getPropertyAsString();
if (knownFields.contains(propName)) {
String method = Traits.helperGetterName(new FieldNode(propName, 0, ClassHelper.OBJECT_TYPE, weavedType, null));
MethodCallExpression mce = new MethodCallExpression(
createFieldHelperReceiver(),
method,
ArgumentListExpression.EMPTY_ARGUMENTS
);
mce.setSourcePosition(exp);
mce.setImplicitThis(false);
return mce;
}
}
} else if (exp instanceof ClosureExpression) {
MethodCallExpression mce = new MethodCallExpression(
exp,
"rehydrate",
new ArgumentListExpression(
new VariableExpression(weaved),
new VariableExpression(weaved),
new VariableExpression(weaved)
)
);
mce.setImplicitThis(false);
mce.setSourcePosition(exp);
return mce;
}
// todo: unary expressions (field++, field+=, ...)
return super.transform(exp);