Search in sources :

Example 41 with ConstantExpression

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

the class MarkupBuilderCodeTransformer method transform.

@Override
public Expression transform(final Expression exp) {
    if (exp instanceof BinaryExpression) {
        return transformBinaryExpression((BinaryExpression) exp);
    }
    if (exp instanceof MethodCallExpression) {
        return transformMethodCall((MethodCallExpression) exp);
    }
    if (exp instanceof ClosureExpression) {
        ClosureExpression cl = (ClosureExpression) exp;
        cl.getCode().visit(this);
        return cl;
    }
    if (exp instanceof VariableExpression) {
        VariableExpression var = (VariableExpression) exp;
        if (var.getAccessedVariable() instanceof DynamicVariable) {
            MethodCallExpression callGetModel = new MethodCallExpression(new VariableExpression("this"), "getModel", ArgumentListExpression.EMPTY_ARGUMENTS);
            callGetModel.setImplicitThis(true);
            callGetModel.setSourcePosition(exp);
            String varName = var.getName();
            if ("model".equals(varName) || "unescaped".equals(varName)) {
                return callGetModel;
            }
            MethodCallExpression mce = new MethodCallExpression(callGetModel, "get", new ArgumentListExpression(new ConstantExpression(varName)));
            mce.setSourcePosition(exp);
            mce.setImplicitThis(false);
            MethodCallExpression yield = new MethodCallExpression(new VariableExpression("this"), "tryEscape", new ArgumentListExpression(mce));
            yield.setImplicitThis(true);
            yield.setSourcePosition(exp);
            yield.putNodeMetaData(TARGET_VARIABLE, varName);
            return autoEscape ? yield : mce;
        }
    }
    return super.transform(exp);
}
Also used : BinaryExpression(org.codehaus.groovy.ast.expr.BinaryExpression) MethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression) DynamicVariable(org.codehaus.groovy.ast.DynamicVariable) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) ArgumentListExpression(org.codehaus.groovy.ast.expr.ArgumentListExpression) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) ClosureExpression(org.codehaus.groovy.ast.expr.ClosureExpression)

Example 42 with ConstantExpression

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

the class SqlWhereVisitor method visitBinaryExpression.

public void visitBinaryExpression(BinaryExpression expression) {
    Expression left = expression.getLeftExpression();
    Expression right = expression.getRightExpression();
    boolean leaf = (right instanceof ConstantExpression || left instanceof ConstantExpression);
    if (!leaf)
        buffer.append("(");
    left.visit(this);
    buffer.append(" ");
    Token token = expression.getOperation();
    buffer.append(tokenAsSql(token));
    buffer.append(" ");
    right.visit(this);
    if (!leaf)
        buffer.append(")");
}
Also used : BooleanExpression(org.codehaus.groovy.ast.expr.BooleanExpression) PropertyExpression(org.codehaus.groovy.ast.expr.PropertyExpression) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) BinaryExpression(org.codehaus.groovy.ast.expr.BinaryExpression) Expression(org.codehaus.groovy.ast.expr.Expression) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) Token(org.codehaus.groovy.syntax.Token)

Example 43 with ConstantExpression

use of org.codehaus.groovy.ast.expr.ConstantExpression in project spring-boot by spring-projects.

the class DependencyCustomizer method createGrabAnnotation.

private AnnotationNode createGrabAnnotation(String group, String module, String version, String classifier, String type, boolean transitive) {
    AnnotationNode annotationNode = new AnnotationNode(new ClassNode(Grab.class));
    annotationNode.addMember("group", new ConstantExpression(group));
    annotationNode.addMember("module", new ConstantExpression(module));
    annotationNode.addMember("version", new ConstantExpression(version));
    if (classifier != null) {
        annotationNode.addMember("classifier", new ConstantExpression(classifier));
    }
    if (type != null) {
        annotationNode.addMember("type", new ConstantExpression(type));
    }
    annotationNode.addMember("transitive", new ConstantExpression(transitive));
    annotationNode.addMember("initClass", new ConstantExpression(false));
    return annotationNode;
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) AnnotationNode(org.codehaus.groovy.ast.AnnotationNode) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) Grab(groovy.lang.Grab)

Example 44 with ConstantExpression

use of org.codehaus.groovy.ast.expr.ConstantExpression in project spring-boot by spring-projects.

the class DependencyManagementBomTransformation method createDependencyMaps.

private List<Map<String, String>> createDependencyMaps(Expression valueExpression) {
    Map<String, String> dependency = null;
    List<ConstantExpression> constantExpressions = getConstantExpressions(valueExpression);
    List<Map<String, String>> dependencies = new ArrayList<>(constantExpressions.size());
    for (ConstantExpression expression : constantExpressions) {
        Object value = expression.getValue();
        if (value instanceof String) {
            String[] components = ((String) expression.getValue()).split(":");
            if (components.length == 3) {
                dependency = new HashMap<>();
                dependency.put("group", components[0]);
                dependency.put("module", components[1]);
                dependency.put("version", components[2]);
                dependency.put("type", "pom");
                dependencies.add(dependency);
            } else {
                handleMalformedDependency(expression);
            }
        }
    }
    return dependencies;
}
Also used : ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 45 with ConstantExpression

use of org.codehaus.groovy.ast.expr.ConstantExpression in project spring-boot by spring-projects.

the class GenericBomAstTransformation method addDependencyManagementBom.

private void addDependencyManagementBom(ModuleNode node, String module) {
    AnnotatedNode annotated = getAnnotatedNode(node);
    if (annotated != null) {
        AnnotationNode bom = getAnnotation(annotated);
        List<Expression> expressions = new ArrayList<>(getConstantExpressions(bom.getMember("value")));
        expressions.add(new ConstantExpression(module));
        bom.setMember("value", new ListExpression(expressions));
    }
}
Also used : AnnotationNode(org.codehaus.groovy.ast.AnnotationNode) ListExpression(org.codehaus.groovy.ast.expr.ListExpression) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) Expression(org.codehaus.groovy.ast.expr.Expression) AnnotatedNode(org.codehaus.groovy.ast.AnnotatedNode) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) ListExpression(org.codehaus.groovy.ast.expr.ListExpression) ArrayList(java.util.ArrayList)

Aggregations

ConstantExpression (org.codehaus.groovy.ast.expr.ConstantExpression)157 Expression (org.codehaus.groovy.ast.expr.Expression)92 VariableExpression (org.codehaus.groovy.ast.expr.VariableExpression)88 ClassExpression (org.codehaus.groovy.ast.expr.ClassExpression)73 ArgumentListExpression (org.codehaus.groovy.ast.expr.ArgumentListExpression)72 MethodCallExpression (org.codehaus.groovy.ast.expr.MethodCallExpression)67 ListExpression (org.codehaus.groovy.ast.expr.ListExpression)59 BinaryExpression (org.codehaus.groovy.ast.expr.BinaryExpression)55 ClassNode (org.codehaus.groovy.ast.ClassNode)51 ClosureExpression (org.codehaus.groovy.ast.expr.ClosureExpression)43 ConstructorCallExpression (org.codehaus.groovy.ast.expr.ConstructorCallExpression)42 PropertyExpression (org.codehaus.groovy.ast.expr.PropertyExpression)41 BlockStatement (org.codehaus.groovy.ast.stmt.BlockStatement)39 ExpressionStatement (org.codehaus.groovy.ast.stmt.ExpressionStatement)37 BooleanExpression (org.codehaus.groovy.ast.expr.BooleanExpression)36 DeclarationExpression (org.codehaus.groovy.ast.expr.DeclarationExpression)35 MapExpression (org.codehaus.groovy.ast.expr.MapExpression)33 Statement (org.codehaus.groovy.ast.stmt.Statement)33 StaticMethodCallExpression (org.codehaus.groovy.ast.expr.StaticMethodCallExpression)31 TupleExpression (org.codehaus.groovy.ast.expr.TupleExpression)29