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));
}
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);
}
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))));
}
}
Aggregations