freemarker.template.expression
Class MethodCall

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

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

A unary operator that calls a TemplateMethodModel. It associates with other Variable expressions to its left.

Version:
$Id: MethodCall.java 1153 2013-04-15 10:59:37Z run2000 $
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface freemarker.template.expression.Unary
Unary.Association
 
Constructor Summary
MethodCall(java.util.List<Expression> arguments)
          Constructor that takes a List of Expressions to be evaluated at method call time.
 
Method Summary
 boolean equals(java.lang.Object o)
          Determines whether this object is equal to the given object.
 ListLiteral getArguments()
          Retrieve the Expressions to be evaluated at call time.
 Unary.Association getAssociationType()
          Retrieve the operator association for this operator.
 TemplateModel getAsTemplateModel(TemplateWriteableHashModel modelRoot)
          The TemplateModel value of this method call.
 java.lang.String getName(TemplateWriteableHashModel modelRoot)
          Retrieve the name of this portion of the variable.
 ExpressionBuilder.Precedence getPrecedence()
          Return the precedence for this operator to the caller.
 Expression getTarget()
          Retrieves the target of this MethodCall operator.
 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()
          Are both the target and the arguments 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 MethodCall operator.
 void setTemplateModel(TemplateWriteableHashModel modelRoot, TemplateModel value)
          A setter that calls a method model.
 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

MethodCall

public MethodCall(java.util.List<Expression> arguments)
Constructor that takes a List of Expressions to be evaluated at method call time.

Parameters:
arguments - a List of Expressions
Throws:
java.lang.NullPointerException - the argument list is null
Method Detail

getArguments

public ListLiteral getArguments()
Retrieve the Expressions to be evaluated at call time.

Returns:
a ListLiteral of arguments to be evaluated

getName

public java.lang.String getName(TemplateWriteableHashModel modelRoot)
                         throws TemplateException
Retrieve the name of this portion of the variable.

Specified by:
getName in interface Variable
Parameters:
modelRoot - the model to be used in cases where the variable is the result of an Expression.
Throws:
TemplateException - the name could not be determined

getAsTemplateModel

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

Specified by:
getAsTemplateModel in interface Expression
Parameters:
modelRoot - the template model that will be evaluated by the expression
Returns:
the TemplateModel returned by the method call
Throws:
TemplateException - the expression could not be evaluated for some reason

setTemplateModel

public void setTemplateModel(TemplateWriteableHashModel modelRoot,
                             TemplateModel value)
                      throws TemplateException
A setter that calls a method model. The value to be set is passed to the method as the last parameter. The return value is ignored.

Specified by:
setTemplateModel in interface Variable
Parameters:
modelRoot - the root model, for determining context
value - the value to be assigned
Throws:
TemplateException - there was a problem performing the assignment

isComplete

public boolean isComplete()
Are both the target and the arguments specified?

Specified by:
isComplete in interface Expression
Returns:
true if both target and arguments are 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()
Retrieve the operator association for this operator.

Specified by:
getAssociationType in interface Unary
Returns:
POSTFIX.

setTarget

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

Specified by:
setTarget in interface Unary
Throws:
java.lang.IllegalArgumentException - the target is of the wrong type for this operator.

getTarget

public Expression getTarget()
Retrieves the target of this MethodCall operator.

Returns:
an Expression representing the TemplateMethodModel to be called

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 enumeration 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()
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