net.christopherschultz.evaluator
Class ArrayReferenceExpression

java.lang.Object
  extended by net.christopherschultz.evaluator.Expression
      extended by net.christopherschultz.evaluator.ArrayReferenceExpression

public class ArrayReferenceExpression
extends Expression

An expression describing an array reference.

Version:
$Revision: 1.2 $ $Date: 2008-06-20 22:58:48 $
Author:
Chris Schultz

Constructor Summary
ArrayReferenceExpression(Expression arrayExp, Expression indexExp)
          Creates a new ArrayReferenceExpression from the specified array and index expressions.
 
Method Summary
 void acceptVisitor(ExpressionVisitor visitor)
          Accepts an ExpressionVisitor.
 Object evaluate(EvaluationContext ec)
          Evaluates this Expression by evaluating the expression used for the array index, and then returning the element of the array at that location.
 Expression getArrayExpression()
          Gets the expression that will evaluate to an array.
 String getArrayName()
          Gets the name of the array, or <anonymous> if the array will be determined at runtime.
 Expression getIndexExpression()
          Gets the expression that will evaluate to an index into the array.
 List getSubExpressions()
          Gets a flattened, depth-first traversal of the expressions in this Expression (including this Expression).
 String toString()
           
 
Methods inherited from class net.christopherschultz.evaluator.Expression
getParent, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ArrayReferenceExpression

public ArrayReferenceExpression(Expression arrayExp,
                                Expression indexExp)
Creates a new ArrayReferenceExpression from the specified array and index expressions.

Parameters:
arrayExp - The expression that will evaluate to the array to index.
indexExp - The expression that will evaluate to the index of the array.
Method Detail

acceptVisitor

public void acceptVisitor(ExpressionVisitor visitor)
Description copied from class: Expression
Accepts an ExpressionVisitor.

Specified by:
acceptVisitor in class Expression

evaluate

public Object evaluate(EvaluationContext ec)
                throws EvaluationException
Evaluates this Expression by evaluating the expression used for the array index, and then returning the element of the array at that location.

Specified by:
evaluate in class Expression
Parameters:
ec - The context in which this function call should be evaluated.
Returns:
The element in the array at the location specified by the index.
Throws:
EvaluationException - If there is an error evaluating the index expression or locating the array element.

getArrayExpression

public Expression getArrayExpression()
Gets the expression that will evaluate to an array.


getIndexExpression

public Expression getIndexExpression()
Gets the expression that will evaluate to an index into the array.


getArrayName

public String getArrayName()
Gets the name of the array, or <anonymous> if the array will be determined at runtime.


getSubExpressions

public List getSubExpressions()
Description copied from class: Expression
Gets a flattened, depth-first traversal of the expressions in this Expression (including this Expression).

Specified by:
getSubExpressions in class Expression
Returns:
A List of sub-expressions for this Expression.

toString

public String toString()
Overrides:
toString in class Object