Class ClosureMetaClass
- All Implemented Interfaces:
MetaClass
,MetaObjectProtocol
,MutableMetaClass
public final class ClosureMetaClass extends MetaClassImpl
The Closure and Class MetaClasses are not replaceable.
This MetaClass is for internal usage only!
- Since:
- 1.5
-
Nested Class Summary
Nested classes/interfaces inherited from class groovy.lang.MetaClassImpl
MetaClassImpl.Index, MetaClassImpl.MetaConstructor
-
Field Summary
Fields inherited from class groovy.lang.MetaClassImpl
getPropertyMethod, INVOKE_METHOD_METHOD, invokeMethodMethod, isGroovyObject, isMap, metaMethodIndex, METHOD_MISSING, PROPERTY_MISSING, registry, setPropertyMethod, STATIC_METHOD_MISSING, STATIC_PROPERTY_MISSING, theCachedClass, theClass
-
Constructor Summary
Constructors Constructor Description ClosureMetaClass(MetaClassRegistry registry, java.lang.Class theClass)
-
Method Summary
Modifier and Type Method Description void
addMetaBeanProperty(MetaBeanProperty mp)
Adds a new MetaBeanProperty to this MetaClassvoid
addMetaMethod(MetaMethod method)
adds a MetaMethod to this class.void
addNewInstanceMethod(java.lang.reflect.Method method)
Adds an instance method to this metaclass.void
addNewStaticMethod(java.lang.reflect.Method method)
Adds a static method to this metaclass.protected void
applyPropertyDescriptors(java.beans.PropertyDescriptor[] propertyDescriptors)
CallSite
createPogoCallCurrentSite(CallSite site, java.lang.Class sender, java.lang.Object[] args)
Create a CallSiteCallSite
createPogoCallSite(CallSite site, java.lang.Object[] args)
Create a CallSiteCallSite
createPojoCallSite(CallSite site, java.lang.Object receiver, java.lang.Object[] args)
Create a CallSitejava.lang.Object
getAttribute(java.lang.Class sender, java.lang.Object object, java.lang.String attribute, boolean useSuper, boolean fromInsideClass)
Retrieves the value of an attribute (field).java.util.List<MetaMethod>
getMetaMethods()
Retrieves the list of MetaMethods held by this class.MetaProperty
getMetaProperty(java.lang.String name)
Returns a MetaProperty for the given name or null if it doesn't existjava.util.List<MetaMethod>
getMethods()
Retrieves the list of MetaMethods held by the class.MetaMethod
getMethodWithoutCaching(int index, java.lang.Class sender, java.lang.String methodName, java.lang.Class[] arguments, boolean isCallToSuper)
java.util.List<MetaProperty>
getProperties()
Get all the properties defined for this typejava.lang.Object
getProperty(java.lang.Class sender, java.lang.Object object, java.lang.String name, boolean useSuper, boolean fromInsideClass)
Retrieves a property on the given receiver for the specified arguments.MetaMethod
getStaticMetaMethod(java.lang.String name, java.lang.Class[] argTypes)
MetaMethod
getStaticMetaMethod(java.lang.String name, java.lang.Object[] args)
Retrieves a static MetaMethod for the given name and argument values, using the types of the arguments to establish the chosen MetaMethodvoid
initialize()
Complete the initialisation process.java.lang.Object
invokeMethod(java.lang.Class sender, java.lang.Object object, java.lang.String methodName, java.lang.Object[] originalArguments, boolean isCallToSuper, boolean fromInsideClass)
Invokes a method on the given receiver for the specified arguments.java.lang.Object
invokeStaticMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object[] arguments)
Invokes a static method on the given Object with the given name and arguments.protected boolean
isInitialized()
MetaMethod
pickMethod(java.lang.String name, java.lang.Class[] argTypes)
Selects a method by name and argument classes.static void
resetCachedMetaClasses()
java.util.List
respondsTo(java.lang.Object obj, java.lang.String name)
Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name regardless of arguments.java.util.List
respondsTo(java.lang.Object obj, java.lang.String name, java.lang.Object[] argTypes)
Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name and arguments types.java.lang.reflect.Constructor
retrieveConstructor(java.lang.Class[] arguments)
MetaMethod
retrieveStaticMethod(java.lang.String methodName, java.lang.Class[] arguments)
void
setAttribute(java.lang.Class sender, java.lang.Object object, java.lang.String attribute, java.lang.Object newValue, boolean useSuper, boolean fromInsideClass)
Sets an attribute on the given receiver for the specified arguments.protected void
setInitialized(boolean initialized)
void
setProperties(java.lang.Object bean, java.util.Map map)
Sets a number of bean properties from the given Map where the keys are the String names of properties and the values are the values of the properties to setvoid
setProperty(java.lang.Class sender, java.lang.Object object, java.lang.String name, java.lang.Object newValue, boolean useSuper, boolean fromInsideClass)
Retrieves a property on the given receiver for the specified arguments.Methods inherited from class groovy.lang.MetaClassImpl
addMetaMethodToIndex, checkIfGroovyObjectMethod, checkInitalised, chooseMethod, clearInvocationCaches, createConstructorSite, createErrorMessageForAmbiguity, createStaticSite, createTransformMetaMethod, doChooseMostSpecificParams, dropMethodCache, dropStaticMethodCache, findMethodInClassHierarchy, findMixinMethod, findOwnMethod, findPropertyInClassHierarchy, getAdditionalMetaMethods, getAttribute, getAttribute, getClassInfo, getClassNode, getEffectiveGetMetaProperty, getMetaMethod, getMethodWithCaching, getMethodWithoutCaching, getProperty, getRegistry, getSubclassMetaMethods, getSuperClasses, getTheCachedClass, getTheClass, getVersion, handleMatches, hasCustomInvokeMethod, hasCustomStaticInvokeMethod, hasProperty, incVersion, invokeConstructor, invokeMethod, invokeMethod, invokeMissingMethod, invokeMissingProperty, invokeStaticMissingProperty, isGroovyObject, isModified, isPermissivePropertyAccess, onGetPropertyFoundInHierarchy, onInvokeMethodFoundInHierarchy, onMixinMethodFound, onSetPropertyFoundInHierarchy, onSuperMethodFoundInHierarchy, onSuperPropertyFoundInHierarchy, reinitialize, retrieveConstructor, retrieveStaticMethod, selectConstructorAndTransformArguments, setAttribute, setPermissivePropertyAccess, setProperty, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Constructor Details
-
ClosureMetaClass
-
-
Method Details
-
resetCachedMetaClasses
public static void resetCachedMetaClasses() -
getMetaProperty
Description copied from interface:MetaObjectProtocol
Returns a MetaProperty for the given name or null if it doesn't exist- Specified by:
getMetaProperty
in interfaceMetaObjectProtocol
- Overrides:
getMetaProperty
in classMetaClassImpl
- Parameters:
name
- The name of the MetaProperty- Returns:
- A MetaProperty or null
- See Also:
MetaObjectProtocol.getMetaProperty(String)
-
invokeMethod
public java.lang.Object invokeMethod(java.lang.Class sender, java.lang.Object object, java.lang.String methodName, java.lang.Object[] originalArguments, boolean isCallToSuper, boolean fromInsideClass)Description copied from class:MetaClassImpl
Invokes a method on the given receiver for the specified arguments. The sender is the class that invoked the method on the object. The MetaClass will attempt to establish the method to invoke based on the name and arguments provided.
The isCallToSuper and fromInsideClass help the Groovy runtime perform optimisations on the call to go directly to the super class if necessary
- Specified by:
invokeMethod
in interfaceMetaClass
- Overrides:
invokeMethod
in classMetaClassImpl
- Parameters:
sender
- The java.lang.Class instance that invoked the methodobject
- The object which the method was invoked onmethodName
- The name of the methodoriginalArguments
- The arguments to the methodisCallToSuper
- Whether the method is a call to a super class methodfromInsideClass
- Whether the call was invoked from the inside or the outside of the class- Returns:
- The return value of the method
- See Also:
MetaClass.invokeMethod(Class, Object, String, Object[], boolean, boolean)
-
initialize
public void initialize()Description copied from class:MetaClassImpl
Complete the initialisation process. After this method is called no methods should be added to the meta class. Invocation of methods or access to fields/properties is forbidden unless this method is called. This method should contain any initialisation code, taking a longer time to complete. An example is the creation of the Reflector. It is suggested to synchronize this method.- Specified by:
initialize
in interfaceMetaClass
- Overrides:
initialize
in classMetaClassImpl
-
getMethods
Description copied from class:MetaClassImpl
Retrieves the list of MetaMethods held by the class. This list does not include MetaMethods added by groovy.lang.ExpandoMetaClass.- Specified by:
getMethods
in interfaceMetaClass
- Specified by:
getMethods
in interfaceMetaObjectProtocol
- Overrides:
getMethods
in classMetaClassImpl
- Returns:
- A list of MetaMethods
- See Also:
MetaMethod
-
getMetaMethods
Description copied from class:MetaClassImpl
Retrieves the list of MetaMethods held by this class. This list includes MetaMethods added by groovy.lang.ExpandoMetaClass.- Specified by:
getMetaMethods
in interfaceMetaClass
- Overrides:
getMetaMethods
in classMetaClassImpl
- Returns:
- A list of MetaMethods
-
getProperties
Description copied from class:MetaClassImpl
Get all the properties defined for this type- Specified by:
getProperties
in interfaceMetaClass
- Specified by:
getProperties
in interfaceMetaObjectProtocol
- Overrides:
getProperties
in classMetaClassImpl
- Returns:
- a list of MetaProperty objects
- See Also:
MetaProperty
-
pickMethod
Description copied from class:MetaClassImpl
Selects a method by name and argument classes. This method does not search for an exact match, it searches for a compatible method. For this the method selection mechanism is used as provided by the implementation of this MetaClass. pickMethod may or may not be used during the method selection process when invoking a method. There is no warranty for that.- Specified by:
pickMethod
in interfaceMetaClass
- Overrides:
pickMethod
in classMetaClassImpl
- Parameters:
name
- the name of the method to pickargTypes
- the method arguments- Returns:
- a matching MetaMethod or null
-
retrieveStaticMethod
-
isInitialized
protected boolean isInitialized()- Overrides:
isInitialized
in classMetaClassImpl
-
setInitialized
protected void setInitialized(boolean initialized)- Overrides:
setInitialized
in classMetaClassImpl
-
getStaticMetaMethod
Description copied from interface:MetaObjectProtocol
Retrieves a static MetaMethod for the given name and argument values, using the types of the arguments to establish the chosen MetaMethod- Specified by:
getStaticMetaMethod
in interfaceMetaObjectProtocol
- Overrides:
getStaticMetaMethod
in classMetaClassImpl
- Parameters:
name
- The name of the MetaMethodargs
- The argument types- Returns:
- A MetaMethod or null if it doesn't exist
- See Also:
MetaObjectProtocol.getStaticMetaMethod(String, Object[])
-
getStaticMetaMethod
-
getProperty
public java.lang.Object getProperty(java.lang.Class sender, java.lang.Object object, java.lang.String name, boolean useSuper, boolean fromInsideClass)Description copied from interface:MetaClass
Retrieves a property on the given receiver for the specified arguments. The sender is the class that is requesting the property from the object. The MetaClass will attempt to establish the method to invoke based on the name and arguments provided.
The isCallToSuper and fromInsideClass help the Groovy runtime perform optimisations on the call to go directly to the super class if necessary
- Specified by:
getProperty
in interfaceMetaClass
- Overrides:
getProperty
in classMetaClassImpl
- Parameters:
sender
- The java.lang.Class instance that requested the propertyobject
- The Object which the property is being retrieved fromname
- The name of the propertyuseSuper
- Whether the call is to a super class propertyfromInsideClass
- ??- Returns:
- the given property's value on the object
-
getAttribute
public java.lang.Object getAttribute(java.lang.Class sender, java.lang.Object object, java.lang.String attribute, boolean useSuper, boolean fromInsideClass)Description copied from class:MetaClassImpl
Retrieves the value of an attribute (field). This method is to support the Groovy runtime and not for general client API usage.- Overrides:
getAttribute
in classMetaClassImpl
- Parameters:
sender
- The class of the object that requested the attributeobject
- The instance the attribute is to be retrieved fromattribute
- The name of the attributeuseSuper
- Whether to look-up on the super class or notfromInsideClass
- Whether the call was invoked from the inside or the outside of the class.- Returns:
- The attribute value
-
setAttribute
public void setAttribute(java.lang.Class sender, java.lang.Object object, java.lang.String attribute, java.lang.Object newValue, boolean useSuper, boolean fromInsideClass)Description copied from class:MetaClassImpl
Sets an attribute on the given receiver for the specified arguments. The sender is the class that is setting the attribute from the object. The MetaClass will attempt to establish the method to invoke based on the name and arguments provided.
The isCallToSuper and fromInsideClass help the Groovy runtime perform optimisations on the call to go directly to the super class if necessary
- Specified by:
setAttribute
in interfaceMetaClass
- Overrides:
setAttribute
in classMetaClassImpl
- Parameters:
sender
- The java.lang.Class instance that is mutating the propertyobject
- The Object which the property is being set onattribute
- The name of the attribute,newValue
- The new value of the attribute to setuseSuper
- Whether the call is to a super class propertyfromInsideClass
- Whether the call was invoked from the inside or the outside of the class
-
invokeStaticMethod
public java.lang.Object invokeStaticMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object[] arguments)Description copied from interface:MetaObjectProtocol
Invokes a static method on the given Object with the given name and arguments.The Object can either be an instance of the class that this MetaObjectProtocol instance applies to or the java.lang.Class instance itself. If a method cannot be invoked a MissingMethodException is will be thrown
- Specified by:
invokeStaticMethod
in interfaceMetaObjectProtocol
- Overrides:
invokeStaticMethod
in classMetaClassImpl
- Parameters:
object
- An instance of the class returned by the getTheClass() method or the class itselfmethodName
- The name of the methodarguments
- The arguments to the method- Returns:
- The return value of the method which is null if the return type is void
- See Also:
MissingMethodException
-
setProperty
public void setProperty(java.lang.Class sender, java.lang.Object object, java.lang.String name, java.lang.Object newValue, boolean useSuper, boolean fromInsideClass)Description copied from class:MetaClassImpl
Retrieves a property on the given receiver for the specified arguments. The sender is the class that is requesting the property from the object. The MetaClass will attempt to establish the method to invoke based on the name and arguments provided.
The useSuper and fromInsideClass help the Groovy runtime perform optimisations on the call to go directly to the super class if necessary
- Specified by:
setProperty
in interfaceMetaClass
- Overrides:
setProperty
in classMetaClassImpl
- Parameters:
sender
- The java.lang.Class instance that is mutating the propertyobject
- The Object which the property is being set onname
- The name of the propertynewValue
- The new value of the property to setuseSuper
- Whether the call is to a super class propertyfromInsideClass
- Whether the call was invoked from the inside or the outside of the class.
-
getMethodWithoutCaching
public MetaMethod getMethodWithoutCaching(int index, java.lang.Class sender, java.lang.String methodName, java.lang.Class[] arguments, boolean isCallToSuper) -
setProperties
public void setProperties(java.lang.Object bean, java.util.Map map)Description copied from class:MetaClassImpl
Sets a number of bean properties from the given Map where the keys are the String names of properties and the values are the values of the properties to set- Overrides:
setProperties
in classMetaClassImpl
-
addMetaBeanProperty
Description copied from class:MetaClassImpl
Adds a new MetaBeanProperty to this MetaClass- Specified by:
addMetaBeanProperty
in interfaceMutableMetaClass
- Overrides:
addMetaBeanProperty
in classMetaClassImpl
- Parameters:
mp
- The MetaBeanProperty
-
addMetaMethod
Description copied from class:MetaClassImpl
adds a MetaMethod to this class. WARNING: this method will not do the neccessary steps for multimethod logic and using this method doesn't mean, that a method added here is replacing another method from a parent class completely. These steps are usually done by initialize, which means if you need these steps, you have to add the method before running initialize the first time.- Specified by:
addMetaMethod
in interfaceMutableMetaClass
- Overrides:
addMetaMethod
in classMetaClassImpl
- Parameters:
method
- the MetaMethod- See Also:
MetaClassImpl.initialize()
-
addNewInstanceMethod
public void addNewInstanceMethod(java.lang.reflect.Method method)Description copied from class:MetaClassImpl
Adds an instance method to this metaclass.- Specified by:
addNewInstanceMethod
in interfaceMutableMetaClass
- Overrides:
addNewInstanceMethod
in classMetaClassImpl
- Parameters:
method
- The method to be added
-
addNewStaticMethod
public void addNewStaticMethod(java.lang.reflect.Method method)Description copied from class:MetaClassImpl
Adds a static method to this metaclass.- Specified by:
addNewStaticMethod
in interfaceMutableMetaClass
- Overrides:
addNewStaticMethod
in classMetaClassImpl
- Parameters:
method
- The method to be added
-
retrieveConstructor
public java.lang.reflect.Constructor retrieveConstructor(java.lang.Class[] arguments)- Overrides:
retrieveConstructor
in classMetaClassImpl
-
createPojoCallSite
public CallSite createPojoCallSite(CallSite site, java.lang.Object receiver, java.lang.Object[] args)Description copied from class:MetaClassImpl
Create a CallSite- Overrides:
createPojoCallSite
in classMetaClassImpl
-
createPogoCallSite
Description copied from class:MetaClassImpl
Create a CallSite- Overrides:
createPogoCallSite
in classMetaClassImpl
-
createPogoCallCurrentSite
public CallSite createPogoCallCurrentSite(CallSite site, java.lang.Class sender, java.lang.Object[] args)Description copied from class:MetaClassImpl
Create a CallSite- Overrides:
createPogoCallCurrentSite
in classMetaClassImpl
-
respondsTo
public java.util.List respondsTo(java.lang.Object obj, java.lang.String name, java.lang.Object[] argTypes)Description copied from interface:MetaObjectProtocol
Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name and arguments types.
Note that this method's return value is based on realised methods and does not take into account objects or classes that implement invokeMethod or methodMissing
This method is "safe" in that it will always return a value and never throw an exception
- Specified by:
respondsTo
in interfaceMetaObjectProtocol
- Overrides:
respondsTo
in classMetaClassImpl
- Parameters:
obj
- The object to inspectname
- The name of the method of interestargTypes
- The argument types to match against- Returns:
- A List of MetaMethods matching the argument types which will be empty if no matching methods exist
- See Also:
MetaObjectProtocol.respondsTo(Object, String, Object[])
-
respondsTo
public java.util.List respondsTo(java.lang.Object obj, java.lang.String name)Description copied from interface:MetaObjectProtocol
Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name regardless of arguments. In other words this method will return for foo() and foo(String).
Note that this method's return value is based on realised methods and does not take into account objects or classes that implement invokeMethod or methodMissing
This method is "safe" in that it will always return a value and never throw an exception
- Specified by:
respondsTo
in interfaceMetaObjectProtocol
- Overrides:
respondsTo
in classMetaClassImpl
- Parameters:
obj
- The object to inspectname
- The name of the method of interest- Returns:
- A List of MetaMethods which will be empty if no methods with the given name exist
- See Also:
MetaObjectProtocol.respondsTo(Object, String)
-
applyPropertyDescriptors
protected void applyPropertyDescriptors(java.beans.PropertyDescriptor[] propertyDescriptors)- Overrides:
applyPropertyDescriptors
in classMetaClassImpl
-