Interface JexlOperator.Uberspect

All Superinterfaces:
JexlArithmetic.Uberspect
Enclosing class:
JexlOperator

public static interface JexlOperator.Uberspect extends JexlArithmetic.Uberspect
Uberspect that solves and evaluates JexlOperator overloads.

This is used by the interpreter to find and execute operator overloads implemented in a derived JexlArithmetic - or in some cases, as methods of the left argument type (contains, size, ...).

This also allows reusing the core logic when extending the applicative type-system; for instance, implementing a Comparator class that calls compare (operator.tryOverload(this, JexlOperator.COMPARE, left, right), etc.

Since:
3.5.0
  • Method Details

    • tryOverload

      Object tryOverload(JexlCache.Reference reference, JexlOperator operator, Object... args)
      Try 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; use tryAssignOverload(JexlCache.Reference, JexlOperator, Consumer, Object...) in that case.

      Parameters:
      reference - an optional reference caching resolved method or failing signature
      operator - the operator
      args - the arguments
      Returns:
      TRY_FAILED if no specific method could be found, the evaluation result otherwise
    • tryAssignOverload

      Evaluates 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

      Parameters:
      node - an optional reference caching resolved method or failing signature
      operator - the operator
      assign - the actual function that performs the side effect
      args - 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
    • size

      Calculate the size of 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.

      Parameters:
      node - an optional reference caching resolved method or failing signature
      object - the object to get the size of
      Returns:
      the evaluation result
    • empty

      Check 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.

      Parameters:
      node - the node holding the object
      object - the object to check the emptiness of
      Returns:
      the evaluation result
    • contains

      boolean contains(JexlCache.Reference node, JexlOperator operator, Object left, Object right)
      The '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.

      Parameters:
      node - an optional reference caching resolved method or failing signature
      operator - the calling operator, =~ or !~
      left - the right operand
      right - the left operand
      Returns:
      true if left matches right, false otherwise
    • startsWith

      boolean startsWith(JexlCache.Reference node, JexlOperator operator, Object left, Object right)
      The 'startsWith' operator implementation.

      Seeks an overload or use the default arithmetic implementation.

      Parameters:
      node - an optional reference caching resolved method or failing signature
      operator - the calling operator, $= or $!
      left - the left operand
      right - the right operand
      Returns:
      true if left starts with right, false otherwise
    • endsWith

      boolean endsWith(JexlCache.Reference node, JexlOperator operator, Object left, Object right)
      The 'endsWith' operator implementation.

      Seeks an overload or use the default arithmetic implementation.

      Parameters:
      node - an optional reference caching resolved method or failing signature
      operator - the calling operator, ^= or ^!
      left - the left operand
      right - the right operand
      Returns:
      true if left ends with right, false otherwise