Search in sources :

Example 6 with MapEntryExpression

use of org.codehaus.groovy.ast.expr.MapEntryExpression in project grails-core by grails.

the class TestMixinTransformation method addTestRuntimeAwareMixinFieldIfNonExistent.

protected FieldNode addTestRuntimeAwareMixinFieldIfNonExistent(ClassNode classNode, ClassNode fieldType, String fieldName) {
    if (classNode == null || classNode.getField(fieldName) != null) {
        return null;
    }
    MapExpression constructorArguments = new MapExpression();
    constructorArguments.addMapEntryExpression(new MapEntryExpression(new ConstantExpression("testClass"), new ClassExpression(classNode)));
    FieldNode mixinInstanceFieldNode = classNode.addField(fieldName, Modifier.STATIC, fieldType, new ConstructorCallExpression(fieldType, constructorArguments));
    mixinInstanceFieldNode.addAnnotation(new AnnotationNode(ClassHelper.make(MixinInstance.class)));
    addJunitRuleFields(classNode);
    return mixinInstanceFieldNode;
}
Also used : MapExpression(org.codehaus.groovy.ast.expr.MapExpression) MapEntryExpression(org.codehaus.groovy.ast.expr.MapEntryExpression) FieldNode(org.codehaus.groovy.ast.FieldNode) AnnotationNode(org.codehaus.groovy.ast.AnnotationNode) ConstructorCallExpression(org.codehaus.groovy.ast.expr.ConstructorCallExpression) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression)

Example 7 with MapEntryExpression

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

the class StaticImportVisitor method transformConstructorCallExpression.

protected Expression transformConstructorCallExpression(ConstructorCallExpression cce) {
    inSpecialConstructorCall = cce.isSpecialCall();
    Expression expression = cce.getArguments();
    if (expression instanceof TupleExpression) {
        TupleExpression tuple = (TupleExpression) expression;
        if (tuple.getExpressions().size() == 1) {
            expression = tuple.getExpression(0);
            if (expression instanceof NamedArgumentListExpression) {
                NamedArgumentListExpression namedArgs = (NamedArgumentListExpression) expression;
                List<MapEntryExpression> entryExpressions = namedArgs.getMapEntryExpressions();
                for (int i = 0; i < entryExpressions.size(); i++) {
                    entryExpressions.set(i, (MapEntryExpression) transformMapEntryExpression(entryExpressions.get(i), cce.getType()));
                }
            }
        }
    }
    Expression ret = cce.transformExpression(this);
    inSpecialConstructorCall = false;
    return ret;
}
Also used : MapEntryExpression(org.codehaus.groovy.ast.expr.MapEntryExpression) ListExpression(org.codehaus.groovy.ast.expr.ListExpression) PropertyExpression(org.codehaus.groovy.ast.expr.PropertyExpression) StaticMethodCallExpression(org.codehaus.groovy.ast.expr.StaticMethodCallExpression) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) NamedArgumentListExpression(org.codehaus.groovy.ast.expr.NamedArgumentListExpression) MethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression) EmptyExpression(org.codehaus.groovy.ast.expr.EmptyExpression) Expression(org.codehaus.groovy.ast.expr.Expression) ConstructorCallExpression(org.codehaus.groovy.ast.expr.ConstructorCallExpression) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) ArgumentListExpression(org.codehaus.groovy.ast.expr.ArgumentListExpression) AnnotationConstantExpression(org.codehaus.groovy.ast.expr.AnnotationConstantExpression) 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) MapEntryExpression(org.codehaus.groovy.ast.expr.MapEntryExpression) TupleExpression(org.codehaus.groovy.ast.expr.TupleExpression) NamedArgumentListExpression(org.codehaus.groovy.ast.expr.NamedArgumentListExpression)

Aggregations

ConstantExpression (org.codehaus.groovy.ast.expr.ConstantExpression)7 MapEntryExpression (org.codehaus.groovy.ast.expr.MapEntryExpression)7 ArgumentListExpression (org.codehaus.groovy.ast.expr.ArgumentListExpression)6 Expression (org.codehaus.groovy.ast.expr.Expression)6 MethodCallExpression (org.codehaus.groovy.ast.expr.MethodCallExpression)6 VariableExpression (org.codehaus.groovy.ast.expr.VariableExpression)6 BinaryExpression (org.codehaus.groovy.ast.expr.BinaryExpression)5 ClassExpression (org.codehaus.groovy.ast.expr.ClassExpression)5 ClosureExpression (org.codehaus.groovy.ast.expr.ClosureExpression)5 ConstructorCallExpression (org.codehaus.groovy.ast.expr.ConstructorCallExpression)5 EmptyExpression (org.codehaus.groovy.ast.expr.EmptyExpression)5 MapExpression (org.codehaus.groovy.ast.expr.MapExpression)5 TupleExpression (org.codehaus.groovy.ast.expr.TupleExpression)5 ListExpression (org.codehaus.groovy.ast.expr.ListExpression)4 DeclarationExpression (org.codehaus.groovy.ast.expr.DeclarationExpression)3 PropertyExpression (org.codehaus.groovy.ast.expr.PropertyExpression)3 StaticMethodCallExpression (org.codehaus.groovy.ast.expr.StaticMethodCallExpression)3 AnnotationConstantExpression (org.codehaus.groovy.ast.expr.AnnotationConstantExpression)2 ArrayExpression (org.codehaus.groovy.ast.expr.ArrayExpression)2 GStringExpression (org.codehaus.groovy.ast.expr.GStringExpression)2