Class PackedClosure.FixedIt

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

public static final class PackedClosure.FixedIt extends PackedClosure implements GeneratedClosure
The implicit-parameter literal ({ it * 2 }): a generated closure class declares both doCall() and doCall(Object) for it, which class-level introspection reads as the fuzzy "0 or 1" arity that lets the closure match both zero- and one-parameter SAM overloads (GROOVY-10905) — so this member declares the same pair.
See Also:
  • Constructor Details

    • FixedIt

      public FixedIt(Object owner, GeneratedDispatcher.Bundle dispatchers, int id, String method, Object[] captured, Class[] visibleTypes, boolean strict)
      Initializes the implicit-parameter packed closure. This member declares both doCall() and doCall(Object).

      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()
      Invokes the implicit-parameter body with no supplied argument.

      Passes the shared empty array to PackedClosure.dispatchAll(java.lang.Object[]), so this entry allocates no argument array. A stored parameter count of zero packs the receiver and the captured values and invokes the hoisted method. A single non-array parameter is bound to null, and a single array parameter is bound to an empty array of its component type. A stored count above one raises MissingMethodException. An exception thrown by the hoisted method propagates to the caller.

      Returns:
      the value returned by the hoisted method, or null when that method is void
    • doCall

      public Object doCall(Object a)
      Coerces the implicit parameter and invokes the hoisted method with it.

      A parameter type of Object, a null argument, or an argument that is already an instance of the parameter type is passed through. Every other value is coerced with the metaclass rules used for a generated closure, and a value that cannot be coerced raises MissingMethodException. No captured values use the one-value dispatch table, one captured value uses the two-value table with the capture before the argument, and any further captures are packed with the receiver and the argument for the general table. An exception thrown by the hoisted method propagates to the caller.

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