freemarker.template.expression
Class Lambda

java.lang.Object
  extended by freemarker.template.expression.Lambda
All Implemented Interfaces:
Expression, Operator, Unary, java.io.Serializable

public final class Lambda
extends java.lang.Object
implements Unary, java.io.Serializable

Implements a Lambda expression. A lambda evaluates to a method model, possibly anonymous, and takes the current template model root as its context. In this respect, a lambda evaluates to a closure.

Since:
1.9
Version:
$Id: Lambda.java 1162 2013-04-20 12:04:32Z run2000 $
Author:
Nicholas Cull
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface freemarker.template.expression.Unary
Unary.Association
 
Constructor Summary
Lambda(java.util.List<Identifier> arguments)
          Constructor that takes a list of arguments to be supplied to the lambda expression.
 
Method Summary
 boolean equals(java.lang.Object o)
          Determines whether this object is equal to the given object.
 Unary.Association getAssociationType()
          Determines the operator association of the unary operation.
 TemplateModel getAsTemplateModel(TemplateWriteableHashModel modelRoot)
          The TemplateModel value of this Expression.
 ExpressionBuilder.Precedence getPrecedence()
          Return the precedence for this operator to the caller.
 java.util.Set<ExpressionUtils.ExpressionType> getType()
          Determine the type of result that can be calculated by this expression.
 int hashCode()
          Returns the hash code for this operator.
 boolean isComplete()
          Is the target specified?
 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.
 void setTarget(Expression target)
          Sets the target of this lambda operator.
 java.lang.String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Lambda

public Lambda(java.util.List<Identifier> arguments)
Constructor that takes a list of arguments to be supplied to the lambda expression.

Parameters:
arguments - the list of variable arguments to be supplied to the lambda expression
Method Detail

getAsTemplateModel

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

Specified by:
getAsTemplateModel in interface 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

public boolean isComplete()
Is the target specified?

Specified by:
isComplete in interface Expression
Returns:
true if the target is specified, otherwise false

getType

public 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.

Specified by:
getType in interface Expression

isConstant

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

Specified by:
isConstant in interface Expression

getAssociationType

public Unary.Association getAssociationType()
Determines the operator association of the unary operation.

Specified by:
getAssociationType in interface Unary
Returns:
PREFIX or POSTFIX.

setTarget

public void setTarget(Expression target)
Sets the target of this lambda operator.

Specified by:
setTarget in interface Unary
Parameters:
target - the target of this operator
Throws:
java.lang.NullPointerException - the expression is null

getPrecedence

public ExpressionBuilder.Precedence getPrecedence()
Return the precedence for this operator to the caller. Used for associating operators according to precedence.

Specified by:
getPrecedence in interface Operator
Returns:
an integer indicating the precedence of this operator

toString

public java.lang.String toString()
Returns a string representation of the object.

Overrides:
toString in class java.lang.Object
Returns:
a String representation of this expression

equals

public boolean equals(java.lang.Object o)
Determines whether this object is equal to the given object.

Overrides:
equals in class java.lang.Object
Parameters:
o - the object to be compared with
Returns:
true if the objects are equal, otherwise false

hashCode

public int hashCode()
Returns the hash code for this operator.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code of this object

resolveExpression

public 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:

Specified by:
resolveExpression in interface Expression
Throws:
TemplateException