use of org.codehaus.groovy.ast.expr.TupleExpression in project groovy by apache.
the class AsmClassGenerator method argumentSize.
public static int argumentSize(final Expression arguments) {
if (arguments instanceof TupleExpression) {
TupleExpression tupleExpression = (TupleExpression) arguments;
int size = tupleExpression.getExpressions().size();
return size;
}
return 1;
}
use of org.codehaus.groovy.ast.expr.TupleExpression in project groovy by apache.
the class ClassCompletionVerifier method visitMethodCallExpression.
@Override
public void visitMethodCallExpression(MethodCallExpression mce) {
super.visitMethodCallExpression(mce);
Expression aexp = mce.getArguments();
if (aexp instanceof TupleExpression) {
TupleExpression arguments = (TupleExpression) aexp;
for (Expression e : arguments.getExpressions()) {
checkForInvalidDeclaration(e);
}
} else {
checkForInvalidDeclaration(aexp);
}
}
use of org.codehaus.groovy.ast.expr.TupleExpression in project groovy by apache.
the class InnerClassVisitor method insertThis0ToSuperCall.
private void insertThis0ToSuperCall(final ConstructorCallExpression call, final ClassNode cn) {
// calculate outer class which we need for this$0
ClassNode parent = classNode;
int level = 0;
for (; parent != null && parent != cn.getOuterClass(); parent = parent.getOuterClass()) {
level++;
}
// if constructor call is not in outer class, don't pass 'this' implicitly. Return.
if (parent == null)
return;
Expression args = call.getArguments();
if (args instanceof TupleExpression) {
// bypass closure
Expression this0 = varX("this");
for (int i = 0; i != level; ++i) {
this0 = attrX(this0, constX("this$0"));
// GROOVY-8104: an anonymous inner class may still have closure nesting
if (i == 0 && classNode.getDeclaredField("this$0").getType().equals(ClassHelper.CLOSURE_TYPE)) {
this0 = callX(this0, "getThisObject");
}
}
((TupleExpression) args).getExpressions().add(0, this0);
}
}
use of org.codehaus.groovy.ast.expr.TupleExpression in project groovy by apache.
the class InnerClassCompletionVisitor method makeBridgeConstructor.
private static void makeBridgeConstructor(final ClassNode c, final Parameter[] p) {
Parameter[] newP = new Parameter[p.length + 1];
for (int i = 0; i < p.length; i += 1) {
newP[i] = new Parameter(p[i].getType(), "p" + i);
}
newP[p.length] = new Parameter(c, "$anonymous");
if (c.getDeclaredConstructor(newP) == null) {
TupleExpression args = new TupleExpression();
for (int i = 0; i < p.length; i += 1) args.addExpression(varX(newP[i]));
addGeneratedConstructor(c, ACC_SYNTHETIC, newP, ClassNode.EMPTY_ARRAY, stmt(ctorThisX(args)));
}
}
use of org.codehaus.groovy.ast.expr.TupleExpression in project groovy by apache.
the class SuperCallTraitTransformer method transformMethodCallExpression.
private Expression transformMethodCallExpression(final MethodCallExpression exp) {
ClassNode traitType = getTraitSuperTarget(exp.getObjectExpression());
if (traitType != null) {
ClassNode helperType = getHelper(traitType);
// TraitType.super.foo() -> TraitType$Trait$Helper.foo(this)
List<MethodNode> targets = helperType.getMethods(exp.getMethodAsString());
boolean isStatic = !targets.isEmpty() && targets.stream().map(MethodNode::getParameters).allMatch(params -> params.length > 0 && isClassType(params[0].getType()));
ArgumentListExpression newArgs = new ArgumentListExpression(isStatic ? thisPropX(false, "class") : varX("this"));
Expression arguments = exp.getArguments();
if (arguments instanceof TupleExpression) {
for (Expression expression : (TupleExpression) arguments) {
newArgs.addExpression(transform(expression));
}
} else {
newArgs.addExpression(transform(arguments));
}
MethodCallExpression newCall = new MethodCallExpression(new ClassExpression(helperType), transform(exp.getMethod()), newArgs);
newCall.getObjectExpression().setSourcePosition(traitType);
newCall.setSpreadSafe(exp.isSpreadSafe());
newCall.setImplicitThis(false);
return newCall;
}
return super.transform(exp);
}
Aggregations