1 46 package org.codehaus.groovy.ast.expr; 47 48 import java.util.ArrayList ; 49 import java.util.List ; 50 import java.util.Map ; 51 52 import org.codehaus.groovy.ast.GroovyCodeVisitor; 53 import org.codehaus.groovy.classgen.AsmClassGenerator2; 54 55 61 public class MapExpression extends Expression { 62 private List mapEntryExpressions; 63 64 public MapExpression() { 65 this(new ArrayList ()); 66 } 67 68 public MapExpression(List mapEntryExpressions) { 69 this.mapEntryExpressions = mapEntryExpressions; 70 } 71 72 public void addMapEntryExpression(MapEntryExpression expression) { 73 mapEntryExpressions.add(expression); 74 } 75 76 public List getMapEntryExpressions() { 77 return mapEntryExpressions; 78 } 79 80 public void visit(GroovyCodeVisitor visitor) { 81 visitor.visitMapExpression(this); 82 } 83 84 public boolean isDynamic() { 85 return false; } 87 88 public Expression transformExpression(ExpressionTransformer transformer) { 89 return new MapExpression(transformExpressions(getMapEntryExpressions(), transformer)); 90 } 91 92 public String toString() { 93 return super.toString() + mapEntryExpressions; 94 } 95 96 public void addMapEntryExpression(Expression keyExpression, Expression valueExpression) { 97 addMapEntryExpression(new MapEntryExpression(keyExpression, valueExpression)); 98 } 99 100 protected void resolveType(AsmClassGenerator2 resolver) { 101 for (int i = 0; i < mapEntryExpressions.size(); i++) { 102 MapEntryExpression mapEntryExpression = (MapEntryExpression) mapEntryExpressions.get(i); 103 mapEntryExpression.resolve(resolver); 104 } 105 super.setTypeClass(Map .class); 106 } 107 } 108 | Popular Tags |