public final class ClosureMetaClass
extends MetaClassImpl
A metaclass for closures generated by the Groovy compiler. These classes have special characteristics this MetaClass uses. One of these is that a generated Closure has only additional doCall methods, all other methods are in the Closure class as well. To use this fact this MetaClass uses a MetaClass for Closure as static field And delegates calls to this MetaClass if needed. This allows a lean implementation for this MetaClass. Multiple generated closures will then use the same MetaClass for Closure. For static dispatching this class uses the MetaClass of Class, again all instances of this class will share that MetaClass. The Class MetaClass is initialized lazy, because most operations do not need this MetaClass.
The Closure and Class metaclasses are not replaceable.
This MetaClass is for internal usage only!
| Fields inherited from class | Fields |
|---|---|
class MetaClassImpl |
EMPTY_ARGUMENTS, INVOKE_METHOD_METHOD, METHOD_MISSING, PROPERTY_MISSING, STATIC_METHOD_MISSING, STATIC_PROPERTY_MISSING, getPropertyMethod, invokeMethodMethod, isGroovyObject, isMap, metaMethodIndex, registry, setPropertyMethod, theCachedClass, theClass |
| Constructor and description |
|---|
ClosureMetaClass(MetaClassRegistry registry, Class theClass)Constructs a new ClosureMetaClass for the given closure class. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public void |
addMetaBeanProperty(MetaBeanProperty mp)Adds a meta bean property to this metaclass. |
|
public void |
addMetaMethod(MetaMethod method)Adds a meta method to this metaclass. |
|
public void |
addNewInstanceMethod(Method method)Adds a new instance method to this metaclass. |
|
public void |
addNewStaticMethod(Method method)Adds a new static method to this metaclass. |
|
protected void |
applyPropertyDescriptors(PropertyDescriptor[] propertyDescriptors) |
|
public CallSite |
createPogoCallCurrentSite(CallSite site, Class sender, Object[] args)Creates a POGO call site for the current class context. |
|
public CallSite |
createPogoCallSite(CallSite site, Object[] args)Creates a POGO (Plain Old Groovy Object) call site for this metaclass. |
|
public CallSite |
createPojoCallSite(CallSite site, Object receiver, Object[] args)Creates a POJO (Plain Old Java Object) call site for this metaclass. |
|
public Object |
getAttribute(Class sender, Object object, String attribute, boolean useSuper, boolean fromInsideClass)Gets an attribute from the closure or the object it represents. |
|
public List<MetaMethod> |
getMetaMethods()Returns a list of all metamethods in the Closure metaclass. |
|
public MetaProperty |
getMetaProperty(String name)Gets the meta property for the given name from the closure metaclass. |
|
public MetaMethod |
getMethodWithoutCaching(int index, Class sender, String methodName, Class[] arguments, boolean isCallToSuper)Gets a method without using the cache. |
|
public List<MetaMethod> |
getMethods()Returns a list of all methods available to closures, including both closure-specific doCall methods and inherited Closure class methods. |
|
public List<MetaProperty> |
getProperties()Returns a list of all properties available to closures. |
|
public Object |
getProperty(Class sender, Object object, String name, boolean useSuper, boolean fromInsideClass)Gets a property on the closure or the object it represents. |
|
public MetaMethod |
getStaticMetaMethod(String name, Object[] args)Gets a static meta method by name and argument objects. |
|
public MetaMethod |
getStaticMetaMethod(String name, Class[] argTypes)Gets a static meta method by name and argument types. |
|
public void |
initialize()Initializes the closure metaclass by discovering and indexing all closure-related methods. |
|
public Object |
invokeMethod(Class sender, Object object, String methodName, Object[] arguments, boolean isCallToSuper, boolean fromInsideClass) |
|
public Object |
invokeStaticMethod(Object object, String methodName, Object[] arguments)Invokes a static method on the closure class itself. |
|
public MetaMethod |
pickMethod(String methodName, Class[] argumentTypes)Picks the most appropriate method from the available closure methods that matches the given method name and argument types. |
|
public static void |
resetCachedMetaClasses()Resets the cached metaclasses for Closure and Class. |
|
public List |
respondsTo(Object obj, String name, Object[] argTypes)Checks if this metaclass responds to the given method name with the specified argument types. |
|
public List |
respondsTo(Object obj, String name)Checks if this metaclass responds to the given method name. |
|
public Constructor |
retrieveConstructor(Class[] arguments)Retrieves a constructor matching the given argument types. |
|
public MetaMethod |
retrieveStaticMethod(String methodName, Class[] arguments)Retrieves a static method with the given name and argument types. |
|
public void |
setAttribute(Class sender, Object object, String attribute, Object newValue, boolean useSuper, boolean fromInsideClass)Sets an attribute on the closure or the object it represents. |
|
public void |
setProperties(Object bean, Map map)Sets multiple properties on a bean. |
|
public void |
setProperty(Class sender, Object object, String name, Object newValue, boolean useSuper, boolean fromInsideClass)Sets a property on the closure or the object it represents. |
Constructs a new ClosureMetaClass for the given closure class. This metaclass handles method invocation and property access for closure instances, providing special handling for closure-specific behavior.
registry - the metaclass registrytheClass - the closure class this metaclass representsAdds a meta bean property to this metaclass. This operation is not supported for ClosureMetaClass as it is immutable.
mp - the meta bean property to addAdds a meta method to this metaclass. This operation is not supported for ClosureMetaClass as it is immutable.
method - the meta method to addAdds a new instance method to this metaclass. This operation is not supported for ClosureMetaClass as it is immutable.
method - the method to addAdds a new static method to this metaclass. This operation is not supported for ClosureMetaClass as it is immutable.
method - the static method to addCreates a POGO call site for the current class context. Provides optimized method invocation for POGO objects within a specific class context.
site - the call sitesender - the class sending the callargs - the argumentsCreates a POGO (Plain Old Groovy Object) call site for this metaclass. Provides optimized method invocation for POGO objects.
site - the call siteargs - the argumentsCreates a POJO (Plain Old Java Object) call site for this metaclass. This operation is not supported for ClosureMetaClass.
site - the call sitereceiver - the receiver objectargs - the argumentsGets an attribute from the closure or the object it represents. For Class objects, delegates to the static metaclass. For closures, checks the cached fields first before delegating to the Closure metaclass.
sender - the class that is sending this requestobject - the object to get the attribute fromattribute - the name of the attributeuseSuper - whether to use super resolutionfromInsideClass - whether the call is from inside the classReturns a list of all metamethods in the Closure metaclass.
Gets the meta property for the given name from the closure metaclass.
name - the property nameGets a method without using the cache. This operation is not supported for ClosureMetaClass.
index - the method indexsender - the class that is sending this requestmethodName - the name of the methodarguments - the argument typesisCallToSuper - whether this is a call to a super methodReturns a list of all methods available to closures, including both closure-specific doCall methods and inherited Closure class methods.
Returns a list of all properties available to closures.
Gets a property on the closure or the object it represents. For Class objects, delegates to the static metaclass; otherwise delegates to Closure metaclass.
sender - the class that is sending this requestobject - the object to get the property fromname - the name of the propertyuseSuper - whether to use super resolutionfromInsideClass - whether the call is from inside the classGets a static meta method by name and argument objects. Delegates to the Closure metaclass.
name - the name of the static methodargs - the argumentsGets a static meta method by name and argument types. Delegates to the Closure metaclass.
name - the name of the static methodargTypes - the argument typesInitializes the closure metaclass by discovering and indexing all closure-related methods.
Invokes a static method on the closure class itself. Delegates to the static metaclass.
object - the object on which to invoke the static methodmethodName - the name of the static methodarguments - the arguments to pass to the methodPicks the most appropriate method from the available closure methods that matches the given method name and argument types.
methodName - the name of the method to pick (typically "call" or "doCall" for closures)argumentTypes - the types of arguments to match against method signaturesResets the cached metaclasses for Closure and Class. This method is used to reinitialize the metaclass caches when the system configuration changes, ensuring that any cached metaclass information is refreshed.
Checks if this metaclass responds to the given method name with the specified argument types. Returns a list of methods that match the given name and signature.
obj - the object to checkname - the method nameargTypes - the argument typesChecks if this metaclass responds to the given method name. Returns a list of methods that match the given name.
obj - the object to checkname - the method nameRetrieves a constructor matching the given argument types. This operation is not supported for ClosureMetaClass.
arguments - the argument typesRetrieves a static method with the given name and argument types. Closures do not support static methods, so this always returns null.
methodName - the name of the static method to retrievearguments - the argument typesSets an attribute on the closure or the object it represents. For Class objects, delegates to the static metaclass. For closures, checks the cached fields first before delegating to the Closure metaclass.
sender - the class that is sending this requestobject - the object on which to set the attributeattribute - the name of the attributenewValue - the new value for the attributeuseSuper - whether to use super resolutionfromInsideClass - whether the call is from inside the classSets multiple properties on a bean. This operation is not supported for ClosureMetaClass.
bean - the bean objectmap - the properties to setSets a property on the closure or the object it represents. For Class objects, delegates to the static metaclass; otherwise delegates to Closure metaclass.
sender - the class that is sending this requestobject - the object on which to set the propertyname - the name of the propertynewValue - the new value for the propertyuseSuper - whether to use super resolutionfromInsideClass - whether the call is from inside the classCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.