Package: org.codehaus.groovy.reflection

## [Java] Class ClassLoaderForClassArtifacts

- org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts

-     public class ClassLoaderForClassArtifacts
      extends ClassLoader

  A specialized ClassLoader used to define per-class artifact classes such as generated meta-method dispatchers.

  Since Groovy 6.0 this loader first attempts to define each artifact as a hidden nestmate of the target via HiddenClassDefiner.tryDefineNestmate. When that soft-fails (unopened package, unsuitable host, …) it falls back to ClassLoader.defineClass with the protection domain captured at construction. Module / nest-host policy is documented on HiddenClassDefiner.

  See Also:
    HiddenClassDefiner

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `SoftReference<Class>` | `klazz` | Soft reference to the class for which artifacts are generated.

  - ### Constructor Summary

    Constructors
    Constructor and description
    `ClassLoaderForClassArtifacts(Class klazz)` Creates a new artifact class loader for the specified class.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public String` | `createClassName(Method method)` Generates a unique class name for an artifact associated with the given method.
    `` | `public String` | `createClassName(String methodName)` Generates a unique class name for an artifact associated with the given method name.
    `` | `public Class` | `define(String name, byte[] bytes)` Defines a class from bytecode, preferring a hidden nestmate of the target.
    `` | `public Constructor` | `defineClassAndGetConstructor(String name, byte[] bytes, Class<?> parameterTypes)` Defines a class from bytecode and returns the public constructor matching the given parameter types, or `null` if definition or lookup fails.
    `` | `public Class` | `loadClass(String name)` Loads the class with the specified binary name. This method searches for classes in the same manner as the loadClass(String, boolean) method. It is invoked by the Java virtual machine to resolve class references. Invoking this method is equivalent to invoking loadClass(name,. throws: ClassNotFoundException If the class was not found Parameters: `name` - The binary name of the class Returns: The resulting `Class` object

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class ClassLoader` | `clearAssertionStatus, equals, getClass, getDefinedPackage, getDefinedPackages, getName, getParent, getPlatformClassLoader, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, hashCode, isRegisteredAsParallelCapable, loadClass, notify, notifyAll, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, toString, wait, wait, wait`

- - ### Field Detail

    - #### public final SoftReference<Class> klazz

      Soft reference to the class for which artifacts are generated.

  - ### Constructor Detail

    - #### public ClassLoaderForClassArtifacts(Class klazz)

      Creates a new artifact class loader for the specified class.

      Parameters:
        `klazz` - the class whose artifact classes are to be defined via this loader

  - ### Method Detail

    - #### public String createClassName(Method method)

      Generates a unique class name for an artifact associated with the given method.

      Parameters:
        `method` - the method for which the artifact is generated
      Returns:
        a unique class name

    - #### public String createClassName(String methodName)

      Generates a unique class name for an artifact associated with the given method name.

      For classes in the `java.*` package hierarchy the name is prefixed to avoid the restricted `java.` namespace. The counter suffix ensures uniqueness when multiple artifacts share the same logical name.

      Parameters:
        `methodName` - the method name component of the artifact class name
      Returns:
        a unique class name

    - #### public Class define(String name, byte[] bytes)

      Defines a class from bytecode, preferring a hidden nestmate of the target.

      Parameters:
        `name` - the binary name used for the fallback (visible-class) path
        `bytes` - the class-file bytes
      Returns:
        the defined class

    - #### public Constructor defineClassAndGetConstructor(String name, byte[] bytes, Class<?> parameterTypes)

      Defines a class from bytecode and returns the public constructor matching the given parameter types, or `null` if definition or lookup fails.

      Uses Class.getConstructor so the returned constructor is always publicly accessible (same contract as before hidden-class support).

      Parameters:
        `name` - the binary name (for fallback visible-class definition)
        `bytes` - the class-file bytes
        `parameterTypes` - the constructor parameter types to look up
      Returns:
        the matching public constructor, or `null`

    - #### public Class loadClass(String name)

      Loads the class with the specified binary name. This method searches for classes in the same manner as the loadClass(String, boolean) method. It is invoked by the Java virtual machine to resolve class references. Invoking this method is equivalent to invoking loadClass(name,.

      throws:
        ClassNotFoundException If the class was not found
      Parameters:
        `name` - The binary name of the class
      Returns:
        The resulting `Class` object