use of org.codehaus.groovy.ast.expr.ArgumentListExpression in project groovy by apache.
the class ListExpressionTransformer method transformRegularConstructor.
private Expression transformRegularConstructor(final ListExpression expr, final MethodNode target) {
// can be replaced with a direct constructor call
List<Expression> transformedArgs = transformArguments(expr);
ConstructorCallExpression cce = new ConstructorCallExpression(target.getDeclaringClass(), new ArgumentListExpression(transformedArgs));
cce.setSourcePosition(expr);
cce.putNodeMetaData(DIRECT_METHOD_CALL_TARGET, target);
return cce;
}
use of org.codehaus.groovy.ast.expr.ArgumentListExpression in project groovy by apache.
the class MapConstructorASTTransformation method assignField.
private static void assignField(boolean useSetters, Parameter map, BlockStatement body, String name) {
ArgumentListExpression nameArg = args(constX(name));
body.addStatement(ifS(callX(varX(map), "containsKey", nameArg), useSetters ? stmt(callThisX(getSetterName(name), callX(varX(map), "get", nameArg))) : assignS(propX(varX("this"), name), callX(varX(map), "get", nameArg))));
}
use of org.codehaus.groovy.ast.expr.ArgumentListExpression in project groovy by apache.
the class AbstractTypeCheckingExtension method argTypesMatches.
public boolean argTypesMatches(MethodCall call, Class... classes) {
ArgumentListExpression argumentListExpression = InvocationWriter.makeArgumentList(call.getArguments());
ClassNode[] argumentTypes = typeCheckingVisitor.getArgumentTypes(argumentListExpression);
return argTypesMatches(argumentTypes, classes);
}
use of org.codehaus.groovy.ast.expr.ArgumentListExpression in project groovy by apache.
the class MarkupBuilderCodeTransformer method transformBinaryExpression.
private Expression transformBinaryExpression(final BinaryExpression bin) {
Expression left = bin.getLeftExpression();
Expression right = bin.getRightExpression();
boolean assignment = bin.getOperation().getType() == Types.ASSIGN;
if (assignment && left instanceof VariableExpression) {
VariableExpression var = (VariableExpression) left;
if (var.getAccessedVariable() instanceof DynamicVariable) {
String varName = var.getName();
if (!"modelTypes".equals(varName)) {
MethodCallExpression callGetModel = new MethodCallExpression(new VariableExpression("this"), "getModel", ArgumentListExpression.EMPTY_ARGUMENTS);
callGetModel.setImplicitThis(true);
callGetModel.setSourcePosition(left);
MethodCallExpression mce = new MethodCallExpression(callGetModel, "put", new ArgumentListExpression(new ConstantExpression(varName), right));
mce.setSourcePosition(left);
mce.setImplicitThis(false);
return transform(mce);
}
}
}
if (assignment && left instanceof VariableExpression && right instanceof ClosureExpression) {
VariableExpression var = (VariableExpression) left;
if ("modelTypes".equals(var.getName())) {
// template declaring its expected types from model directly
// modelTypes = {
// List<String> items
// ...
// }
Map<String, ClassNode> modelTypes = extractModelTypesFromClosureExpression((ClosureExpression) right);
Expression result = new EmptyExpression();
result.setSourcePosition(bin);
classNode.putNodeMetaData(MarkupTemplateEngine.MODELTYPES_ASTKEY, modelTypes);
return result;
}
}
return super.transform(bin);
}
use of org.codehaus.groovy.ast.expr.ArgumentListExpression in project groovy by apache.
the class MarkupBuilderCodeTransformer method tryTransformInclude.
private Expression tryTransformInclude(final MethodCallExpression exp) {
Expression arguments = exp.getArguments();
if (arguments instanceof TupleExpression) {
List<Expression> expressions = ((TupleExpression) arguments).getExpressions();
if (expressions.size() == 1 && expressions.get(0) instanceof MapExpression) {
MapExpression map = (MapExpression) expressions.get(0);
List<MapEntryExpression> entries = map.getMapEntryExpressions();
if (entries.size() == 1) {
MapEntryExpression mapEntry = entries.get(0);
Expression keyExpression = mapEntry.getKeyExpression();
try {
IncludeType includeType = IncludeType.valueOf(keyExpression.getText().toLowerCase());
MethodCallExpression call = new MethodCallExpression(exp.getObjectExpression(), includeType.getMethodName(), new ArgumentListExpression(mapEntry.getValueExpression()));
call.setImplicitThis(true);
call.setSafe(exp.isSafe());
call.setSpreadSafe(exp.isSpreadSafe());
call.setSourcePosition(exp);
return call;
} catch (IllegalArgumentException e) {
// not a valid import type, do not modify the code
}
}
}
}
return super.transform(exp);
}
Aggregations