Class Closure
- java.lang.Object
-
- org.apache.commons.jexl3.internal.Script
-
- org.apache.commons.jexl3.internal.Closure
-
- All Implemented Interfaces:
JexlExpression,JexlScript
public class Closure extends Script
A Script closure.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.commons.jexl3.internal.Script
Script.Callable
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedClosure(Interpreter theCaller, ASTJexlLambda lambda)Creates a closure.protectedClosure(Script base, java.lang.Object[] args)Creates a curried version of a script.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Script.Callablecallable(JexlContext context, java.lang.Object... args)Creates a Callable from this script.(package private) voidcaptureSelfIfRecursive(Frame parentFrame, int symbol)Enable lambda recursion.booleanequals(java.lang.Object obj)java.lang.Objectevaluate(JexlContext context)Evaluates the expression with the variables contained in the suppliedJexlContext.java.lang.Objectexecute(JexlContext context)Executes the script with the variables contained in the suppliedJexlContext.java.lang.Objectexecute(JexlContext context, java.lang.Object... args)Executes the script with the variables contained in the suppliedJexlContextand a set of arguments corresponding to the parameters used during parsing.java.lang.String[]getUnboundParameters()Gets this script unbound parameters.inthashCode()-
Methods inherited from class org.apache.commons.jexl3.internal.Script
callable, checkCacheVersion, createFrame, createInterpreter, createInterpreter, curry, getCapturedVariables, getEngine, getFeatures, getInfo, getLocalVariables, getParameters, getParsedText, getParsedText, getPragmas, getScript, getSourceText, getVariables, toString
-
-
-
-
Field Detail
-
frame
protected final Frame frame
The frame.
-
options
protected final JexlOptions options
The options.
-
-
Constructor Detail
-
Closure
protected Closure(Interpreter theCaller, ASTJexlLambda lambda)
Creates a closure.- Parameters:
theCaller- the calling interpreterlambda- the lambda
-
Closure
protected Closure(Script base, java.lang.Object[] args)
Creates a curried version of a script.- Parameters:
base- the base scriptargs- the script arguments
-
-
Method Detail
-
callable
public Script.Callable callable(JexlContext context, java.lang.Object... args)
Description copied from class:ScriptCreates a Callable from this script.This allows submitting it to an executor pool and provides support for asynchronous calls.
The interpreter will handle interruption/cancellation gracefully if needed.
- Specified by:
callablein interfaceJexlScript- Overrides:
callablein classScript- Parameters:
context- the contextargs- the script arguments- Returns:
- the callable
-
captureSelfIfRecursive
void captureSelfIfRecursive(Frame parentFrame, int symbol)
Enable lambda recursion.Assign this lambda in its own frame if the symbol it is assigned to in its definition scope is captured in its body.
This done allow a locally defined function to "see" and call itself as a local (captured) variable.
Typical case is:const f = (x)->x <= 0? 1 : x*f(x-1). Since assignment of f occurs after the lambda creation, we need to patch the lambda frame to expose itself through the captured symbol.- Parameters:
parentFrame- the parent calling framesymbol- the symbol index (in the caller of this closure)
-
evaluate
public java.lang.Object evaluate(JexlContext context)
Description copied from interface:JexlExpressionEvaluates the expression with the variables contained in the suppliedJexlContext.- Specified by:
evaluatein interfaceJexlExpression- Overrides:
evaluatein classScript- Parameters:
context- A JexlContext containing variables.- Returns:
- The result of this evaluation
-
execute
public java.lang.Object execute(JexlContext context)
Description copied from interface:JexlScriptExecutes the script with the variables contained in the suppliedJexlContext.- Specified by:
executein interfaceJexlScript- Overrides:
executein classScript- Parameters:
context- A JexlContext containing variables.- Returns:
- The result of this script, usually the result of the last statement.
-
execute
public java.lang.Object execute(JexlContext context, java.lang.Object... args)
Description copied from interface:JexlScriptExecutes the script with the variables contained in the suppliedJexlContextand a set of arguments corresponding to the parameters used during parsing.- Specified by:
executein interfaceJexlScript- Overrides:
executein classScript- Parameters:
context- A JexlContext containing variables.args- the arguments- Returns:
- The result of this script, usually the result of the last statement.
-
getUnboundParameters
public java.lang.String[] getUnboundParameters()
Description copied from interface:JexlScriptGets this script unbound parameters.Parameters that haven't been bound by a previous call to curry().
- Specified by:
getUnboundParametersin interfaceJexlScript- Overrides:
getUnboundParametersin classScript- Returns:
- the parameters or null
-
-