Class Operator
- All Implemented Interfaces:
JexlArithmetic.Uberspect,JexlOperator.Uberspect
- Since:
- 3.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classThe reverse compare swaps left and right arguments and exploits the symmetry of compare as in: compare(a, b) <=> -compare(b, a)private static classDelegates a comparison operator to a compare method. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final JexlArithmeticThe arithmetic instance being analyzed.private intCaching state: -1 unknown, 0 false, 1 true.private static final Set<JexlOperator>The comparison operators.private final JexlArithmetic.UberspectThe delegate if built as a 3.4 legacy.private static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate final Set<JexlOperator>The set of overloaded operators.private static final Set<JexlOperator>The postfix operators.private final JexlUberspectThe uberspect. -
Constructor Summary
ConstructorsConstructorDescriptionOperator(JexlUberspect theUberspect, JexlArithmetic theArithmetic) Creates an instance.Operator(JexlUberspect theUberspect, JexlArithmetic theArithmetic, Set<JexlOperator> theOverloads) Creates an instance.Operator(JexlUberspect theUberspect, JexlArithmetic theArithmetic, Set<JexlOperator> theOverloads, int theCache) Creates an instance. -
Method Summary
Modifier and TypeMethodDescriptionprivate Object[]arguments(JexlOperator operator, Object... args) Tidy arguments based on operator arity.private BooleanbooleanDuckCall(String methodName, Object left, Object right) Attempts finding a method in left and eventually narrowing right.booleancontains(JexlCache.Reference node, JexlOperator operator, Object left, Object right) The 'match'/'in' operator implementation.private voidcontrolNullOperands(JexlArithmetic arithmetic, JexlOperator operator, Object... args) Throw a NPE if operator is strict and one of the arguments is null.empty(JexlCache.Reference node, Object object) Check for emptiness of various types: Collection, Array, Map, String, and anything that has a boolean isEmpty() method.booleanendsWith(JexlCache.Reference node, JexlOperator operator, Object left, Object right) The 'endsWith' operator implementation.private JexlMethodgetAlternateOverload(JexlOperator operator, Object... args) Special handling of overloads where another attempt at finding a method may be attempted.getOperator(JexlOperator operator, Object... args) Gets the most specific method for an operator.private booleanprivate <T> ToperatorError(JexlCache.Reference ref, JexlOperator operator, Throwable cause, T alt) Triggered when an operator fails.booleanoverloads(JexlOperator operator) Checks whether this uberspect has overloads for a given operator.private ObjectperformBaseOperation(JexlOperator operator, Object... args) Performs the base operation of an assignment.private booleanChecks whether a method returns a boolean or a Boolean.private booleanChecks whether a method returns an int or an Integer.size(JexlCache.Reference node, Object object) Calculate thesizeof various types: Collection, Array, Map, String, and anything that has an int size() method.booleanstartsWith(JexlCache.Reference node, JexlOperator operator, Object left, Object right) The 'startsWith' operator implementation.tryAssignOverload(JexlCache.Reference node, JexlOperator operator, Consumer<Object> assignFun, Object... args) Evaluates an assign operator.private ObjecttryEval(JexlCache.Reference node, JexlOperator operator, Object... args) Tries operator evaluation, handles method resolution caching.tryOverload(JexlCache.Reference node, JexlOperator operator, Object... args) Try to find the most specific method and evaluate an operator.private JexlMethoduberspectOperator(JexlArithmetic arithmetic, JexlOperator operator, Object... args) Seeks an implementation of an operator method in an arithmetic instance.
-
Field Details
-
METHOD_IS_EMPTY
- See Also:
-
METHOD_SIZE
- See Also:
-
METHOD_CONTAINS
- See Also:
-
METHOD_STARTS_WITH
- See Also:
-
METHOD_ENDS_WITH
- See Also:
-
CMP_OPS
The comparison operators.Used to determine if a compare method overload might be used.
-
POSTFIX_OPS
The postfix operators.Used to determine the returned value in assignment.
-
uberspect
The uberspect. -
arithmetic
The arithmetic instance being analyzed. -
overloads
The set of overloaded operators. -
delegate
The delegate if built as a 3.4 legacy. -
caching
private volatile int cachingCaching state: -1 unknown, 0 false, 1 true.
-
-
Constructor Details
-
Operator
Creates an instance.Mostly used as a compatibility measure by delegating instead of extending.
- Parameters:
theUberspect- The uberspect instancetheArithmetic- The arithmetic instance used to delegate operator overloads
-
Operator
public Operator(JexlUberspect theUberspect, JexlArithmetic theArithmetic, Set<JexlOperator> theOverloads) Creates an instance.- Parameters:
theUberspect- The uberspect instancetheArithmetic- The arithmetic instancetheOverloads- The overloaded operators
-
Operator
public Operator(JexlUberspect theUberspect, JexlArithmetic theArithmetic, Set<JexlOperator> theOverloads, int theCache) Creates an instance.- Parameters:
theUberspect- The uberspect instancetheArithmetic- The arithmetic instancetheOverloads- The overloaded operatorstheCache- The caching state
-
-
Method Details
-
getOperator
Description copied from interface:JexlArithmetic.UberspectGets the most specific method for an operator.- Specified by:
getOperatorin interfaceJexlArithmetic.Uberspect- Parameters:
operator- The operatorargs- The arguments- Returns:
- The most specific method or null if no specific override could be found
-
overloads
Description copied from interface:JexlArithmetic.UberspectChecks whether this uberspect has overloads for a given operator.- Specified by:
overloadsin interfaceJexlArithmetic.Uberspect- Parameters:
operator- The operator to check- Returns:
- true if an overload exists, false otherwise
-
isCaching
private boolean isCaching()- Returns:
- whether caching is enabled in the engine
-
arguments
Tidy arguments based on operator arity.The interpreter may add a null to the arguments of operator expecting only one parameter.
- Parameters:
operator- The operatorargs- The arguments (as seen by the interpreter)- Returns:
- The tidied arguments
-
booleanDuckCall
Attempts finding a method in left and eventually narrowing right.- Parameters:
methodName- The method nameright- The left argument in the operatorleft- The right argument in the operator- Returns:
- A boolean is call was possible, null otherwise
- Throws:
Exception- Thrown if invocation fails
-
controlNullOperands
Throw a NPE if operator is strict and one of the arguments is null.- Parameters:
arithmetic- The JEXL arithmetic instanceoperator- The operator to checkargs- The operands- Throws:
JexlArithmetic.NullOperand- if operator is strict and an operand is null
-
operatorError
Triggered when an operator fails.- Type Parameters:
T- the return type- Parameters:
ref- The node where the error originated fromoperator- The operator symbolcause- The cause of error (if any)alt- what to return if not strict- Returns:
- throws JexlException if strict and not silent, null otherwise
-
uberspectOperator
private JexlMethod uberspectOperator(JexlArithmetic arithmetic, JexlOperator operator, Object... args) Seeks an implementation of an operator method in an arithmetic instance.Method must <>not/em belong to JexlArithmetic
- Parameters:
arithmetic- The arithmetic instanceoperator- The operatorargs- The arguments- Returns:
- A JexlMethod instance or null
-
returnsBoolean
Checks whether a method returns a boolean or a Boolean.- Parameters:
vm- The JexlMethod (can be null)- Returns:
- true of false
-
returnsInteger
Checks whether a method returns an int or an Integer.- Parameters:
vm- The JexlMethod (can be null)- Returns:
- true of false
-
empty
Description copied from interface:JexlOperator.UberspectCheck for emptiness of various types: Collection, Array, Map, String, and anything that has a boolean isEmpty() method.Seeks an overload or use the default arithmetic implementation.
Note that the result may not be a boolean.
- Specified by:
emptyin interfaceJexlOperator.Uberspect- Parameters:
node- The node holding the objectobject- The object to check the emptiness of- Returns:
- The evaluation result
-
size
Description copied from interface:JexlOperator.UberspectCalculate thesizeof various types: Collection, Array, Map, String, and anything that has an int size() method.Seeks an overload or use the default arithmetic implementation.
Note that the result may not be an integer.
- Specified by:
sizein interfaceJexlOperator.Uberspect- Parameters:
node- An optional reference caching resolved method or failing signatureobject- The object to get the size of- Returns:
- The evaluation result
-
contains
Description copied from interface:JexlOperator.UberspectThe 'match'/'in' operator implementation.Seeks an overload or use the default arithmetic implementation.
Note that 'x in y' or 'x matches y' means 'y contains x' ; the JEXL operator arguments order syntax is the reverse of this method call.
- Specified by:
containsin interfaceJexlOperator.Uberspect- Parameters:
node- An optional reference caching resolved method or failing signatureoperator- The calling operator, =~ or !~left- The right operandright- The left operand- Returns:
- true if left matches right, false otherwise
-
startsWith
public boolean startsWith(JexlCache.Reference node, JexlOperator operator, Object left, Object right) Description copied from interface:JexlOperator.UberspectThe 'startsWith' operator implementation.Seeks an overload or use the default arithmetic implementation.
- Specified by:
startsWithin interfaceJexlOperator.Uberspect- Parameters:
node- An optional reference caching resolved method or failing signatureoperator- The calling operator, $= or $!left- The left operandright- The right operand- Returns:
- true if left starts with right, false otherwise
-
endsWith
Description copied from interface:JexlOperator.UberspectThe 'endsWith' operator implementation.Seeks an overload or use the default arithmetic implementation.
- Specified by:
endsWithin interfaceJexlOperator.Uberspect- Parameters:
node- An optional reference caching resolved method or failing signatureoperator- The calling operator, ^= or ^!left- The left operandright- The right operand- Returns:
- true if left ends with right, false otherwise
-
tryAssignOverload
public Object tryAssignOverload(JexlCache.Reference node, JexlOperator operator, Consumer<Object> assignFun, Object... args) Description copied from interface:JexlOperator.UberspectEvaluates an assign operator.This takes care of finding and caching the operator method when appropriate. If an overloads returns a value not-equal to TRY_FAILED, it means the side-effect is complete. Otherwise,
a += b <=> a = a + b- Specified by:
tryAssignOverloadin interfaceJexlOperator.Uberspect- Parameters:
node- An optional reference caching resolved method or failing signatureoperator- The operatorassignFun- The actual function that performs the side effectargs- The arguments, the first one being the target of assignment- Returns:
- JexlEngine.TRY_FAILED if no operation was performed, the value to use as the side effect argument otherwise
-
performBaseOperation
Performs the base operation of an assignment.- Parameters:
operator- The operatorargs- The arguments- Returns:
- The result
-
tryOverload
Description copied from interface:JexlOperator.UberspectTry to find the most specific method and evaluate an operator.This method does not call
JexlArithmetic.Uberspect.overloads(JexlOperator)and shall not be called with an assignment operator; useJexlOperator.Uberspect.tryAssignOverload(JexlCache.Reference, JexlOperator, Consumer, Object...)in that case.- Specified by:
tryOverloadin interfaceJexlOperator.Uberspect- Parameters:
node- An optional reference caching resolved method or failing signatureoperator- The operatorargs- The arguments- Returns:
- TRY_FAILED if no specific method could be found, the evaluation result otherwise
-
tryEval
Tries operator evaluation, handles method resolution caching.- Parameters:
node- The nodeoperator- The operatorargs- The operator arguments- Returns:
- The operator evaluation result or TRY_FAILED
-
getAlternateOverload
Special handling of overloads where another attempt at finding a method may be attempted.As of 3.5.0, only the comparison operators attempting to use compare() are handled.
- Parameters:
operator- The operatorargs- The arguments- Returns:
- An instance or null
-