Class PackedClosureMetaClass

java.lang.Object
groovy.lang.MetaClassImpl
org.codehaus.groovy.runtime.metaclass.PackedClosureMetaClass
All Implemented Interfaces:
MetaClass, MetaObjectProtocol, MutableMetaClass

public final class PackedClosureMetaClass extends MetaClassImpl
The stock metaclass for PackedClosure, giving packed closures their own MOP standing (the analog of ClosureMetaClass for generated closure classes, whose per-class metaclasses packed closures deliberately do not have).

invokeMethod("call"/"doCall") dispatches straight to the adapter — a plain virtual call that routes to the hosting class's dispatch tables — with no reflection anywhere on the path, and, matching ClosureMetaClass, without consulting categories for the closure-invocation names (categories have never applied to closure doCall dispatch). Each fixed-arity family member class gets its own instance of this metaclass from the registry (a per-class registry can only be per-adapter-class), so class-level metaclass changes affect every packed closure of that member's arity; per-instance setMetaClass is honoured as usual — the adapter's dispatch guard routes perturbed instances through the replacement's invokeMethod.

respondsTo(Object, String, Object[]) is instance-faithful: the fixed-arity family member's doCall(s) are erased to Object parameters (and FixedN's is varargs), so the answer for the closure-invocation names is additionally filtered by the instance's declared parameter types (which the adapter carries for exactly this purpose). Purely class-level introspection (pickMethod, getMetaMethods) necessarily reflects the shared adapter class, not any single literal.

Since:
6.0.0
  • Constructor Details

  • Method Details

    • invokeMethod

      public Object invokeMethod(Class sender, Object object, String methodName, Object[] originalArguments, boolean isCallToSuper, boolean fromInsideClass)
      Description copied from class: MetaClassImpl
      Invokes a method on the given receiver for the specified arguments. The sender is the class that invoked the method on the object. The MetaClass will attempt to establish the method to invoke based on the name and arguments provided.

      The isCallToSuper and fromInsideClass help the Groovy runtime perform optimisations on the call to go directly to the super class if necessary

      Specified by:
      invokeMethod in interface MetaClass
      Overrides:
      invokeMethod in class MetaClassImpl
      Parameters:
      sender - The java.lang.Class instance that invoked the method
      object - The object which the method was invoked on
      methodName - The name of the method
      originalArguments - The arguments to the method
      isCallToSuper - Whether the method is a call to a super class method
      fromInsideClass - Whether the call was invoked from the inside or the outside of the class
      Returns:
      The return value of the method.
      See Also:
    • respondsTo

      public List<MetaMethod> respondsTo(Object obj, String name, Object[] argTypes)
      Description copied from interface: MetaObjectProtocol

      Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name and arguments types.

      Note that this method's return value is based on realised methods and does not take into account objects or classes that implement invokeMethod or methodMissing

      This method is "safe" in that it will always return a value and never throw an exception

      Specified by:
      respondsTo in interface MetaObjectProtocol
      Overrides:
      respondsTo in class MetaClassImpl
      Parameters:
      obj - The object to inspect
      name - The name of the method of interest
      argTypes - The argument types to match against
      Returns:
      A List of MetaMethods matching the argument types which will be empty if no matching methods exist
      See Also: