Class ClosureMetaMethod
java.lang.Object
org.codehaus.groovy.reflection.ParameterTypes
groovy.lang.MetaMethod
org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod
- All Implemented Interfaces:
ClosureInvokingMethod,MetaMember,Cloneable
A MetaMethod that accepts a closure in the constructor which is invoked when the MetaMethod is called.
The delegate of the closure is set to the instance that the MetaMethod is invoked on when called.
- Since:
- 1.5
-
Field Summary
Fields inherited from class groovy.lang.MetaMethod
EMPTY_ARRAY -
Constructor Summary
ConstructorsConstructorDescriptionClosureMetaMethod(String name, Closure c, CachedMethod doCall) Constructs a new ClosureMetaMethod with the specified name and closure.ClosureMetaMethod(String name, Class declaringClass, Closure c, CachedMethod doCall) Constructs a new ClosureMetaMethod with the specified name, declaring class, and closure. -
Method Summary
Modifier and TypeMethodDescriptionstatic ClosureMetaMethodcopy(ClosureMetaMethod closureMethod) Creates a copy of the given ClosureMetaMethod.static List<MetaMethod>createMethodList(String name, Class declaringClass, Closure closure) Creates a list of MetaMethod instances from the given closure.Retrieves the closure that is invoked by this MetaMethodReturns the cached class that declares this meta method.Returns the cached method that represents the closure's doCall method.intReturns the modifiers for this method.getName()Returns the name of this closure meta method.Returns the return type of this method.Invokes the closure with the given arguments.Methods inherited from class groovy.lang.MetaMethod
checkParameters, clone, doMethodInvoke, equal, equal, getDescriptor, getMopName, getSignature, isAbstract, isCacheable, isDefault, isMethod, isSame, processDoMethodInvokeException, toStringMethods inherited from class org.codehaus.groovy.reflection.ParameterTypes
coerceArgumentsToClasses, correctArguments, getNativeParameterTypes, getParameterTypes, getPT, isValidExactMethod, isValidExactMethod, isValidMethod, isValidMethod, isVargsMethod, isVargsMethod, setParametersTypesMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface groovy.lang.MetaMember
isFinal, isPackagePrivate, isPrivate, isProtected, isPublic, isStatic, isSynthetic
-
Constructor Details
-
ClosureMetaMethod
Constructs a new ClosureMetaMethod with the specified name and closure. The declaring class is obtained from the closure's owner.- Parameters:
name- the name of the methodc- the closure to invoke when this method is calleddoCall- the cached method representing the closure's doCall method
-
ClosureMetaMethod
Constructs a new ClosureMetaMethod with the specified name, declaring class, and closure.- Parameters:
name- the name of the methoddeclaringClass- the class that declares this meta methodc- the closure to invoke when this method is calleddoCall- the cached method representing the closure's doCall method
-
-
Method Details
-
getModifiers
public int getModifiers()Returns the modifiers for this method.- Specified by:
getModifiersin interfaceMetaMember- Specified by:
getModifiersin classMetaMethod- Returns:
- Modifier.PUBLIC
-
getName
Returns the name of this closure meta method.- Specified by:
getNamein interfaceMetaMember- Specified by:
getNamein classMetaMethod- Returns:
- the name of the method
-
getReturnType
Returns the return type of this method.- Specified by:
getReturnTypein classMetaMethod- Returns:
- Object.class, as closures return Object
-
getDeclaringClass
Returns the cached class that declares this meta method.- Specified by:
getDeclaringClassin classMetaMethod- Returns:
- the declaring class
-
invoke
Invokes the closure with the given arguments. The closure's delegate is set to the object on which this method is being invoked.- Specified by:
invokein classMetaMethod- Parameters:
object- the object on which the method is invoked (becomes the closure's delegate)arguments- the arguments to pass to the closure- Returns:
- the result of the closure invocation
-
getClosure
Retrieves the closure that is invoked by this MetaMethod- Specified by:
getClosurein interfaceClosureInvokingMethod- Returns:
- The closure
-
createMethodList
Creates a list of MetaMethod instances from the given closure. Handles MethodClosure, GeneratedClosure, and anonymous closures appropriately.- Parameters:
name- the name of the methoddeclaringClass- the class that declares this meta methodclosure- the closure to create meta methods from- Returns:
- a list of MetaMethod instances
-
getDoCall
Returns the cached method that represents the closure's doCall method.- Returns:
- the cached doCall method
-
copy
Creates a copy of the given ClosureMetaMethod. If the method is a MethodClosureMetaMethod, returns a new MethodClosureMetaMethod; otherwise returns a new ClosureMetaMethod.- Parameters:
closureMethod- the closure meta method to copy- Returns:
- a copy of the closure meta method
-