Package org.codehaus.groovy.reflection
Class ParameterTypes
java.lang.Object
org.codehaus.groovy.reflection.ParameterTypes
- Direct Known Subclasses:
CachedConstructor,MetaMethod
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
ConstructorsConstructorDescriptionConstructs aParameterTypeswith uninitialized parameter types.ParameterTypes(Class[] pt) Constructs aParameterTypeswith the specified native parameter types.ParameterTypes(String[] pt) Deprecated.ParameterTypes(CachedClass[] pt) Constructs aParameterTypeswith the specified cached parameter types. -
Method Summary
Modifier and TypeMethodDescriptionfinal 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[]Returns the native JavaClassobjects for the parameter types.Returns the cached class representations of the parameter types.protected Class[]getPT()Protected method subclasses override to provide parameter types.booleanisValidExactMethod(Class[] args) Checks if the given argument types exactly match this method's parameter types.booleanisValidExactMethod(Object[] args) Checks if the given actual arguments exactly match this method's parameter types.booleanisValidMethod(Class[] argumentTypes) Checks if the given argument types are valid for this method, considering varargs conversion.booleanisValidMethod(Object[] arguments) Checks if the given actual arguments are valid for this method, considering varargs conversion.booleanReturns whether this represents a varargs (variable arguments) method.booleanisVargsMethod(Object[] arguments) Checks if this varargs method should treat arguments as a varargs invocation.protected final voidSets the cached parameter types and determines if this is a varargs method.
-
Constructor Details
-
ParameterTypes
public ParameterTypes()Constructs aParameterTypeswith uninitialized parameter types. -
ParameterTypes
Constructs aParameterTypeswith the specified native parameter types.- Parameters:
pt- the native JavaClassarray representing method parameters
-
ParameterTypes
Deprecated.UseParameterTypes(Class[])insteadConstructs aParameterTypesfrom class names.- Parameters:
pt- an array of fully qualified class names- Throws:
NoClassDefFoundError- if any class name cannot be resolved
-
ParameterTypes
Constructs aParameterTypeswith the specified cached parameter types.- Parameters:
pt- an array of cached class objects representing method parameters
-
-
Method Details
-
setParametersTypes
Sets the cached parameter types and determines if this is a varargs method.- Parameters:
pt- the array of cached parameter types
-
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
Returns the native JavaClassobjects for the parameter types. Lazily initializes the types on first access.- Returns:
- an array of native parameter classes
-
getPT
Protected method subclasses override to provide parameter types. Default implementation throwsUnsupportedOperationException.- 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:
trueif the last parameter is an array type,falseotherwise
-
isVargsMethod
Checks if this varargs method should treat arguments as a varargs invocation.- Parameters:
arguments- the actual arguments passed to the method- Returns:
trueif varargs conversion is needed,falseotherwise
-
coerceArgumentsToClasses
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
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
Checks if the given argument types are valid for this method, considering varargs conversion.- Parameters:
argumentTypes- the argument types to validate- Returns:
trueif the types match the method parameters;falseotherwise
-
isValidExactMethod
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:
trueif the arguments are valid for exact invocation;falseotherwise
-
isValidExactMethod
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:
trueif the types are valid for exact invocation;falseotherwise
-
isValidMethod
Checks if the given actual arguments are valid for this method, considering varargs conversion.- Parameters:
arguments- the actual arguments to validate- Returns:
trueif the arguments are valid for this method;falseotherwise
-
ParameterTypes(Class[])instead