View Javadoc
Minimize
Table

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.stmt;
17  
18  import org.codehaus.groovy.ast.ClassHelper;
19  import org.codehaus.groovy.ast.ClassNode;
20  import org.codehaus.groovy.ast.GroovyCodeVisitor;
21  import org.codehaus.groovy.ast.Parameter;
22  import org.codehaus.groovy.ast.VariableScope;
23  import org.codehaus.groovy.ast.expr.Expression;
24  
25  /**
26   * Represents a standard for loop in Groovy
27   * 
28   * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
29   * @version $Revision: 21246 $
30   */
31  public class ForStatement extends Statement implements LoopingStatement {
32      public static final Parameter FOR_LOOP_DUMMY = new Parameter(ClassHelper.OBJECT_TYPE,"forLoopDummyParameter");
33  
34      private Parameter variable;
35      private Expression collectionExpression;
36      private Statement loopBlock;
37      private VariableScope scope;
38      
39  
40      public ForStatement(Parameter variable, Expression collectionExpression, Statement loopBlock) {
41          this.variable = variable; 
42          this.collectionExpression = collectionExpression;
43          this.loopBlock = loopBlock;
44      }
45      
46      public void visit(GroovyCodeVisitor visitor) {
47          visitor.visitForLoop(this);
48      }
49      
50      public Expression getCollectionExpression() {
51          return collectionExpression;
52      }
53  
54      public Statement getLoopBlock() {
55          return loopBlock;
56      }
57  
58      public Parameter getVariable() {
59          return variable;
60      }
61      
62      public ClassNode getVariableType() {
63          return variable.getType();
64      }
65      
66      public void setCollectionExpression(Expression collectionExpression) {
67          this.collectionExpression = collectionExpression;
68      }
69  
70      public void setVariableScope(VariableScope variableScope) {
71         scope = variableScope;        
72      }
73  
74      public VariableScope getVariableScope() {
75          return scope;
76      }
77  
78      public void setLoopBlock(Statement loopBlock) {
79          this.loopBlock = loopBlock;
80      }
81  }