Package org.codehaus.groovy.reflection
Class CachedMethod
java.lang.Object
org.codehaus.groovy.reflection.ParameterTypes
groovy.lang.MetaMethod
org.codehaus.groovy.reflection.CachedMethod
- All Implemented Interfaces:
MetaMember,Cloneable,Comparable
Caches reflection information about a single method for fast lookup and invocation.
Extends MetaMethod and implements Comparable for method sorting.
Provides efficient access to method metadata and supports call site optimization.
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal CachedClassThe cached class that declares this method.static final CachedMethod[]An empty array constant representing zero cached methods. -
Constructor Summary
ConstructorsConstructorDescriptionCachedMethod(Method method) Constructs aCachedMethodfor the given Java method.CachedMethod(CachedClass clazz, Method method) Constructs aCachedMethodfor the given method within a cached class. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanAccessLegally(Class<?> callerClass) Checks whether the given caller class can legally access this method.intCompares this cached method with another method-like object for ordering.createPogoMetaMethodSite(CallSite site, MetaClassImpl metaClass, Class[] params) Creates an optimized call site for invoking this method on POGO (Groovy) objects.createPojoMetaMethodSite(CallSite site, MetaClassImpl metaClass, Class[] params) Creates an optimized call site for invoking this method on POJO (plain Java) objects.createStaticMetaMethodSite(CallSite site, MetaClassImpl metaClass, Class[] params) Creates an optimized call site for invoking this static method.booleanChecks equality with another method.static CachedMethodFinds aCachedMethodcorresponding to the specified Java method by searching the cached methods of its declaring class.<T extends Annotation>
TgetAnnotation(Class<T> annotationClass) Returns the annotation of the specified type on this method, if present.Returns the underlying Java method, making it accessible if necessary.Returns the cached class that declares this method.Returns the bytecode method descriptor for this method (e.g., "(II)Z").intReturns the modifiers of this method (e.g., public, static, synchronized).getName()Returns the name of this method.intReturns the number of parameters this method accepts.Returns the parameter type information for this method.Class[]getPT()Returns the native Java parameter types of this method.Returns the return type of this method.Returns the complete method signature (name + bytecode descriptor).Returns the transformed version of this method, if one exists.inthashCode()Returns the hash code for this cached method based on the underlying Java method.final ObjectInvokes this method on the given object with the specified arguments.booleanReturns whether this method is synthetic (generated by the compiler).final MethodMakes this method accessible and returns the underlying Java method.voidsetTransformedMethod(CachedMethod transformedMethod) Sets the transformed version of this method.toString()Returns the string representation of the underlying Java method.Methods inherited from class groovy.lang.MetaMethod
checkParameters, clone, doMethodInvoke, equal, equal, getMopName, isAbstract, isCacheable, isDefault, isMethod, isSame, processDoMethodInvokeExceptionMethods 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
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface groovy.lang.MetaMember
isFinal, isPackagePrivate, isPrivate, isProtected, isPublic, isStatic
-
Field Details
-
EMPTY_ARRAY
An empty array constant representing zero cached methods. -
cachedClass
The cached class that declares this method.
-
-
Constructor Details
-
CachedMethod
Constructs aCachedMethodfor the given method within a cached class.- Parameters:
clazz- the cached class that declares this methodmethod- the Java method to cache
-
CachedMethod
Constructs aCachedMethodfor the given Java method. Automatically resolves the cached class from the method's declaring class.- Parameters:
method- the Java method to cache
-
-
Method Details
-
find
Finds aCachedMethodcorresponding to the specified Java method by searching the cached methods of its declaring class.- Parameters:
method- the method to find- Returns:
- the cached method, or
nullif not found
-
compareTo
Compares this cached method with another method-like object for ordering. Comparison is based on method name, return type, parameters, and declaring class.- Specified by:
compareToin interfaceComparable- Parameters:
other- the object to compare with (typically anotherCachedMethodorMethod)- Returns:
- a negative, zero, or positive value if this method is less than, equal to, or greater than the other
-
equals
Checks equality with another method. Two methods are equal if they represent the same underlying Java method. -
hashCode
public int hashCode()Returns the hash code for this cached method based on the underlying Java method. -
toString
Returns the string representation of the underlying Java method.- Overrides:
toStringin classMetaMethod- Returns:
- a string representation of this cached method
-
canAccessLegally
Checks whether the given caller class can legally access this method.- Parameters:
callerClass- the class attempting to access this method- Returns:
trueif access is allowed;falseotherwise
-
getAnnotation
Returns the annotation of the specified type on this method, if present.- Type Parameters:
T- the annotation type- Parameters:
annotationClass- the class of the annotation to retrieve- Returns:
- the annotation instance, or
nullif not present
-
getCachedMethod
Returns the underlying Java method, making it accessible if necessary.- Returns:
- the cached method with accessibility ensured
-
getDeclaringClass
Returns the cached class that declares this method.- Specified by:
getDeclaringClassin classMetaMethod- Returns:
- the declaring cached class
-
getDescriptor
Returns the bytecode method descriptor for this method (e.g., "(II)Z"). The descriptor encodes parameter and return types in JVM format.- Overrides:
getDescriptorin classMetaMethod- Returns:
- the method descriptor string
-
getModifiers
public int getModifiers()Returns the modifiers of this method (e.g., public, static, synchronized). SeeModifierfor modifier constants.- Specified by:
getModifiersin interfaceMetaMember- Specified by:
getModifiersin classMetaMethod- Returns:
- the method modifiers
-
getName
Returns the name of this method.- Specified by:
getNamein interfaceMetaMember- Specified by:
getNamein classMetaMethod- Returns:
- the method name
-
getParamsCount
public int getParamsCount()Returns the number of parameters this method accepts.- Returns:
- the parameter count
-
getParamTypes
Returns the parameter type information for this method.Note: This method always returns
nulland is retained for compatibility.- Returns:
null
-
getPT
Returns the native Java parameter types of this method.- Overrides:
getPTin classParameterTypes- Returns:
- an array of parameter classes
-
getReturnType
Returns the return type of this method.- Specified by:
getReturnTypein classMetaMethod- Returns:
- the method's return class
-
getSignature
Returns the complete method signature (name + bytecode descriptor). For example: "toString()Ljava/lang/String;"- Overrides:
getSignaturein classMetaMethod- Returns:
- the method signature
-
isSynthetic
public boolean isSynthetic()Returns whether this method is synthetic (generated by the compiler).- Specified by:
isSyntheticin interfaceMetaMember- Returns:
trueif this method is synthetic;falseotherwise
-
getTransformedMethod
Returns the transformed version of this method, if one exists. Transformed methods are compiler-optimized variants.- Returns:
- the transformed method, or
nullif no transformation exists
-
setTransformedMethod
Sets the transformed version of this method.- Parameters:
transformedMethod- the transformed method, ornullto clear
-
createPogoMetaMethodSite
Creates an optimized call site for invoking this method on POGO (Groovy) objects. Attempts to compile the method for maximum performance.- Parameters:
site- the call site being createdmetaClass- the metaclass of the target object's classparams- the parameter types of the call- Returns:
- a call site optimized for POGO invocation
-
createPojoMetaMethodSite
Creates an optimized call site for invoking this method on POJO (plain Java) objects. Attempts to compile the method for maximum performance.- Parameters:
site- the call site being createdmetaClass- the metaclass of the target object's classparams- the parameter types of the call- Returns:
- a call site optimized for POJO invocation
-
createStaticMetaMethodSite
Creates an optimized call site for invoking this static method. Attempts to compile the method for maximum performance.- Parameters:
site- the call site being createdmetaClass- the metaclass associated with the static methodparams- the parameter types of the call- Returns:
- a call site optimized for static method invocation
-
invoke
Invokes this method on the given object with the specified arguments. Handles accessibility, exception wrapping, and method invocation.- Specified by:
invokein classMetaMethod- Parameters:
object- the target object (may benullfor static methods)arguments- the arguments to pass to the method- Returns:
- the result of the method invocation
- Throws:
InvokerInvocationException- if the method raises a checked exception or illegal access occursRuntimeException- if the method raises an uncaught exception (except MissingMethodException)
-
setAccessible
Makes this method accessible and returns the underlying Java method. Synonym forgetCachedMethod().- Returns:
- the cached method with accessibility ensured
-