Search in sources :

Example 61 with TupleExpression

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;
}
Also used : TupleExpression(org.codehaus.groovy.ast.expr.TupleExpression)

Example 62 with TupleExpression

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);
    }
}
Also used : ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) BinaryExpression(org.codehaus.groovy.ast.expr.BinaryExpression) PropertyExpression(org.codehaus.groovy.ast.expr.PropertyExpression) MethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression) Expression(org.codehaus.groovy.ast.expr.Expression) DeclarationExpression(org.codehaus.groovy.ast.expr.DeclarationExpression) TupleExpression(org.codehaus.groovy.ast.expr.TupleExpression) GStringExpression(org.codehaus.groovy.ast.expr.GStringExpression) MapEntryExpression(org.codehaus.groovy.ast.expr.MapEntryExpression) TupleExpression(org.codehaus.groovy.ast.expr.TupleExpression)

Example 63 with TupleExpression

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);
    }
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) InnerClassNode(org.codehaus.groovy.ast.InnerClassNode) Expression(org.codehaus.groovy.ast.expr.Expression) ConstructorCallExpression(org.codehaus.groovy.ast.expr.ConstructorCallExpression) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) ClosureExpression(org.codehaus.groovy.ast.expr.ClosureExpression) TupleExpression(org.codehaus.groovy.ast.expr.TupleExpression) TupleExpression(org.codehaus.groovy.ast.expr.TupleExpression)

Example 64 with TupleExpression

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)));
    }
}
Also used : TupleExpression(org.codehaus.groovy.ast.expr.TupleExpression) Parameter(org.codehaus.groovy.ast.Parameter)

Example 65 with TupleExpression

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);
}
Also used : PropertyExpression(org.codehaus.groovy.ast.expr.PropertyExpression) GeneralUtils.thisPropX(org.codehaus.groovy.ast.tools.GeneralUtils.thisPropX) ACC_STATIC(org.objectweb.asm.Opcodes.ACC_STATIC) Function(java.util.function.Function) ACC_ABSTRACT(org.objectweb.asm.Opcodes.ACC_ABSTRACT) ClosureUtils(org.codehaus.groovy.ast.tools.ClosureUtils) ClassCodeExpressionTransformer(org.codehaus.groovy.ast.ClassCodeExpressionTransformer) MethodNode(org.codehaus.groovy.ast.MethodNode) MethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression) GeneralUtils.varX(org.codehaus.groovy.ast.tools.GeneralUtils.varX) MetaProperty(groovy.lang.MetaProperty) Expression(org.codehaus.groovy.ast.expr.Expression) Parameter(org.codehaus.groovy.ast.Parameter) SourceUnit(org.codehaus.groovy.control.SourceUnit) ClassNode(org.codehaus.groovy.ast.ClassNode) ClassHelper(org.codehaus.groovy.ast.ClassHelper) Types(org.codehaus.groovy.syntax.Types) ArgumentListExpression(org.codehaus.groovy.ast.expr.ArgumentListExpression) ClassHelper.isPrimitiveBoolean(org.codehaus.groovy.ast.ClassHelper.isPrimitiveBoolean) ClassHelper.isPrimitiveVoid(org.codehaus.groovy.ast.ClassHelper.isPrimitiveVoid) InnerClassNode(org.codehaus.groovy.ast.InnerClassNode) ClosureExpression(org.codehaus.groovy.ast.expr.ClosureExpression) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression) TupleExpression(org.codehaus.groovy.ast.expr.TupleExpression) List(java.util.List) ClassHelper.isClassType(org.codehaus.groovy.ast.ClassHelper.isClassType) BinaryExpression(org.codehaus.groovy.ast.expr.BinaryExpression) ACC_PUBLIC(org.objectweb.asm.Opcodes.ACC_PUBLIC) ACC_SYNTHETIC(org.objectweb.asm.Opcodes.ACC_SYNTHETIC) ClassNode(org.codehaus.groovy.ast.ClassNode) InnerClassNode(org.codehaus.groovy.ast.InnerClassNode) MethodNode(org.codehaus.groovy.ast.MethodNode) MethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression) PropertyExpression(org.codehaus.groovy.ast.expr.PropertyExpression) MethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression) Expression(org.codehaus.groovy.ast.expr.Expression) ArgumentListExpression(org.codehaus.groovy.ast.expr.ArgumentListExpression) ClosureExpression(org.codehaus.groovy.ast.expr.ClosureExpression) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression) TupleExpression(org.codehaus.groovy.ast.expr.TupleExpression) BinaryExpression(org.codehaus.groovy.ast.expr.BinaryExpression) TupleExpression(org.codehaus.groovy.ast.expr.TupleExpression) ArgumentListExpression(org.codehaus.groovy.ast.expr.ArgumentListExpression) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression)

Aggregations

TupleExpression (org.codehaus.groovy.ast.expr.TupleExpression)78 Expression (org.codehaus.groovy.ast.expr.Expression)65 VariableExpression (org.codehaus.groovy.ast.expr.VariableExpression)56 MethodCallExpression (org.codehaus.groovy.ast.expr.MethodCallExpression)48 ArgumentListExpression (org.codehaus.groovy.ast.expr.ArgumentListExpression)44 PropertyExpression (org.codehaus.groovy.ast.expr.PropertyExpression)42 ConstantExpression (org.codehaus.groovy.ast.expr.ConstantExpression)41 ConstructorCallExpression (org.codehaus.groovy.ast.expr.ConstructorCallExpression)40 ClosureExpression (org.codehaus.groovy.ast.expr.ClosureExpression)35 ClassNode (org.codehaus.groovy.ast.ClassNode)34 ClassExpression (org.codehaus.groovy.ast.expr.ClassExpression)34 BinaryExpression (org.codehaus.groovy.ast.expr.BinaryExpression)31 ArrayExpression (org.codehaus.groovy.ast.expr.ArrayExpression)23 DeclarationExpression (org.codehaus.groovy.ast.expr.DeclarationExpression)23 MapExpression (org.codehaus.groovy.ast.expr.MapExpression)22 InnerClassNode (org.codehaus.groovy.ast.InnerClassNode)20 Parameter (org.codehaus.groovy.ast.Parameter)20 ListExpression (org.codehaus.groovy.ast.expr.ListExpression)18 MapEntryExpression (org.codehaus.groovy.ast.expr.MapEntryExpression)18 CastExpression (org.codehaus.groovy.ast.expr.CastExpression)17