com.go.tea.parsetree
Class ForeachStatement

java.lang.Object
  |
  +--com.go.tea.parsetree.Node
        |
        +--com.go.tea.parsetree.Statement
              |
              +--com.go.tea.parsetree.ForeachStatement
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class ForeachStatement
extends Statement

A ForeachStatement iterates over the values of an array or a Collection, storing each value in a variable, allowing a statement or statements to operate on each. Reverse looping is supported for arrays and Lists.

Because Collections don't know the type of elements they contain (they only know that they are Objects), the only operations allowed on the loop variable are those that are defined for Object.

Collection class can be subclassed to contain a special field that defines the element type. The field must have the following signature: public static final Class ELEMENT_TYPE

Version:
30 , 9/07/00
Author:
Brian S O'Neill
See Also:
Serialized Form

Constructor Summary
ForeachStatement(SourceInfo info, VariableRef loopVar, Expression range, Expression endRange, boolean reverse, Block body)
           
 
Method Summary
 java.lang.Object accept(NodeVisitor visitor)
          Every subclass of Node must override this method with the following: return visitor.visit(this).
 java.lang.Object clone()
          Returns a clone of this Node and all its children.
 Block getBody()
           
 Expression getEndRange()
          Returns null if this foreach statement iterates over an array/collection instead of an integer range of values.
 Statement getInitializer()
          Initializer is a section of code that executes before the loop is entered.
 VariableRef getLoopVariable()
           
 Expression getRange()
           
 boolean isReverse()
           
 void setBody(Block body)
           
 void setEndRange(Expression endRange)
           
 void setInitializer(Statement stmt)
           
 void setRange(Expression range)
           
 
Methods inherited from class com.go.tea.parsetree.Statement
isBreak, isReturn
 
Methods inherited from class com.go.tea.parsetree.Node
getSourceInfo, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ForeachStatement

public ForeachStatement(SourceInfo info,
                        VariableRef loopVar,
                        Expression range,
                        Expression endRange,
                        boolean reverse,
                        Block body)
Method Detail

accept

public java.lang.Object accept(NodeVisitor visitor)
Description copied from class: Node
Every subclass of Node must override this method with the following: return visitor.visit(this).
Overrides:
accept in class Statement
Following copied from class: com.go.tea.parsetree.Node
Parameters:
visitor - A visitor of this Node
Returns:
Node The Node returned by the visitor
See Also:
NodeVisitor

clone

public java.lang.Object clone()
Description copied from class: Node
Returns a clone of this Node and all its children. Immutable child objects are not necessarily cloned
Overrides:
clone in class Node

getLoopVariable

public VariableRef getLoopVariable()

getRange

public Expression getRange()

getEndRange

public Expression getEndRange()
Returns null if this foreach statement iterates over an array/collection instead of an integer range of values.

isReverse

public boolean isReverse()

getInitializer

public Statement getInitializer()
Initializer is a section of code that executes before the loop is entered. By default, it is null. A type checker may define an initializer.

getBody

public Block getBody()

setRange

public void setRange(Expression range)

setEndRange

public void setEndRange(Expression endRange)

setInitializer

public void setInitializer(Statement stmt)

setBody

public void setBody(Block body)