Class InterpreterBase
- Direct Known Subclasses:
Interpreter
- Since:
- 3.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
Cached arithmetic function call.protected class
Helping dispatch function calls.protected static class
Cached context function call.protected static class
A ctor that needs a context as 1st argument.protected static class
Cached function call. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final JexlArithmetic
The arithmetic handler.protected final boolean
Cache executors.protected final AtomicBoolean
Cancellation support.protected final JexlContext
The context to store/retrieve variables.protected static final Object[]
Empty parameters for method matching.protected final JexlContext.ClassNameResolver
The class name resolver.The map of 'prefix:function' to object resolving as namespaces.The map of dynamically created namespaces, NamespaceFunctor or duck-types of those.protected final Engine
The JEXL engine.protected final org.apache.commons.logging.Log
The logger.protected final JexlContext.NamespaceResolver
The namespace resolver.protected final Operators
The operators evaluation delegate.protected final JexlOptions
The options.protected final JexlUberspect
The uberspect. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
InterpreterBase
(Engine engine, JexlOptions opts, JexlContext aContext) Creates an interpreter base.protected
InterpreterBase
(InterpreterBase ii, JexlArithmetic jexla) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected Object
annotationError
(JexlNode node, String annotation, Throwable cause) Triggered when an annotation processing fails.protected Object[]
callArguments
(Object target, boolean narrow, Object[] args) Concatenate arguments in call(...).protected boolean
cancel()
Cancels this evaluation, setting the cancel flag that will result in a JexlException.Cancel to be thrown.protected void
cancelCheck
(JexlNode node) Throws a JexlException.Cancel if script execution was cancelled.protected void
closeIfSupported
(Object closeable) Attempt to call close() if supported.protected boolean
defineVariable
(ASTVar var, LexicalFrame frame) Defines a variable.protected JexlNode
findNullOperand
(RuntimeException xrt, JexlNode node, Object left, Object right) Deprecated.protected JexlNode
findNullOperand
(JexlNode node, Object left, Object right) Finds the node causing a NPE for diadic operators.protected Object
functionArgument
(boolean narrow, Object arg) Optionally narrows an argument for a function call.protected Object[]
functionArguments
(Object target, boolean narrow, Object[] args) Concatenate arguments in call(...).protected Object
getAttribute
(Object object, Object attribute, JexlNode node) Gets an attribute of an object.protected Object
getVariable
(Frame frame, LexicalScope block, ASTIdentifier identifier) Gets a value of a defined local variable or from the context.protected JexlException
invocationException
(JexlNode node, String methodName, Throwable xany) Triggered when method, function or constructor invocation fails with an exception.protected boolean
protected boolean
Checks whether this interpreter execution was cancelled due to thread interruption.protected boolean
isSafe()
Whether this interpreter ignores null in navigation expression as errors.protected boolean
isSilent()
Whether this interpreter is currently evaluating with a silent mode.protected boolean
Whether this interpreter is currently evaluating with a strict engine flag.protected boolean
isStrictOperand
(JexlNode node) protected boolean
isTernaryProtected
(JexlNode node) Check if a null evaluated expression is protected by a ternary expression.protected boolean
isVariableDefined
(Frame frame, LexicalScope block, String name) Checks whether a variable is defined.protected Object
operatorError
(JexlNode node, JexlOperator operator, Throwable cause) Triggered when an operator fails.protected Object
redefinedVariable
(JexlNode node, String var) Triggered when a variable is lexically known as being redefined.protected Object
resolveNamespace
(String prefix, JexlNode node) Resolves a namespace, eventually allocating an instance using context as constructor argument.protected void
setAttribute
(Object object, Object attribute, Object value, JexlNode node) Sets an attribute of an object.protected void
setContextVariable
(JexlNode node, String name, Object value) Sets a variable in the global context.protected String
stringifyProperty
(JexlNode node) Pretty-prints a failing property (de)reference.protected static String
Pretty-prints a failing property value (de)reference.protected Object
undefinedVariable
(JexlNode node, String var) Triggered when a variable is lexically known as undefined.protected Object
unsolvableMethod
(JexlNode node, String method) Triggered when a method can not be resolved.protected Object
unsolvableMethod
(JexlNode node, String method, Object[] args) Triggered when a method can not be resolved.protected Object
unsolvableProperty
(JexlNode node, String property, boolean undef, Throwable cause) Triggered when a property can not be resolved.protected Object
unsolvableVariable
(JexlNode node, String var, boolean undef) Triggered when a variable can not be resolved.protected Object
variableError
(JexlNode node, String var, JexlException.VariableIssue issue) Triggered when a variable generates an issue.Methods inherited from class org.apache.commons.jexl3.parser.ParserVisitor
visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit
-
Field Details
-
jexl
The JEXL engine. -
logger
protected final org.apache.commons.logging.Log loggerThe logger. -
uberspect
The uberspect. -
arithmetic
The arithmetic handler. -
context
The context to store/retrieve variables. -
options
The options. -
cache
protected final boolean cacheCache executors. -
cancelled
Cancellation support. -
EMPTY_PARAMS
Empty parameters for method matching. -
ns
The namespace resolver. -
fqcnSolver
The class name resolver. -
operators
The operators evaluation delegate. -
functions
The map of 'prefix:function' to object resolving as namespaces. -
functors
The map of dynamically created namespaces, NamespaceFunctor or duck-types of those.
-
-
Constructor Details
-
InterpreterBase
Creates an interpreter base.- Parameters:
engine
- the engine creating this interpreteropts
- the evaluation optionsaContext
- the evaluation context
-
InterpreterBase
Copy constructor.- Parameters:
ii
- the base to copyjexla
- the arithmetic instance to use (or null)
-
-
Method Details
-
closeIfSupported
Attempt to call close() if supported.This is used when dealing with auto-closeable (duck-like) objects
- Parameters:
closeable
- the object we'd like to close
-
isStrictOperand
- Parameters:
node
- the operand node- Returns:
- true if this node is an operand of a strict operator, false otherwise
-
resolveNamespace
Resolves a namespace, eventually allocating an instance using context as constructor argument.The lifetime of such instances span the current expression or script evaluation.
- Parameters:
prefix
- the prefix name (can be null for global namespace)node
- the AST node- Returns:
- the namespace instance
-
defineVariable
Defines a variable.- Parameters:
var
- the variable to defineframe
- the frame in which it will be defined- Returns:
- true if definition succeeded, false otherwise
-
isVariableDefined
Checks whether a variable is defined.The var may be either a local variable declared in the frame and visible from the block or defined in the context.
- Parameters:
frame
- the frameblock
- the blockname
- the variable name- Returns:
- true if variable is defined, false otherwise
-
getVariable
Gets a value of a defined local variable or from the context.- Parameters:
frame
- the local frameblock
- the lexical block if anyidentifier
- the variable node- Returns:
- the value
-
setContextVariable
Sets a variable in the global context.If interpretation applies lexical shade, the variable must exist (ie the context has(...) method returns true) otherwise an error occurs.
- Parameters:
node
- the nodename
- the variable namevalue
- the variable value
-
isStrictEngine
protected boolean isStrictEngine()Whether this interpreter is currently evaluating with a strict engine flag.- Returns:
- true if strict engine, false otherwise
-
isSafe
protected boolean isSafe()Whether this interpreter ignores null in navigation expression as errors.- Returns:
- true if safe, false otherwise
-
isSilent
protected boolean isSilent()Whether this interpreter is currently evaluating with a silent mode.- Returns:
- true if silent, false otherwise
-
isCancellable
protected boolean isCancellable()- Returns:
- true if interrupt throws a JexlException.Cancel.
-
findNullOperand
@Deprecated protected JexlNode findNullOperand(RuntimeException xrt, JexlNode node, Object left, Object right) Deprecated. -
findNullOperand
Finds the node causing a NPE for diadic operators.- Parameters:
node
- the parent nodeleft
- the left argumentright
- the right argument- Returns:
- the left, right or parent node
-
unsolvableVariable
Triggered when a variable can not be resolved.- Parameters:
node
- the node where the error originated fromvar
- the variable nameundef
- whether the variable is undefined or null- Returns:
- throws JexlException if strict and not silent, null otherwise
-
undefinedVariable
Triggered when a variable is lexically known as undefined.- Parameters:
node
- the node where the error originated fromvar
- the variable name- Returns:
- throws JexlException if strict and not silent, null otherwise
-
redefinedVariable
Triggered when a variable is lexically known as being redefined.- Parameters:
node
- the node where the error originated fromvar
- the variable name- Returns:
- throws JexlException if strict and not silent, null otherwise
-
isTernaryProtected
Check if a null evaluated expression is protected by a ternary expression.The rationale is that the ternary / elvis expressions are meant for the user to explicitly take control over the error generation; ie, ternaries can return null even if the engine in strict mode would normally throw an exception.
- Returns:
- true if nullable variable, false otherwise
-
variableError
Triggered when a variable generates an issue.- Parameters:
node
- the node where the error originated fromvar
- the variable nameissue
- the issue type- Returns:
- throws JexlException if strict and not silent, null otherwise
-
unsolvableMethod
Triggered when a method can not be resolved.- Parameters:
node
- the node where the error originated frommethod
- the method name- Returns:
- throws JexlException if strict and not silent, null otherwise
-
unsolvableMethod
Triggered when a method can not be resolved.- Parameters:
node
- the node where the error originated frommethod
- the method nameargs
- the method arguments- Returns:
- throws JexlException if strict and not silent, null otherwise
-
unsolvableProperty
Triggered when a property can not be resolved.- Parameters:
node
- the node where the error originated fromproperty
- the property nodecause
- the cause if anyundef
- whether the property is undefined or null- Returns:
- throws JexlException if strict and not silent, null otherwise
-
stringifyProperty
Pretty-prints a failing property (de)reference.Used by calls to unsolvableProperty(...).
- Parameters:
node
- the property node- Returns:
- the (pretty) string
-
stringifyPropertyValue
Pretty-prints a failing property value (de)reference.Used by calls to unsolvableProperty(...).
- Parameters:
node
- the property node- Returns:
- the (pretty) string value
-
operatorError
Triggered when an operator fails.- Parameters:
node
- the node where the error originated fromoperator
- the method namecause
- the cause of error (if any)- Returns:
- throws JexlException if strict and not silent, null otherwise
-
annotationError
Triggered when an annotation processing fails.- Parameters:
node
- the node where the error originated fromannotation
- the annotation namecause
- the cause of error (if any)- Returns:
- throws a JexlException if strict and not silent, null otherwise
-
invocationException
Triggered when method, function or constructor invocation fails with an exception.- Parameters:
node
- the node triggering the exceptionmethodName
- the method/function namexany
- the cause- Returns:
- a JexlException that will be thrown
-
cancel
protected boolean cancel()Cancels this evaluation, setting the cancel flag that will result in a JexlException.Cancel to be thrown.- Returns:
- false if already cancelled, true otherwise
-
isCancelled
protected boolean isCancelled()Checks whether this interpreter execution was cancelled due to thread interruption.- Returns:
- true if cancelled, false otherwise
-
cancelCheck
Throws a JexlException.Cancel if script execution was cancelled.- Parameters:
node
- the node being evaluated
-
functionArguments
Concatenate arguments in call(...).When target == context, we are dealing with a global namespace function call
- Parameters:
target
- the pseudo-method owner, first to-be argumentnarrow
- whether we should attempt to narrow number argumentsargs
- the other (non null) arguments- Returns:
- the arguments array
-
callArguments
Concatenate arguments in call(...).- Parameters:
target
- the pseudo-method owner, first to-be argumentnarrow
- whether we should attempt to narrow number argumentsargs
- the other (non null) arguments- Returns:
- the arguments array
-
functionArgument
Optionally narrows an argument for a function call.- Parameters:
narrow
- whether narrowing should occurarg
- the argument- Returns:
- the narrowed argument
-
getAttribute
Gets an attribute of an object.- Parameters:
object
- to retrieve value fromattribute
- the attribute of the object, e.g. an index (1, 0, 2) or key for a mapnode
- the node that evaluated as the object- Returns:
- the attribute value
-
setAttribute
Sets an attribute of an object.- Parameters:
object
- to set the value toattribute
- the attribute of the object, e.g. an index (1, 0, 2) or key for a mapvalue
- the value to assign to the object's attributenode
- the node that evaluated as the object
-