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.
  • Field Details

    • frame

      protected final Frame frame
      The frame.
    • options

      protected final JexlOptions options
      The options.
  • Constructor Details

    • Closure

      protected Closure(Interpreter theCaller, ASTJexlLambda lambda)
      Creates a closure.
      Parameters:
      theCaller - the calling interpreter
      lambda - the lambda
    • Closure

      protected Closure(Script base, Object[] args)
      Creates a curried version of a script.
      Parameters:
      base - the base script
      args - the script arguments
  • Method Details

    • callable

      public Script.Callable callable(JexlContext context, Object... args)
      Description copied from class: Script
      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:
      callable in interface JexlScript
      Overrides:
      callable in class Script
      Parameters:
      context - the context
      args - 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 frame
      symbol - the symbol index (in the caller of this closure)
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Script
    • evaluate

      public Object evaluate(JexlContext context)
      Description copied from interface: JexlExpression
      Evaluates the expression with the variables contained in the supplied JexlContext.
      Specified by:
      evaluate in interface JexlExpression
      Overrides:
      evaluate in class Script
      Parameters:
      context - A JexlContext containing variables.
      Returns:
      The result of this evaluation
    • execute

      public Object execute(JexlContext context)
      Description copied from interface: JexlScript
      Executes the script with the variables contained in the supplied JexlContext.
      Specified by:
      execute in interface JexlScript
      Overrides:
      execute in class Script
      Parameters:
      context - A JexlContext containing variables.
      Returns:
      The result of this script, usually the result of the last statement.
    • execute

      public Object execute(JexlContext context, Object... args)
      Description copied from interface: JexlScript
      Executes the script with the variables contained in the supplied JexlContext and a set of arguments corresponding to the parameters used during parsing.
      Specified by:
      execute in interface JexlScript
      Overrides:
      execute in class Script
      Parameters:
      context - A JexlContext containing variables.
      args - the arguments
      Returns:
      The result of this script, usually the result of the last statement.
    • getUnboundParameters

      public String[] getUnboundParameters()
      Description copied from interface: JexlScript
      Gets this script unbound parameters.

      Parameters that haven't been bound by a previous call to curry().

      Specified by:
      getUnboundParameters in interface JexlScript
      Overrides:
      getUnboundParameters in class Script
      Returns:
      the parameters or null
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Script