Package: org.codehaus.groovy.reflection

## [Java] Class CachedClass

- org.codehaus.groovy.reflection.CachedClass

-     public class CachedClass
      extends Object

  Caches reflection information for a class including its fields, methods, constructors, and interfaces.

  Lazily initializes cached members on first access and provides utility methods for searching methods, checking assignability, and managing MOP methods. Instances are typically obtained via ReflectionCache.

- - ### Nested Class Summary

    Nested classes
    Modifiers | Name | Description
    --- | --- | ---
    `static class` | `CachedClass.CachedMethodComparatorByName` | Comparator for ordering cached methods by name.
    `static class` | `CachedClass.CachedMethodComparatorWithString` | Comparator for ordering cached methods against string names.

  - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static CachedClass[]` | `EMPTY_ARRAY` | An empty array constant representing zero cached classes.
    `ClassInfo` | `classInfo` | `ClassInfo` object for this class, holding metadata about the class.
    `boolean` | `isArray` | `true` if the cached class is an array type, `false` otherwise.
    `boolean` | `isInterface` | `true` if the cached class is an interface, `false` otherwise.
    `boolean` | `isNumber` | `true` if the cached class is assignable from Number, `false` otherwise.
    `boolean` | `isPrimitive` | `true` if the cached class is a primitive type, `false` otherwise.
    `int` | `modifiers` | The modifiers of this class (e.g., public, final, abstract).
    `CachedMethod[]` | `mopMethods` | Array of MOP (Meta-Object Protocol) methods, including inherited methods.

  - ### Constructor Summary

    Constructors
    Constructor and description
    `CachedClass(Class<?> klazz, ClassInfo classInfo)` Constructs a `CachedClass` for the given class with the specified `ClassInfo`.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public void` | `addNewMopMethods(List<MetaMethod> arr)` Adds a list of new meta-methods to this class's existing MOP methods.
    `` | `public Object` | `coerceArgument(Object argument)` Coerces an argument to a form suitable for this class.
    `` | `public CachedClass` | `getCachedClass()` Returns this cached class (for compatibility).
    `` | `public CachedClass` | `getCachedSuperClass()` Returns the cached superclass of this class, if any.
    `` | `public CallSiteClassLoader` | `getCallSiteLoader()` Returns the class loader used for generating call site classes for this cached class.
    `` | `public CachedConstructor[]` | `getConstructors()` Returns all public and protected constructors declared in this class.
    `` | `public Set<CachedClass>` | `getDeclaredInterfaces()` Returns a set of interfaces directly declared by this class (not including inherited ones).
    `` | `public CachedField[]` | `getFields()` Returns all public and protected fields declared in this class.
    `` | `public Collection<ClassInfo>` | `getHierarchy()` Returns the complete type hierarchy for this class, including superclasses and interfaces.
    `` | `public Set<CachedClass>` | `getInterfaces()` Returns a set of all interfaces implemented or extended by this class, including inherited interfaces.
    `` | `public CachedMethod[]` | `getMethods()` Returns all public and protected methods of this class and its superclasses.
    `` | `public int` | `getModifiers()` Returns the access modifier flags for this class.
    `` | `public String` | `getName()` Returns the fully qualified name of this class.
    `` | `public MetaMethod[]` | `getNewMetaMethods()` Returns a list of new meta-methods added to this class's meta-class.
    `` | `public int` | `getSuperClassDistance()` Computes the distance from this class to the superclass hierarchy, used for type matching.
    `` | `public final Class<?>` | `getTheClass()` Returns the underlying Java `Class` object wrapped by this cached class.
    `` | `public String` | `getTypeDescription()` Returns the bytecode type descriptor for this class.
    `` | `public int` | `hashCode()`
    `` | `public boolean` | `isAssignableFrom(Class<?> argument)` Returns whether the argument class is assignable to this class.
    `` | `public boolean` | `isDirectlyAssignable(Object argument)` Returns whether an object instance is directly assignable to this class.
    `` | `public boolean` | `isInterface()` Returns whether this class represents an interface type.
    `` | `public boolean` | `isPrimitive()` Returns whether this class represents a primitive type.
    `` | `public boolean` | `isVoid()` Returns whether this class represents the void type.
    `` | `public CachedMethod` | `searchMethods(String name, CachedClass[] parameterTypes)` Searches for a method with the specified name and parameter types in this class.
    `` | `public void` | `setNewMopMethods(List<MetaMethod> arr)` Replaces the current MOP methods with the specified list of meta-methods.
    `` | `public String` | `toString()`

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### public static final CachedClass[] EMPTY_ARRAY

      An empty array constant representing zero cached classes.

    - #### public ClassInfo classInfo

      `ClassInfo` object for this class, holding metadata about the class.

    - #### public final boolean isArray

      `true` if the cached class is an array type, `false` otherwise.

    - #### public final boolean isInterface

      `true` if the cached class is an interface, `false` otherwise.

    - #### public final boolean isNumber

      `true` if the cached class is assignable from Number, `false` otherwise.

    - #### public final boolean isPrimitive

      `true` if the cached class is a primitive type, `false` otherwise.

    - #### public final int modifiers

      The modifiers of this class (e.g., public, final, abstract). See Modifier for constants.

    - #### public CachedMethod[] mopMethods

      Array of MOP (Meta-Object Protocol) methods, including inherited methods. Updated when methods are added via setNewMopMethods(List) or addNewMopMethods(List).

  - ### Constructor Detail

    - #### public CachedClass(Class<?> klazz, ClassInfo classInfo)

      Constructs a `CachedClass` for the given class with the specified `ClassInfo`.

      Parameters:
        `klazz` - the class to cache reflection information for
        `classInfo` - the `ClassInfo` object associated with this cached class

  - ### Method Detail

    - #### public void addNewMopMethods(List<MetaMethod> arr)

      Adds a list of new meta-methods to this class's existing MOP methods. Reinitializes the meta-class to incorporate the new methods alongside existing ones.

      throws:
        GroovyRuntimeException if a strong custom meta-class is already set
      Parameters:
        `arr` - the list of meta-methods to add

    - #### public Object coerceArgument(Object argument)

      Coerces an argument to a form suitable for this class.

      By default, returns the argument unchanged. Subclasses may override to provide type-specific coercion logic.

      Parameters:
        `argument` - the argument to coerce
      Returns:
        the coerced argument

    - #### public CachedClass getCachedClass()

      Returns this cached class (for compatibility).

      Returns:
        this `CachedClass`

    - #### public CachedClass getCachedSuperClass()

      Returns the cached superclass of this class, if any.

      Returns:
        the cached superclass, or `null` if this is `Object` or an interface

    - #### public CallSiteClassLoader getCallSiteLoader()

      Returns the class loader used for generating call site classes for this cached class.

      Returns:
        a call site class loader

    - #### public CachedConstructor[] getConstructors()

      Returns all public and protected constructors declared in this class.

      Returns:
        an array of cached constructors

    - #### public Set<CachedClass> getDeclaredInterfaces()

      Returns a set of interfaces directly declared by this class (not including inherited ones).

      Returns:
        a set of directly declared cached interfaces

    - #### public CachedField[] getFields()

      Returns all public and protected fields declared in this class.

      Returns:
        an array of cached fields

    - #### public Collection<ClassInfo> getHierarchy()

      Returns the complete type hierarchy for this class, including superclasses and interfaces.

      Returns:
        a collection of `ClassInfo` objects in the hierarchy

    - #### public Set<CachedClass> getInterfaces()

      Returns a set of all interfaces implemented or extended by this class, including inherited interfaces. If this class is an interface, it includes itself in the set.

      Returns:
        a set of cached interfaces

    - #### public CachedMethod[] getMethods()

      Returns all public and protected methods of this class and its superclasses.

      Returns:
        an array of cached methods, sorted by name

    - #### public int getModifiers()

      Returns the access modifier flags for this class.

      Returns:
        the modifiers as an integer, see Modifier

    - #### public String getName()

      Returns the fully qualified name of this class.

      Returns:
        the class name

    - #### public MetaMethod[] getNewMetaMethods()

      Returns a list of new meta-methods added to this class's meta-class. Includes expando methods and methods from all superclasses and interfaces.

      Returns:
        an array of meta-methods

    - #### public int getSuperClassDistance()

      Computes the distance from this class to the superclass hierarchy, used for type matching. The distance is the number of steps up the inheritance chain from this class to `Object`.

      Returns:
        the superclass distance (1 for Object, 2 for direct subclasses of Object, etc.)

    - #### public final Class<?> getTheClass()

      Returns the underlying Java `Class` object wrapped by this cached class.

      Returns:
        the class object

    - #### public String getTypeDescription()

      Returns the bytecode type descriptor for this class.

      Returns:
        the type descriptor string

    - #### public int hashCode()

    - #### public boolean isAssignableFrom(Class<?> argument)

      Returns whether the argument class is assignable to this class. Returns `true` for `null` arguments.

      Parameters:
        `argument` - the class to check
      Returns:
        `true` if `argument` is `null` or assignable to this class

    - #### public boolean isDirectlyAssignable(Object argument)

      Returns whether an object instance is directly assignable to this class.

      Parameters:
        `argument` - the object to check
      Returns:
        `true` if the object's class is assignable to this class

    - #### public boolean isInterface()

      Returns whether this class represents an interface type.

      Returns:
        `true` if this is an interface, `false` otherwise

    - #### public boolean isPrimitive()

      Returns whether this class represents a primitive type.

      Returns:
        `true` if this is a primitive type (int, double, etc.), `false` otherwise

    - #### public boolean isVoid()

      Returns whether this class represents the void type.

      Returns:
        `true` if this class is void, `false` otherwise

    - #### public CachedMethod searchMethods(String name, CachedClass[] parameterTypes)

      Searches for a method with the specified name and parameter types in this class.

      Parameters:
        `name` - the name of the method to search for
        `parameterTypes` - the parameter types of the method
      Returns:
        the matching cached method, or `null` if not found. If multiple matches exist, returns the one with the most specific return type

    - #### public void setNewMopMethods(List<MetaMethod> arr)

      Replaces the current MOP methods with the specified list of meta-methods. Reinitializes the meta-class to reflect the new methods.

      throws:
        GroovyRuntimeException if a strong custom meta-class is already set
      Parameters:
        `arr` - the new list of meta-methods to use, or `null` to revert to default

    - #### public String toString()