View Javadoc
Minimize
Table

Bug Overview

linebug prioritybugbug descriptionexisting sinceauthor
40mediumTODODer Code ist an dieser Stelle eventuell unfertig oder fehlerhaft. Bitte überprüfen!18.06.2012-10:31Unbekannt

1   /*
2    * Copyright 2003-2007 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Represents a list expression [1, 2, 3] which creates a mutable List
26   *
27   * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
28   * @version $Revision: 20590 $
29   */
30  public class ListExpression extends Expression {
31      private List<Expression> expressions;
32      private boolean wrapped = false;
33  
34      public ListExpression() {
35          this(new ArrayList<Expression>());
36      }
37  
38      public ListExpression(List<Expression> expressions) {
39          this.expressions = expressions;
40 bug overview            //TODO: get the type's of the expressions to specify the 
41          // list type to List<X> if possible.
42          setType(ClassHelper.LIST_TYPE);
43      }
44  
45      public void addExpression(Expression expression) {
46          expressions.add(expression);
47      }
48  
49      public List<Expression> getExpressions() {
50          return expressions;
51      }
52  
53      public void setWrapped(boolean value) {
54          wrapped = value;
55      }
56  
57      public boolean isWrapped() {
58          return wrapped;
59      }
60  
61      public void visit(GroovyCodeVisitor visitor) {
62          visitor.visitListExpression(this);
63      }
64  
65      public Expression transformExpression(ExpressionTransformer transformer) {
66          Expression ret = new ListExpression(transformExpressions(getExpressions(), transformer));
67          ret.setSourcePosition(this);
68          return ret;
69      }
70  
71      public Expression getExpression(int i) {
72          return expressions.get(i);
73      }
74  
75      public String getText() {
76          StringBuffer buffer = new StringBuffer("[");
77          boolean first = true;
78          for (Expression expression : expressions) {
79              if (first) {
80                  first = false;
81              } else {
82                  buffer.append(", ");
83              }
84  
85              buffer.append(expression.getText());
86          }
87          buffer.append("]");
88          return buffer.toString();
89      }
90  
91      public String toString() {
92          return super.toString() + expressions;
93      }
94  }