org.outerj.expression
Interface Expression

All Known Implementing Classes:
AbstractExpression, DecimalConstantFunction, StringConstantFunction, VariableFunction

public interface Expression

An expression is something that can be evaluated. Expression objects are structured in a tree which is (usually) created by the FormulaParser (see FormulaParser.jj).


Method Summary
 void addArgument(Expression expression)
          Add an argument to this expression.
 void addArgument(int index, Expression expression)
          Add an argument to this expression.
 void check()
          Check if the expression's structure is OK.
 java.lang.Object evaluate(ExpressionContext context)
          Evaluates this expression and returns the result of that evaluation.
 int getColumn()
          Returns the column number where this expression occurs.
 java.lang.String getDescription()
          Returns a description of this expression that will be shown to the user in error messages.
 int getLine()
          Returns the line number where this expression occurs.
 java.lang.Class getResultType()
          Returns the class of the the type of object that this expression will return.
 void setPosition(int line, int column)
          Called by the parser to set the position of this expression.
 

Method Detail

addArgument

public void addArgument(Expression expression)
Add an argument to this expression. The argument itself is also an expression. The expression can check the validity of its arguments in the check() method.


addArgument

public void addArgument(int index,
                        Expression expression)
Add an argument to this expression. The argument itself is also an expression. The expression can check the validity of its arguments in the check() method.


evaluate

public java.lang.Object evaluate(ExpressionContext context)
                          throws ExpressionException
Evaluates this expression and returns the result of that evaluation.

Throws:
ExpressionException

check

public void check()
           throws ExpressionException
Check if the expression's structure is OK. If everything is ok, this method should just return.

Throws:
ExpressionException - to indicate the expression-syntax error.

getResultType

public java.lang.Class getResultType()
Returns the class of the the type of object that this expression will return. This allows to check the correctness of functions at compile-time. If unknown, this may return null.


getLine

public int getLine()
Returns the line number where this expression occurs.


getColumn

public int getColumn()
Returns the column number where this expression occurs.


setPosition

public void setPosition(int line,
                        int column)
Called by the parser to set the position of this expression.


getDescription

public java.lang.String getDescription()
Returns a description of this expression that will be shown to the user in error messages.