Search in sources :

Example 66 with ConstructorCallExpression

use of org.codehaus.groovy.ast.expr.ConstructorCallExpression in project groovy by apache.

the class NewifyASTTransformation method transform.

public Expression transform(Expression expr) {
    if (expr == null)
        return null;
    if (expr instanceof MethodCallExpression && candidate == null) {
        MethodCallExpression mce = (MethodCallExpression) expr;
        Expression args = transform(mce.getArguments());
        if (isNewifyCandidate(mce)) {
            Expression transformed = transformMethodCall(mce, args);
            transformed.setSourcePosition(mce);
            return transformed;
        }
        Expression method = transform(mce.getMethod());
        Expression object = transform(mce.getObjectExpression());
        MethodCallExpression transformed = callX(object, method, args);
        transformed.setImplicitThis(mce.isImplicitThis());
        transformed.setSourcePosition(mce);
        return transformed;
    } else if (expr instanceof ClosureExpression) {
        ClosureExpression ce = (ClosureExpression) expr;
        ce.getCode().visit(this);
    } else if (expr instanceof ConstructorCallExpression) {
        ConstructorCallExpression cce = (ConstructorCallExpression) expr;
        if (cce.isUsingAnonymousInnerClass()) {
            cce.getType().visitContents(this);
        }
    } else if (expr instanceof DeclarationExpression) {
        DeclarationExpression de = (DeclarationExpression) expr;
        if (de == candidate || auto) {
            candidate = null;
            Expression left = de.getLeftExpression();
            Expression right = transform(de.getRightExpression());
            DeclarationExpression newDecl = new DeclarationExpression(left, de.getOperation(), right);
            newDecl.addAnnotations(de.getAnnotations());
            return newDecl;
        }
        return de;
    }
    return expr.transformExpression(this);
}
Also used : MethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression) ListExpression(org.codehaus.groovy.ast.expr.ListExpression) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) MethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression) Expression(org.codehaus.groovy.ast.expr.Expression) ConstructorCallExpression(org.codehaus.groovy.ast.expr.ConstructorCallExpression) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) DeclarationExpression(org.codehaus.groovy.ast.expr.DeclarationExpression) ClosureExpression(org.codehaus.groovy.ast.expr.ClosureExpression) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression) ConstructorCallExpression(org.codehaus.groovy.ast.expr.ConstructorCallExpression) DeclarationExpression(org.codehaus.groovy.ast.expr.DeclarationExpression) ClosureExpression(org.codehaus.groovy.ast.expr.ClosureExpression)

Example 67 with ConstructorCallExpression

use of org.codehaus.groovy.ast.expr.ConstructorCallExpression in project groovy by apache.

the class RangeExpressionTransformer method transformRangeExpression.

public Expression transformRangeExpression(RangeExpression range) {
    final ClassNode inferred = range.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE);
    if (INTRANGE_TYPE.equals(inferred)) {
        ArgumentListExpression bounds = new ArgumentListExpression(new ConstantExpression(range.isInclusive(), true), range.getFrom(), range.getTo());
        ConstructorCallExpression cce = new ConstructorCallExpression(INTRANGE_TYPE, bounds);
        cce.setSourcePosition(range);
        cce.putNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET, INTRANGE_CTOR);
        cce.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, INTRANGE_TYPE);
        return transformer.transform(cce);
    }
    return transformer.superTransform(range);
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) ConstructorCallExpression(org.codehaus.groovy.ast.expr.ConstructorCallExpression) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) ArgumentListExpression(org.codehaus.groovy.ast.expr.ArgumentListExpression)

Example 68 with ConstructorCallExpression

use of org.codehaus.groovy.ast.expr.ConstructorCallExpression in project gradle by gradle.

the class GradleResolveVisitor method transformConstructorCallExpression.

protected Expression transformConstructorCallExpression(ConstructorCallExpression cce) {
    ClassNode type = cce.getType();
    resolveOrFail(type, cce);
    if (Modifier.isAbstract(type.getModifiers())) {
        addError("You cannot create an instance from the abstract " + getDescription(type) + ".", cce);
    }
    Expression ret = cce.transformExpression(this);
    return ret;
}
Also used : InnerClassNode(org.codehaus.groovy.ast.InnerClassNode) ClassNode(org.codehaus.groovy.ast.ClassNode) ListExpression(org.codehaus.groovy.ast.expr.ListExpression) MapExpression(org.codehaus.groovy.ast.expr.MapExpression) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) BinaryExpression(org.codehaus.groovy.ast.expr.BinaryExpression) CastExpression(org.codehaus.groovy.ast.expr.CastExpression) PropertyExpression(org.codehaus.groovy.ast.expr.PropertyExpression) MethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression) Expression(org.codehaus.groovy.ast.expr.Expression) SpreadMapExpression(org.codehaus.groovy.ast.expr.SpreadMapExpression) ConstructorCallExpression(org.codehaus.groovy.ast.expr.ConstructorCallExpression) AnnotationConstantExpression(org.codehaus.groovy.ast.expr.AnnotationConstantExpression) DeclarationExpression(org.codehaus.groovy.ast.expr.DeclarationExpression) ClosureExpression(org.codehaus.groovy.ast.expr.ClosureExpression) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression) MapEntryExpression(org.codehaus.groovy.ast.expr.MapEntryExpression)

Aggregations

ConstructorCallExpression (org.codehaus.groovy.ast.expr.ConstructorCallExpression)68 Expression (org.codehaus.groovy.ast.expr.Expression)45 VariableExpression (org.codehaus.groovy.ast.expr.VariableExpression)44 ExpressionStatement (org.codehaus.groovy.ast.stmt.ExpressionStatement)37 ArgumentListExpression (org.codehaus.groovy.ast.expr.ArgumentListExpression)35 BlockStatement (org.codehaus.groovy.ast.stmt.BlockStatement)32 ConstantExpression (org.codehaus.groovy.ast.expr.ConstantExpression)30 ClassExpression (org.codehaus.groovy.ast.expr.ClassExpression)28 ClosureExpression (org.codehaus.groovy.ast.expr.ClosureExpression)25 MethodCallExpression (org.codehaus.groovy.ast.expr.MethodCallExpression)25 ClassNode (org.codehaus.groovy.ast.ClassNode)24 Statement (org.codehaus.groovy.ast.stmt.Statement)24 TupleExpression (org.codehaus.groovy.ast.expr.TupleExpression)21 PropertyExpression (org.codehaus.groovy.ast.expr.PropertyExpression)18 ReturnStatement (org.codehaus.groovy.ast.stmt.ReturnStatement)16 ArrayList (java.util.ArrayList)15 BinaryExpression (org.codehaus.groovy.ast.expr.BinaryExpression)15 ListExpression (org.codehaus.groovy.ast.expr.ListExpression)15 InnerClassNode (org.codehaus.groovy.ast.InnerClassNode)13 DeclarationExpression (org.codehaus.groovy.ast.expr.DeclarationExpression)10