freemarker.template.expression
Interface Expression

All Known Subinterfaces:
Binary, Operator, Unary, Variable
All Known Implementing Classes:
AbstractBinary, And, BooleanLiteral, Constant, Divide, Dot, DynamicKeyName, EmptyLiteral, Equals, GreaterThan, GreaterThanOrEquals, HashLiteral, Identifier, Lambda, LessThan, LessThanOrEquals, ListLiteral, ListRange, MethodCall, Minus, Modulo, Multiply, Not, NotEquals, NumberLiteral, Or, Plus, StringLiteral, Ternary

public interface Expression

An Expression can return a TemplateModel value. An expression is used whenever we want to interact with the template models. An expression can be simple, such as an identifier, or more complex, such as a dynamic key name or a concatenation operator.

Expressions can be (in fact, usually are) nested. For instance, a comparison of two concatenation operations may be represented as follows:

                         Equals
                           |
          +----------------+---------------+
          |                                |
          |Plus                            | Plus
     +----+----+                     +-----+-----+
     |         |                     |           |
     |         |                     |           |
 identifier identifier           identifier      + dynamic-key-name
                                                 |
                                                 |
                                                 + identifier
 

Each node on the tree represents a different expression object.

Once complete (i.e. parsed), expressions should be considered immutable.

Version:
$Id: Expression.java 1101 2013-04-01 04:17:32Z run2000 $

Method Summary
 TemplateModel getAsTemplateModel(TemplateWriteableHashModel modelRoot)
          The TemplateModel value of this Expression.
 java.util.Set<ExpressionUtils.ExpressionType> getType()
          Determine the type of result that can be calculated by this expression.
 boolean isComplete()
          Is the Expression complete?
 boolean isConstant()
          Determine whether result calculated by this expression is a constant value.
 Expression resolveExpression()
          Resolves the current expression, possibly into a different expression object.
 

Method Detail

getAsTemplateModel

TemplateModel getAsTemplateModel(TemplateWriteableHashModel modelRoot)
                                 throws TemplateException
The TemplateModel value of this Expression.

Parameters:
modelRoot - the template model that will be evaluated by the expression
Throws:
TemplateException - the expression could not be evaluated for some reason

isComplete

boolean isComplete()
Is the Expression complete?

Returns:
true if this Expression is complete, otherwise false

getType

java.util.Set<ExpressionUtils.ExpressionType> getType()
Determine the type of result that can be calculated by this expression. This is in the form of an integer constant ored together from values in the ExpressionUtils class.


isConstant

boolean isConstant()
Determine whether result calculated by this expression is a constant value.


resolveExpression

Expression resolveExpression()
                             throws TemplateException
Resolves the current expression, possibly into a different expression object. This is loosely equivalent to the serialization protocol's readResolve method. Situations where this may be used are:

Throws:
TemplateException