Search in sources :

Example 41 with MapExpression

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

the class ImmutableASTTransformation method createNoArgConstructor.

private void createNoArgConstructor(ClassNode cNode) {
    Statement body = stmt(ctorX(ClassNode.THIS, args(new MapExpression())));
    doAddConstructor(cNode, new ConstructorNode(ACC_PUBLIC, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, body));
}
Also used : MapExpression(org.codehaus.groovy.ast.expr.MapExpression) BlockStatement(org.codehaus.groovy.ast.stmt.BlockStatement) Statement(org.codehaus.groovy.ast.stmt.Statement) ThrowStatement(org.codehaus.groovy.ast.stmt.ThrowStatement) EmptyStatement(org.codehaus.groovy.ast.stmt.EmptyStatement) ConstructorNode(org.codehaus.groovy.ast.ConstructorNode)

Example 42 with MapExpression

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

the class GrabAnnotationTransformation method callGrabAsStaticInitIfNeeded.

private void callGrabAsStaticInitIfNeeded(ClassNode classNode, ClassNode grapeClassNode, List<Map<String, Object>> grabMapsInit, List<Map<String, Object>> grabExcludeMaps) {
    List<Statement> grabInitializers = new ArrayList<Statement>();
    MapExpression basicArgs = new MapExpression();
    if (autoDownload != null) {
        basicArgs.addMapEntryExpression(new ConstantExpression(AUTO_DOWNLOAD_SETTING), new ConstantExpression(autoDownload));
    }
    if (disableChecksums != null) {
        basicArgs.addMapEntryExpression(new ConstantExpression(DISABLE_CHECKSUMS_SETTING), new ConstantExpression(disableChecksums));
    }
    if (!grabExcludeMaps.isEmpty()) {
        ListExpression list = new ListExpression();
        for (Map<String, Object> map : grabExcludeMaps) {
            Set<Map.Entry<String, Object>> entries = map.entrySet();
            MapExpression inner = new MapExpression();
            for (Map.Entry<String, Object> entry : entries) {
                inner.addMapEntryExpression(new ConstantExpression(entry.getKey()), new ConstantExpression(entry.getValue()));
            }
            list.addExpression(inner);
        }
        basicArgs.addMapEntryExpression(new ConstantExpression("excludes"), list);
    }
    List<Expression> argList = new ArrayList<Expression>();
    argList.add(basicArgs);
    if (grabMapsInit.size() == 0)
        return;
    for (Map<String, Object> grabMap : grabMapsInit) {
        // add Grape.grab(excludeArgs, [group:group, module:module, version:version, classifier:classifier])
        // or Grape.grab([group:group, module:module, version:version, classifier:classifier])
        MapExpression dependencyArg = new MapExpression();
        for (String s : GRAB_REQUIRED) {
            dependencyArg.addMapEntryExpression(new ConstantExpression(s), new ConstantExpression(grabMap.get(s)));
        }
        for (String s : GRAB_OPTIONAL) {
            if (grabMap.containsKey(s))
                dependencyArg.addMapEntryExpression(new ConstantExpression(s), new ConstantExpression(grabMap.get(s)));
        }
        argList.add(dependencyArg);
    }
    ArgumentListExpression grabArgs = new ArgumentListExpression(argList);
    grabInitializers.add(new ExpressionStatement(new StaticMethodCallExpression(grapeClassNode, "grab", grabArgs)));
    // insert at beginning so we have the classloader set up before the class is called
    classNode.addStaticInitializerStatements(grabInitializers, true);
}
Also used : MapExpression(org.codehaus.groovy.ast.expr.MapExpression) Statement(org.codehaus.groovy.ast.stmt.Statement) ExpressionStatement(org.codehaus.groovy.ast.stmt.ExpressionStatement) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) ListExpression(org.codehaus.groovy.ast.expr.ListExpression) ArgumentListExpression(org.codehaus.groovy.ast.expr.ArgumentListExpression) StaticMethodCallExpression(org.codehaus.groovy.ast.expr.StaticMethodCallExpression) ArgumentListExpression(org.codehaus.groovy.ast.expr.ArgumentListExpression) ListExpression(org.codehaus.groovy.ast.expr.ListExpression) MapExpression(org.codehaus.groovy.ast.expr.MapExpression) StaticMethodCallExpression(org.codehaus.groovy.ast.expr.StaticMethodCallExpression) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) MethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression) Expression(org.codehaus.groovy.ast.expr.Expression) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) ArgumentListExpression(org.codehaus.groovy.ast.expr.ArgumentListExpression) ExpressionStatement(org.codehaus.groovy.ast.stmt.ExpressionStatement)

Example 43 with MapExpression

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

the class GrabAnnotationTransformation method addGrabResolverAsStaticInitIfNeeded.

private void addGrabResolverAsStaticInitIfNeeded(ClassNode grapeClassNode, AnnotationNode node, List<Statement> grabResolverInitializers, Map<String, Object> grabResolverMap) {
    if ((node.getMember("initClass") == null) || (node.getMember("initClass") == ConstantExpression.TRUE)) {
        MapExpression resolverArgs = new MapExpression();
        for (Map.Entry<String, Object> next : grabResolverMap.entrySet()) {
            resolverArgs.addMapEntryExpression(new ConstantExpression(next.getKey()), new ConstantExpression(next.getValue()));
        }
        grabResolverInitializers.add(new ExpressionStatement(new StaticMethodCallExpression(grapeClassNode, "addResolver", new ArgumentListExpression(resolverArgs))));
    }
}
Also used : MapExpression(org.codehaus.groovy.ast.expr.MapExpression) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) ExpressionStatement(org.codehaus.groovy.ast.stmt.ExpressionStatement) StaticMethodCallExpression(org.codehaus.groovy.ast.expr.StaticMethodCallExpression) ArgumentListExpression(org.codehaus.groovy.ast.expr.ArgumentListExpression)

Aggregations

MapExpression (org.codehaus.groovy.ast.expr.MapExpression)43 Expression (org.codehaus.groovy.ast.expr.Expression)27 ConstantExpression (org.codehaus.groovy.ast.expr.ConstantExpression)23 MapEntryExpression (org.codehaus.groovy.ast.expr.MapEntryExpression)22 VariableExpression (org.codehaus.groovy.ast.expr.VariableExpression)22 MethodCallExpression (org.codehaus.groovy.ast.expr.MethodCallExpression)21 ClassExpression (org.codehaus.groovy.ast.expr.ClassExpression)19 ListExpression (org.codehaus.groovy.ast.expr.ListExpression)19 TupleExpression (org.codehaus.groovy.ast.expr.TupleExpression)19 ArgumentListExpression (org.codehaus.groovy.ast.expr.ArgumentListExpression)18 BinaryExpression (org.codehaus.groovy.ast.expr.BinaryExpression)18 ConstructorCallExpression (org.codehaus.groovy.ast.expr.ConstructorCallExpression)18 BlockStatement (org.codehaus.groovy.ast.stmt.BlockStatement)18 ClosureExpression (org.codehaus.groovy.ast.expr.ClosureExpression)16 DeclarationExpression (org.codehaus.groovy.ast.expr.DeclarationExpression)16 ClassNode (org.codehaus.groovy.ast.ClassNode)15 PropertyExpression (org.codehaus.groovy.ast.expr.PropertyExpression)15 ArrayExpression (org.codehaus.groovy.ast.expr.ArrayExpression)13 CastExpression (org.codehaus.groovy.ast.expr.CastExpression)13 StaticMethodCallExpression (org.codehaus.groovy.ast.expr.StaticMethodCallExpression)13