Minimize
Table
Bug Overview
line | bug priority | bug | bug description | existing since | author |
---|
39 | medium | TODO | Der Code ist an dieser Stelle eventuell unfertig oder fehlerhaft. Bitte überprüfen! | 18.06.2012-10:31 | Unbekannt |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codehaus.groovy.ast.expr;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.codehaus.groovy.ast.ClassHelper;
22 import org.codehaus.groovy.ast.GroovyCodeVisitor;
23
24
25
26
27
28
29
30 public class MapExpression extends Expression {
31 private final List<MapEntryExpression> mapEntryExpressions;
32
33 public MapExpression() {
34 this(new ArrayList<MapEntryExpression>());
35 }
36
37 public MapExpression(List<MapEntryExpression> mapEntryExpressions) {
38 this.mapEntryExpressions = mapEntryExpressions;
39
40
41 setType(ClassHelper.MAP_TYPE);
42 }
43
44 public void addMapEntryExpression(MapEntryExpression expression) {
45 mapEntryExpressions.add(expression);
46 }
47
48 public List<MapEntryExpression> getMapEntryExpressions() {
49 return mapEntryExpressions;
50 }
51
52 public void visit(GroovyCodeVisitor visitor) {
53 visitor.visitMapExpression(this);
54 }
55
56 public boolean isDynamic() {
57 return false;
58 }
59
60 public Expression transformExpression(ExpressionTransformer transformer) {
61 Expression ret = new MapExpression(transformExpressions(getMapEntryExpressions(), transformer, MapEntryExpression.class));
62 ret.setSourcePosition(this);
63 return ret;
64 }
65
66 public String toString() {
67 return super.toString() + mapEntryExpressions;
68 }
69
70 public String getText() {
71 StringBuffer sb = new StringBuffer(32);
72 sb.append("[");
73 int size = mapEntryExpressions.size();
74 MapEntryExpression mapEntryExpression = null;
75 if (size > 0) {
76 mapEntryExpression = mapEntryExpressions.get(0);
77 sb.append(mapEntryExpression.getKeyExpression().getText() + ":" + mapEntryExpression.getValueExpression().getText());
78 for (int i = 1; i < size; i++) {
79 mapEntryExpression = mapEntryExpressions.get(i);
80 sb.append(", " + mapEntryExpression.getKeyExpression().getText() + ":" + mapEntryExpression.getValueExpression().getText());
81 if (sb.length() > 120 && i < size - 1) {
82 sb.append(", ... ");
83 break;
84 }
85 }
86 } else {
87 sb.append(":");
88 }
89 sb.append("]");
90 return sb.toString();
91 }
92
93 public void addMapEntryExpression(Expression keyExpression, Expression valueExpression) {
94 addMapEntryExpression(new MapEntryExpression(keyExpression, valueExpression));
95 }
96
97 }