Package org.codehaus.groovy.runtime.metaclass

# 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

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from class groovy.lang.MetaClassImpl

  `MetaClassImpl.MetaConstructor`

- ## Field Summary

  ### Fields inherited from class groovy.lang.MetaClassImpl

  `EMPTY_ARGUMENTS, getPropertyMethod, INVOKE_METHOD_METHOD, invokeMethodMethod, isGroovyObject, isMap, metaMethodIndex, METHOD_MISSING, PROPERTY_MISSING, registry, setPropertyMethod, STATIC_METHOD_MISSING, STATIC_PROPERTY_MISSING, theCachedClass, theClass`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PackedClosureMetaClass(MetaClassRegistry registry, Class theClass)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Object`
  `invokeMethod(Class sender, Object object, String methodName, Object[] originalArguments, boolean isCallToSuper, boolean fromInsideClass)`
  Invokes a method on the given receiver for the specified arguments.
  `List<MetaMethod>`
  `respondsTo(Object obj, String name, Object[] argTypes)`
  Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name and arguments types.

  ### Methods inherited from class groovy.lang.MetaClassImpl

  `addMetaBeanProperty, addMetaMethod, addMetaMethodToIndex, addNewInstanceMethod, addNewStaticMethod, applyPropertyDescriptors, checkIfGroovyObjectMethod, checkInitalised, chooseConstructor, chooseMethod, chooseNamedArgCompatibleConstructor, clearInvocationCaches, createErrorMessageForAmbiguity, createTransformMetaMethod, doChooseMostSpecificParams, dropMethodCache, dropStaticMethodCache, findMethodInClassHierarchy, findMixinMethod, findOwnMethod, findPropertyInClassHierarchy, getAdditionalMetaMethods, getAttribute, getAttribute, getAttribute, getClassInfo, getClassNode, getEffectiveGetMetaProperty, getMetaMethod, getMetaMethods, getMetaProperty, getMethods, getMethodWithCaching, getMethodWithCaching, getMethodWithoutCaching, getNonClosureOuter, getProperties, getProperty, getProperty, getRegistry, getStaticMetaMethod, getSubclassMetaMethods, getSuperClasses, getTheCachedClass, getTheClass, getVersion, handleMatches, hasCustomInvokeMethod, hasCustomStaticInvokeMethod, hasProperty, incVersion, initialize, invokeConstructor, invokeMethod, invokeMethod, invokeMissingMethod, invokeMissingProperty, invokeStaticMethod, invokeStaticMissingProperty, isGroovyObject, isInitialized, isModified, isPermissivePropertyAccess, onGetPropertyFoundInHierarchy, onInvokeMethodFoundInHierarchy, onMixinMethodFound, onSetPropertyFoundInHierarchy, onSuperMethodFoundInHierarchy, onSuperPropertyFoundInHierarchy, pickMethod, reinitialize, respondsTo, retrieveConstructor, retrieveConstructor, retrieveStaticMethod, selectConstructorAndTransformArguments, setAttribute, setAttribute, setInitialized, setPermissivePropertyAccess, setProperties, setProperty, setProperty, toString`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### PackedClosureMetaClass

    public PackedClosureMetaClass(MetaClassRegistry registry, Class theClass)

- ## 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:
      - `MetaClass.invokeMethod(Class, Object, String, Object[], boolean, boolean)`

  - ### 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:
      - `MetaObjectProtocol.respondsTo(Object, String, Object[])`