Package: org.codehaus.groovy.reflection

## [Java] Class ParameterTypes

- org.codehaus.groovy.reflection.ParameterTypes

-     public class ParameterTypes
      extends Object

  Manages parameter type information for methods and constructors, supporting lazy initialization.

  Stores both cached class representations and native Java `Class` objects, initializing them on-demand with thread-safe synchronization.

- - ### Constructor Summary

    Constructors
    Constructor and description
    `ParameterTypes()` Constructs a `ParameterTypes` with uninitialized parameter types.
    `ParameterTypes(Class[] pt)` Constructs a `ParameterTypes` with the specified native parameter types.
    `ParameterTypes(String[] pt)` Constructs a `ParameterTypes` from class names.
    `ParameterTypes(CachedClass[] pt)` Constructs a `ParameterTypes` with the specified cached parameter types.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public final Object[]` | `coerceArgumentsToClasses(Object[] arguments)` Coerces arguments to match the expected parameter types, handling type conversions and varargs expansion.
    `` | `public Object[]` | `correctArguments(Object[] arguments)` Corrects argument count to match method signature, handling varargs expansion and null filling.
    `` | `public Class[]` | `getNativeParameterTypes()` Returns the native Java `Class` objects for the parameter types.
    `` | `protected Class[]` | `getPT()` Protected method subclasses override to provide parameter types.
    `` | `public CachedClass[]` | `getParameterTypes()` Returns the cached class representations of the parameter types.
    `` | `public boolean` | `isValidExactMethod(Object[] args)` Checks if the given actual arguments exactly match this method's parameter types.
    `` | `public boolean` | `isValidExactMethod(Class[] args)` Checks if the given argument types exactly match this method's parameter types.
    `` | `public boolean` | `isValidMethod(Class[] argumentTypes)` Checks if the given argument types are valid for this method, considering varargs conversion.
    `` | `public boolean` | `isValidMethod(Object[] arguments)` Checks if the given actual arguments are valid for this method, considering varargs conversion.
    `` | `public boolean` | `isVargsMethod()` Returns whether this represents a varargs (variable arguments) method.
    `` | `public boolean` | `isVargsMethod(Object[] arguments)` Checks if this varargs method should treat arguments as a varargs invocation.
    `` | `protected final void` | `setParametersTypes(CachedClass[] pt)` Sets the cached parameter types and determines if this is a varargs method.

  - ### Inherited Methods Summary

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

- - ### Constructor Detail

    - #### public ParameterTypes()

      Constructs a `ParameterTypes` with uninitialized parameter types.

    - #### public ParameterTypes(Class[] pt)

      Constructs a `ParameterTypes` with the specified native parameter types.

      Parameters:
        `pt` - the native Java `Class` array representing method parameters

    - #### @Deprecated
      public ParameterTypes(String[] pt)

      Constructs a `ParameterTypes` from class names.

      deprecated:
        Use ParameterTypes(Class[]) instead
      throws:
        NoClassDefFoundError if any class name cannot be resolved
      Parameters:
        `pt` - an array of fully qualified class names

    - #### public ParameterTypes(CachedClass[] pt)

      Constructs a `ParameterTypes` with the specified cached parameter types.

      Parameters:
        `pt` - an array of cached class objects representing method parameters

  - ### Method Detail

    - #### public final Object[] coerceArgumentsToClasses(Object[] arguments)

      Coerces arguments to match the expected parameter types, handling type conversions and varargs expansion. First corrects argument count for varargs methods, then coerces each argument to its target type.

      throws:
        IllegalArgumentException if null is passed where a primitive type is expected
      Parameters:
        `arguments` - the arguments to coerce
      Returns:
        the coerced argument array

    - #### public Object[] correctArguments(Object[] arguments)

      Corrects argument count to match method signature, handling varargs expansion and null filling. Transforms arguments to match the expected parameter count by expanding varargs arrays or filling nulls.

      Parameters:
        `arguments` - the arguments to correct
      Returns:
        the corrected argument array

    - #### public Class[] getNativeParameterTypes()

      Returns the native Java `Class` objects for the parameter types. Lazily initializes the types on first access.

      Returns:
        an array of native parameter classes

    - #### protected Class[] getPT()

      Protected method subclasses override to provide parameter types. Default implementation throws `UnsupportedOperationException`.

      throws:
        UnsupportedOperationException if not overridden by subclass
      Returns:
        the native parameter class array

    - #### public CachedClass[] getParameterTypes()

      Returns the cached class representations of the parameter types. Lazily initializes the types on first access.

      Returns:
        an array of cached parameter types

    - #### public boolean isValidExactMethod(Object[] args)

      Checks if the given actual arguments exactly match this method's parameter types. All arguments must be assignable to their corresponding parameters.

      Parameters:
        `args` - the actual arguments to validate
      Returns:
        `true` if the arguments are valid for exact invocation; `false` otherwise

    - #### public boolean isValidExactMethod(Class[] args)

      Checks if the given argument types exactly match this method's parameter types. All types must be assignable to their corresponding parameters.

      Parameters:
        `args` - the argument types to validate
      Returns:
        `true` if the types are valid for exact invocation; `false` otherwise

    - #### public boolean isValidMethod(Class[] argumentTypes)

      Checks if the given argument types are valid for this method, considering varargs conversion.

      Parameters:
        `argumentTypes` - the argument types to validate
      Returns:
        `true` if the types match the method parameters; `false` otherwise

    - #### public boolean isValidMethod(Object[] arguments)

      Checks if the given actual arguments are valid for this method, considering varargs conversion.

      Parameters:
        `arguments` - the actual arguments to validate
      Returns:
        `true` if the arguments are valid for this method; `false` otherwise

    - #### public boolean isVargsMethod()

      Returns whether this represents a varargs (variable arguments) method.

      Returns:
        `true` if the last parameter is an array type, `false` otherwise

    - #### public boolean isVargsMethod(Object[] arguments)

      Checks if this varargs method should treat arguments as a varargs invocation.

      Parameters:
        `arguments` - the actual arguments passed to the method
      Returns:
        `true` if varargs conversion is needed, `false` otherwise

    - #### protected final void setParametersTypes(CachedClass[] pt)

      Sets the cached parameter types and determines if this is a varargs method.

      Parameters:
        `pt` - the array of cached parameter types