Package org.codehaus.groovy.reflection

# Class ParameterTypes

java.lang.Object
org.codehaus.groovy.reflection.ParameterTypes

Direct Known Subclasses:
  `CachedConstructor`, `MetaMethod`

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
  Description
  `ParameterTypes()`
  Constructs a `ParameterTypes` with uninitialized parameter types.
  `ParameterTypes(Class[] pt)`
  Constructs a `ParameterTypes` with the specified native parameter types.
  `ParameterTypes(String[] pt)`
  Deprecated.
  Use `ParameterTypes(Class[])` instead
  `ParameterTypes(CachedClass[] pt)`
  Constructs a `ParameterTypes` with the specified cached parameter types.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `final Object[]`
  `coerceArgumentsToClasses(Object[] arguments)`
  Coerces arguments to match the expected parameter types, handling type conversions and varargs expansion.
  `Object[]`
  `correctArguments(Object[] arguments)`
  Corrects argument count to match method signature, handling varargs expansion and null filling.
  `Class[]`
  `getNativeParameterTypes()`
  Returns the native Java `Class` objects for the parameter types.
  `CachedClass[]`
  `getParameterTypes()`
  Returns the cached class representations of the parameter types.
  `protected Class[]`
  `getPT()`
  Protected method subclasses override to provide parameter types.
  `boolean`
  `isValidExactMethod(Class[] args)`
  Checks if the given argument types exactly match this method's parameter types.
  `boolean`
  `isValidExactMethod(Object[] args)`
  Checks if the given actual arguments exactly match this method's parameter types.
  `boolean`
  `isValidMethod(Class[] argumentTypes)`
  Checks if the given argument types are valid for this method, considering varargs conversion.
  `boolean`
  `isValidMethod(Object[] arguments)`
  Checks if the given actual arguments are valid for this method, considering varargs conversion.
  `boolean`
  `isVargsMethod()`
  Returns whether this represents a varargs (variable arguments) method.
  `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.

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

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

- ## Constructor Details

  - ### ParameterTypes

    public ParameterTypes()
    Constructs a `ParameterTypes` with uninitialized parameter types.

  - ### ParameterTypes

    public ParameterTypes(Class[] pt)
    Constructs a `ParameterTypes` with the specified native parameter types.
    Parameters:
      `pt` - the native Java `Class` array representing method parameters

  - ### ParameterTypes

    @Deprecated public ParameterTypes(String[] pt)
    Deprecated.
    Use `ParameterTypes(Class[])` instead
    Constructs a `ParameterTypes` from class names.
    Parameters:
      `pt` - an array of fully qualified class names
    Throws:
      `NoClassDefFoundError` - if any class name cannot be resolved

  - ### ParameterTypes

    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 Details

  - ### setParametersTypes

    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

  - ### getParameterTypes

    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

  - ### getNativeParameterTypes

    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

  - ### getPT

    protected Class[] getPT()
    Protected method subclasses override to provide parameter types. Default implementation throws `UnsupportedOperationException`.
    Returns:
      the native parameter class array
    Throws:
      `UnsupportedOperationException` - if not overridden by subclass

  - ### isVargsMethod

    public boolean isVargsMethod()
    Returns whether this represents a varargs (variable arguments) method.
    Returns:
      `true` if the last parameter is an array type, `false` otherwise

  - ### isVargsMethod

    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

  - ### coerceArgumentsToClasses

    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.
    Parameters:
      `arguments` - the arguments to coerce
    Returns:
      the coerced argument array
    Throws:
      `IllegalArgumentException` - if null is passed where a primitive type is expected

  - ### correctArguments

    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

  - ### isValidMethod

    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

  - ### isValidExactMethod

    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

  - ### isValidExactMethod

    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

  - ### isValidMethod

    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