Package org.codehaus.groovy.reflection
Class CachedConstructor
java.lang.Object
org.codehaus.groovy.reflection.ParameterTypes
org.codehaus.groovy.reflection.CachedConstructor
- All Implemented Interfaces:
MetaMember
Caches reflection information about a single constructor for fast lookup and invocation.
Extends ParameterTypes to manage parameter type information and implements
MetaMember for meta-programming support. Provides methods to invoke
constructors with argument coercion and error handling.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs aCachedConstructorfor the given Java constructor.CachedConstructor(CachedClass clazz, Constructor c) Constructs aCachedConstructorfor the given constructor within a cached class. -
Method Summary
Modifier and TypeMethodDescriptiondoConstructorInvoke(Object[] argumentArray) Invokes this constructor with the specified arguments after coercing them to the parameter types.static CachedConstructorfind(Constructor constructor) Finds aCachedConstructorcorresponding to the specified Java constructor by searching the cached constructors of its declaring class.Returns the cached class that declares this constructor.Returns the underlying Java constructor object, making it accessible if necessary.Returns the class that declares this constructor.intReturns the modifiers of this constructor (e.g., public, private, protected).getName()Returns the name of the constructor (same as the declaring class name).protected Class[]getPT()Protected method subclasses override to provide parameter types.Invokes this constructor with the specified arguments.booleanReturns whether this constructor is synthetic (generated by the compiler).toString()Returns the string representation of this cached constructor.Methods inherited from class org.codehaus.groovy.reflection.ParameterTypes
coerceArgumentsToClasses, correctArguments, getNativeParameterTypes, getParameterTypes, isValidExactMethod, isValidExactMethod, isValidMethod, isValidMethod, isVargsMethod, isVargsMethod, setParametersTypesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface groovy.lang.MetaMember
isFinal, isPackagePrivate, isPrivate, isProtected, isPublic, isStatic
-
Constructor Details
-
CachedConstructor
Constructs aCachedConstructorfor the given constructor within a cached class.- Parameters:
clazz- the cached class that declares this constructorc- the Java constructor to cache
-
CachedConstructor
Constructs aCachedConstructorfor the given Java constructor. Automatically resolves the cached class from the constructor's declaring class.- Parameters:
c- the Java constructor to cache
-
-
Method Details
-
getPT
Description copied from class:ParameterTypesProtected method subclasses override to provide parameter types. Default implementation throwsUnsupportedOperationException.- Overrides:
getPTin classParameterTypes- Returns:
- the native parameter class array
-
getName
Returns the name of the constructor (same as the declaring class name).- Specified by:
getNamein interfaceMetaMember- Returns:
- the constructor name
-
getModifiers
public int getModifiers()Returns the modifiers of this constructor (e.g., public, private, protected). SeeModifierfor modifier constants.- Specified by:
getModifiersin interfaceMetaMember- Returns:
- the constructor modifiers
-
isSynthetic
public boolean isSynthetic()Returns whether this constructor is synthetic (generated by the compiler).- Specified by:
isSyntheticin interfaceMetaMember- Returns:
trueif this constructor is synthetic;falseotherwise
-
toString
Returns the string representation of this cached constructor. -
find
Finds aCachedConstructorcorresponding to the specified Java constructor by searching the cached constructors of its declaring class.- Parameters:
constructor- the constructor to find- Returns:
- the cached constructor
- Throws:
RuntimeException- if the constructor is not found in the cache
-
doConstructorInvoke
Invokes this constructor with the specified arguments after coercing them to the parameter types.- Parameters:
argumentArray- the arguments to pass to the constructor- Returns:
- a new instance of the class
- Throws:
GroovyRuntimeException- if the invocation fails
-
invoke
Invokes this constructor with the specified arguments. Handles access control, abstract class checks, and exception wrapping.- Parameters:
argumentArray- the arguments to pass to the constructor- Returns:
- a new instance of the class
- Throws:
GroovyRuntimeException- if invocation fails, access is denied, or the class is abstract
-
getCachedClass
Returns the cached class that declares this constructor.- Returns:
- the cached class
-
getDeclaringClass
Returns the class that declares this constructor.- Returns:
- the declaring class
-
getCachedConstructor
Returns the underlying Java constructor object, making it accessible if necessary.- Returns:
- the cached constructor
-