Class Script
- All Implemented Interfaces:
JexlExpression,JexlScript
- Direct Known Subclasses:
Closure
A JexlScript implementation.
- Since:
- 1.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassImplements the Future and Callable interfaces to help delegation. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final EngineThe engine for this expression.protected final ASTJexlScriptThe resulting AST we can interpret.protected final StringOriginal expression stripped from leading and trailing spaces.protected intThe engine version (as class loader change count) that last evaluated this script. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedScript(Engine engine, String expr, ASTJexlScript ref) Do not let this be generally instantiated with a 'new'. -
Method Summary
Modifier and TypeMethodDescriptioncallable(JexlContext context) Creates a Callable from this script.callable(JexlContext context, Object... args) Creates a Callable from this script.protected voidChecks that this script cached methods (wrt introspection) matches the engine version.protected FramecreateFrame(Object[] args) Creates this script frame for evaluation.protected InterpretercreateInterpreter(JexlContext context, Frame frame) Creates this script interpreter.protected InterpretercreateInterpreter(JexlContext context, Frame frame, JexlOptions options) Creates this script interpreter.Curries this script, returning a script with bound arguments.booleanevaluate(JexlContext context) Evaluates the expression with the variables contained in the suppliedJexlContext.execute(JexlContext context) Executes the script with the variables contained in the suppliedJexlContext.execute(JexlContext context, Object... args) Executes the script with the variables contained in the suppliedJexlContextand a set of arguments corresponding to the parameters used during parsing.String[]Gets this script captured variable, i.e.getInfo()String[]Gets this script local variables.String[]Gets this script parameters.Recreates the source text of this expression from the internal syntactic tree.getParsedText(int indent) Recreates the source text of this expression from the internal syntactic tree.Gets this script pragmasprotected ASTJexlScriptReturns the source text of this expression.String[]Gets this script unbound parameters.Gets this script variables.inthashCode()toString()
-
Field Details
-
jexl
The engine for this expression. -
source
Original expression stripped from leading and trailing spaces. -
script
The resulting AST we can interpret. -
version
protected int versionThe engine version (as class loader change count) that last evaluated this script.
-
-
Constructor Details
-
Script
Do not let this be generally instantiated with a 'new'.- Parameters:
engine- the interpreter to evaluate the expressionexpr- the expression source.ref- the parsed expression.
-
-
Method Details
-
callable
Creates a Callable from this script.This allows to submit it to an executor pool and provides support for asynchronous calls.
The interpreter will handle interruption/cancellation gracefully if needed.
- Specified by:
callablein interfaceJexlExpression- Specified by:
callablein interfaceJexlScript- Parameters:
context- the context- Returns:
- the callable
-
callable
Creates a Callable from this script.This allows to submit it to an executor pool and provides support for asynchronous calls.
The interpreter will handle interruption/cancellation gracefully if needed.
- Specified by:
callablein interfaceJexlScript- Parameters:
context- the contextargs- the script arguments- Returns:
- the callable
-
checkCacheVersion
protected void checkCacheVersion()Checks that this script cached methods (wrt introspection) matches the engine version.If the engine class loader has changed since we last evaluated this script, the script local cache is invalidated to drop references to obsolete methods. It is not strictly necessary since the tryExecute will fail because the class won't match but it seems cleaner nevertheless.
-
createFrame
Creates this script frame for evaluation.- Parameters:
args- the arguments to bind to parameters- Returns:
- the frame (may be null)
-
createInterpreter
Creates this script interpreter.- Parameters:
context- the contextframe- the calling frame- Returns:
- the interpreter
-
createInterpreter
Creates this script interpreter.- Parameters:
context- the contextframe- the calling frameoptions- the interpreter options- Returns:
- the interpreter
-
curry
Description copied from interface:JexlScriptCurries this script, returning a script with bound arguments.If this script does not declare parameters or if all of them are already bound, no error is generated and this script is returned.
- Specified by:
curryin interfaceJexlScript- Parameters:
args- the arguments to bind- Returns:
- the curried script or this script if no binding can occur
-
equals
-
evaluate
Description copied from interface:JexlExpressionEvaluates the expression with the variables contained in the suppliedJexlContext.- Specified by:
evaluatein interfaceJexlExpression- Parameters:
context- A JexlContext containing variables.- Returns:
- The result of this evaluation
-
execute
Description copied from interface:JexlScriptExecutes the script with the variables contained in the suppliedJexlContext.- Specified by:
executein interfaceJexlScript- Parameters:
context- A JexlContext containing variables.- Returns:
- The result of this script, usually the result of the last statement.
-
execute
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- Parameters:
context- A JexlContext containing variables.args- the arguments- Returns:
- The result of this script, usually the result of the last statement.
-
getCapturedVariables
Gets this script captured variable, i.e. symbols captured from outer scopes.- Returns:
- the captured variable names
-
getEngine
- Returns:
- the engine that created this script
-
getFeatures
- Returns:
- the script features
-
getInfo
- Returns:
- the info
-
getLocalVariables
Description copied from interface:JexlScriptGets this script local variables.- Specified by:
getLocalVariablesin interfaceJexlScript- Returns:
- the local variables or null
-
getParameters
Description copied from interface:JexlScriptGets this script parameters.- Specified by:
getParametersin interfaceJexlScript- Returns:
- the parameters or null
-
getParsedText
Description copied from interface:JexlScriptRecreates the source text of this expression from the internal syntactic tree.- Specified by:
getParsedTextin interfaceJexlExpression- Specified by:
getParsedTextin interfaceJexlScript- Returns:
- the source text
-
getParsedText
Description copied from interface:JexlScriptRecreates the source text of this expression from the internal syntactic tree.- Specified by:
getParsedTextin interfaceJexlScript- Parameters:
indent- the number of spaces for indentation, 0 meaning no indentation- Returns:
- the source text
-
getPragmas
Gets this script pragmasPragma keys are ant-ish variables, their values are scalar literals..
- Specified by:
getPragmasin interfaceJexlScript- Returns:
- the pragmas
-
getScript
- Returns:
- the script AST
-
getSourceText
Description copied from interface:JexlScriptReturns the source text of this expression.- Specified by:
getSourceTextin interfaceJexlExpression- Specified by:
getSourceTextin interfaceJexlScript- Returns:
- the source text
-
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- Returns:
- the parameters or null
-
getVariables
Gets this script variables.Note that since variables can be in an ant-ish form (ie foo.bar.quux), each variable is returned as a list of strings where each entry is a fragment of the variable ({"foo", "bar", "quux"} in the example.
- Specified by:
getVariablesin interfaceJexlScript- Returns:
- the variables or null
-
hashCode
public int hashCode() -
toString
-