Top Description Fields Constructors Methods
org.springframework.expression.spel.ast

public Class FunctionReference

extends SpelNodeImpl
Class Inheritance
Imports
java.lang.invoke.MethodHandle, .MethodType, java.lang.reflect.Method, .Modifier, java.util.StringJoiner, org.springframework.asm.MethodVisitor, org.springframework.core.MethodParameter, org.springframework.core.convert.TypeDescriptor, org.springframework.expression.EvaluationException, .TypeConverter, .TypedValue, org.springframework.expression.spel.CodeFlow, .ExpressionState, .SpelEvaluationException, .SpelMessage, org.springframework.expression.spel.support.ReflectionHelper, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .ReflectionUtils

A function reference is of the form "#someFunction(a,b,c)".

Functions can be either a Method (for static Java methods) or a MethodHandle and must be registered in the context prior to evaluation of the expression. See the registerFunction() methods in org.springframework.expression.spel.support.StandardEvaluationContext for details.

Authors
Andy Clement, Juergen Hoeller, Simon Baslé, Sam Brannen
Since
3.0
See Also
org.springframework.expression.spel.support.StandardEvaluationContext#registerFunction(String, Method), org.springframework.expression.spel.support.StandardEvaluationContext#registerFunction(String, MethodHandle)

Field Summary

Modifier and TypeField and Description
private volatile Method
private final String
Inherited from org.springframework.expression.spel.ast.SpelNodeImpl:
childrenexitTypeDescriptor

Constructor Summary

AccessConstructor and Description
public
FunctionReference(String functionName, int startPos, int endPos, SpelNodeImpl... arguments)

Method Summary

Modifier and TypeMethod and Description
private TypedValue

Returns:

the return value of the invoked Java method
executeFunctionViaMethod
(ExpressionState
the expression evaluation state
state
,
Method
the method to invoke
method
)

Execute a function represented as a Method.

private TypedValue

Returns:

the return value of the invoked Java method
executeFunctionViaMethodHandle
(ExpressionState
the expression evaluation state
state
,
MethodHandle
the method handle to invoke
methodHandle
)

Execute a function represented as MethodHandle.

public void
generateCode(MethodVisitor
the ASM MethodVisitor into which code should be generated
mv
,
CodeFlow
a context object with info about what is on the stack
cf
)

Overrides org.springframework.expression.spel.ast.SpelNodeImpl.generateCode.

Generate the bytecode for this node into the supplied visitor.
private Object[]

Returns:

an array of argument values for the function call
getArguments
(ExpressionState state)

Compute the arguments to the function, they are the children of this expression node.

public TypedValue
public boolean
isCompilable()

Overrides org.springframework.expression.spel.ast.SpelNodeImpl.isCompilable.

Check whether a node can be compiled to bytecode.
public String
toStringAST()

Implements org.springframework.expression.spel.SpelNode.toStringAST.

Return the string form of this AST node.
Inherited from org.springframework.expression.spel.ast.SpelNodeImpl:
generateCodeForArgumentgenerateCodeForArgumentsgetChildgetChildCountgetEndPositiongetExitDescriptorgetObjectClassgetStartPositiongetTypedValuegetValuegetValuegetValueRefisWritablenextChildIssetValuesetValueInternal

Field Detail

methodback to summary
private volatile Method method
Annotations
@Nullable
nameback to summary
private final String name

Constructor Detail

FunctionReferenceback to summary
public FunctionReference(String functionName, int startPos, int endPos, SpelNodeImpl... arguments)

Method Detail

executeFunctionViaMethodback to summary
private TypedValue executeFunctionViaMethod(ExpressionState state, Method method) throws EvaluationException

Execute a function represented as a Method.

Parameters
state:ExpressionState

the expression evaluation state

method:Method

the method to invoke

Returns:TypedValue

the return value of the invoked Java method

Exceptions
EvaluationException:
if there is any problem invoking the method
executeFunctionViaMethodHandleback to summary
private TypedValue executeFunctionViaMethodHandle(ExpressionState state, MethodHandle methodHandle) throws EvaluationException

Execute a function represented as MethodHandle.

Method types that take no arguments (fully bound handles or static methods with no parameters) can use MethodHandle#invoke() which is the most efficient. Otherwise, MethodHandle#invokeWithArguments() is used.

Parameters
state:ExpressionState

the expression evaluation state

methodHandle:MethodHandle

the method handle to invoke

Returns:TypedValue

the return value of the invoked Java method

Exceptions
EvaluationException:
if there is any problem invoking the method
Since
6.1
generateCodeback to summary
public void generateCode(MethodVisitor mv, CodeFlow cf)

Overrides org.springframework.expression.spel.ast.SpelNodeImpl.generateCode.

Doc from org.springframework.expression.spel.ast.SpelNodeImpl.generateCode.

Generate the bytecode for this node into the supplied visitor. Context info about the current expression being compiled is available in the codeflow object, e.g. including information about the type of the object currently on the stack.

Parameters
mv:MethodVisitor

the ASM MethodVisitor into which code should be generated

cf:CodeFlow

a context object with info about what is on the stack

Annotations
@Override
getArgumentsback to summary
private Object[] getArguments(ExpressionState state) throws EvaluationException

Compute the arguments to the function, they are the children of this expression node.

Returns:Object[]

an array of argument values for the function call

getValueInternalback to summary
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException

Implements abstract org.springframework.expression.spel.ast.SpelNodeImpl.getValueInternal.

Annotations
@Override
isCompilableback to summary
public boolean isCompilable()

Overrides org.springframework.expression.spel.ast.SpelNodeImpl.isCompilable.

Doc from org.springframework.expression.spel.ast.SpelNodeImpl.isCompilable.

Check whether a node can be compiled to bytecode. The reasoning in each node may be different but will typically involve checking whether the exit type descriptor of the node is known and any relevant child nodes are compilable.

Returns:boolean

true if this node can be compiled to bytecode

Annotations
@Override
toStringASTback to summary
public String toStringAST()

Implements org.springframework.expression.spel.SpelNode.toStringAST.

Doc from org.springframework.expression.spel.SpelNode.toStringAST.

Return the string form of this AST node.

Returns:String

the string form

Annotations
@Override