Class PackedClosure.Fixed2

All Implemented Interfaces:
GroovyCallable<Object>, GroovyObject, Serializable, Cloneable, Runnable, Callable<Object>, GeneratedClosure
Enclosing class:
PackedClosure

public static final class PackedClosure.Fixed2 extends PackedClosure implements GeneratedClosure
Packed closure whose only doCall takes two arguments and passes them to PackedClosure.dispatchTwo(java.lang.Object, java.lang.Object).
See Also:
  • Constructor Details

    • Fixed2

      public Fixed2(Object owner, GeneratedDispatcher.Bundle dispatchers, int id, String method, Object[] captured, Class[] visibleTypes, boolean strict)
      Initializes the two-parameter packed closure. doCall(Object, Object) coerces the pair and dispatches them.

      The arguments are forwarded to PackedClosure. owner is stored as the closure owner, the delegate, and the this object, and as the receiver each later dispatch passes to the hoisted method. The general, one-value, and two-value dispatchers are taken from dispatchers. id and method are stored. captured is kept by reference, and a null array is replaced with an empty one. Closure first fills the parameter metadata by reflecting this member's doCall; that metadata is then replaced by visibleTypes, which is also kept by reference.

      Parameters:
      owner - the object stored as the closure owner, the delegate, and the this object, and as the receiver passed to the hoisted method. A static hoisted method is given the enclosing class
      dispatchers - the hosting class's GeneratedDispatcher tables. The general, one-value, and two-value dispatchers are read from this bundle
      id - index of the hoisted method in those tables
      method - name of the hoisted method, kept for diagnostics
      captured - values closed over from the enclosing scope and passed ahead of the call arguments. null is stored as an empty array; a non-null array is retained by reference
      visibleTypes - declared parameter types, retained by reference and installed as this closure's parameter metadata in place of the types reflected from doCall
      strict - value stored for the delegate and resolve-strategy guards. true makes a non-null delegate other than the owner, or a strategy other than owner-first or owner-only, fail when it is set
  • Method Details

    • doCall

      public Object doCall(Object a, Object b)
      Coerces both arguments and invokes the hoisted method with them.

      When nothing was captured, each argument is coerced to the matching stored parameter type and the two-value table is used. Otherwise the two arguments are packed with the receiver and the captured values and coerced on the way into the general table. A value that cannot be coerced raises MissingMethodException. An exception thrown by the hoisted method propagates to the caller.

      Parameters:
      a - value supplied for the first parameter
      b - value supplied for the second parameter
      Returns:
      the value returned by the hoisted method, or null when that method is void