Class ClosureMetaClass
- All Implemented Interfaces:
MetaClass,MetaObjectProtocol,MutableMetaClass
- Since:
- 1.5
- Author:
- Jochen Theodorou
-
Nested Class Summary
Nested classes/interfaces inherited from class groovy.lang.MetaClassImpl
MetaClassImpl.Index -
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a new MetaBeanProperty to this MetaClassvoidaddMetaMethod(MetaMethod method) adds a MetaMethod to this class.voidaddNewInstanceMethod(Method method) adds a new instance method to this MetaClass.voidaddNewStaticMethod(Method method) adds a new static method to this MetaClass.protected voidapplyPropertyDescriptors(PropertyDescriptor[] propertyDescriptors) createPogoCallCurrentSite(CallSite site, Class sender, Object[] args) createPogoCallSite(CallSite site, Object[] args) createPojoCallSite(CallSite site, Object receiver, Object[] args) getAttribute(Class sender, Object object, String attribute, boolean useSuper, boolean fromInsideClass) Looks up the given attribute (field) on the given objectRetrieves a list of MetaMethods held by this classgetMetaProperty(String name) Returns a MetaProperty for the given name or null if it doesn't existRetrieves a list of MetaMethods held by the classgetMethodWithoutCaching(int index, Class sender, String methodName, Class[] arguments, boolean isCallToSuper) Get all the properties defined for this typegetProperty(Class sender, Object object, String name, boolean useSuper, boolean fromInsideClass) Retrieves a property on the given receiver for the specified arguments.getStaticMetaMethod(String name, Class[] argTypes) getStaticMetaMethod(String name, Object[] args) Retrieves a static MetaMethod for the given name and argument values, using the types of the arguments to establish the chosen MetaMethodvoidcomplete the initialisation process.invokeMethod(Class sender, Object object, String methodName, Object[] originalArguments, boolean isCallToSuper, boolean fromInsideClass) Invokes the given method on the object.invokeStaticMethod(Object object, String methodName, Object[] arguments) Invokes a static method on the given Object with the given name and arguments.protected booleanpickMethod(String name, Class[] argTypes) Selects a method by name and argument classes.respondsTo(Object obj, String name) Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name regardless of arguments.respondsTo(Object obj, String name, Object[] argTypes) Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name and arguments types.retrieveConstructor(Class[] arguments) retrieveStaticMethod(String methodName, Class[] arguments) voidsetAttribute(Class sender, Object object, String attribute, Object newValue, boolean useSuper, boolean fromInsideClass) Sets the given attribute (field) on the given objectvoidsetProperties(Object bean, 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 setvoidsetProperty(Class sender, Object object, String name, Object newValue, boolean useSuper, boolean fromInsideClass) Sets the property value on an objectMethods inherited from class groovy.lang.MetaClassImpl
addMetaMethodToIndex, checkIfGroovyObjectMethod, checkInitalised, chooseMethod, clearInvocationCaches, createConstructorSite, createStaticSite, dropMethodCache, dropStaticMethodCache, findMethodInClassHierarchy, findMixinMethod, findOwnMethod, findPropertyInClassHierarchy, getAdditionalMetaMethods, getAttribute, getAttribute, getClassInfo, getClassNode, getEffectiveGetMetaProperty, getMetaMethod, getMethodWithCaching, getMethodWithoutCaching, getProperty, getSubclassMetaMethods, getSuperClasses, getTheCachedClass, getTheClass, getVersion, hasProperty, incVersion, invokeConstructor, invokeConstructorAt, invokeMethod, invokeMethod, invokeMissingMethod, invokeMissingProperty, invokeStaticMissingProperty, isGroovyObject, isModified, onGetPropertyFoundInHierarchy, onInvokeMethodFoundInHierarchy, onMixinMethodFound, onSetPropertyFoundInHierarchy, onSuperMethodFoundInHierarchy, onSuperPropertyFoundInHierarchy, retrieveMethod, retrieveStaticMethod, selectConstructorAndTransformArguments, setAttribute, setProperty, toString
-
Constructor Details
-
ClosureMetaClass
-
-
Method Details
-
getMetaProperty
Description copied from interface:MetaObjectProtocolReturns a MetaProperty for the given name or null if it doesn't exist- Specified by:
getMetaPropertyin interfaceMetaObjectProtocol- Overrides:
getMetaPropertyin classMetaClassImpl- Parameters:
name- The name of the MetaProperty- Returns:
- A MetaProperty or null
- See Also:
-
invokeMethod
public Object invokeMethod(Class sender, Object object, String methodName, Object[] originalArguments, boolean isCallToSuper, boolean fromInsideClass) Description copied from class:MetaClassImplInvokes the given method on the object.- Specified by:
invokeMethodin interfaceMetaClass- Overrides:
invokeMethodin 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
-
initialize
public void initialize()Description copied from interface:MetaClasscomplete 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:
initializein interfaceMetaClass- Overrides:
initializein classMetaClassImpl
-
getMethods
Description copied from interface:MetaClassRetrieves a list of MetaMethods held by the class- Specified by:
getMethodsin interfaceMetaClass- Specified by:
getMethodsin interfaceMetaObjectProtocol- Overrides:
getMethodsin classMetaClassImpl- Returns:
- A list of MetaMethods
- See Also:
-
getMetaMethods
Description copied from interface:MetaClassRetrieves a list of MetaMethods held by this class- Specified by:
getMetaMethodsin interfaceMetaClass- Overrides:
getMetaMethodsin classMetaClassImpl- Returns:
- A list of MetaMethods
-
getProperties
Description copied from class:MetaClassImplGet all the properties defined for this type- Specified by:
getPropertiesin interfaceMetaClass- Specified by:
getPropertiesin interfaceMetaObjectProtocol- Overrides:
getPropertiesin classMetaClassImpl- Returns:
- a list of MetaProperty objects
- See Also:
-
pickMethod
Description copied from interface:MetaClassSelects 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:
pickMethodin interfaceMetaClass- Overrides:
pickMethodin 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:
isInitializedin classMetaClassImpl
-
getStaticMetaMethod
Description copied from interface:MetaObjectProtocolRetrieves a static MetaMethod for the given name and argument values, using the types of the arguments to establish the chosen MetaMethod- Specified by:
getStaticMetaMethodin interfaceMetaObjectProtocol- Overrides:
getStaticMetaMethodin classMetaClassImpl- Parameters:
name- The name of the MetaMethodargs- The argument types- Returns:
- A MetaMethod or null if it doesn't exist
- See Also:
-
getStaticMetaMethod
-
getProperty
public Object getProperty(Class sender, Object object, String name, boolean useSuper, boolean fromInsideClass) Description copied from interface:MetaClassRetrieves 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:
getPropertyin interfaceMetaClass- Overrides:
getPropertyin 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 Object getAttribute(Class sender, Object object, String attribute, boolean useSuper, boolean fromInsideClass) Description copied from class:MetaClassImplLooks up the given attribute (field) on the given object- Overrides:
getAttributein classMetaClassImpl
-
setAttribute
public void setAttribute(Class sender, Object object, String attribute, Object newValue, boolean useSuper, boolean fromInsideClass) Description copied from class:MetaClassImplSets the given attribute (field) on the given object- Specified by:
setAttributein interfaceMetaClass- Overrides:
setAttributein classMetaClassImpl- Parameters:
sender- The class of the object that requested the attributeobject- The instanceattribute- The name of the attributenewValue- The value of the attributeuseSuper- Whether to look-up on the super class or notfromInsideClass- Whether the call happened from the inside or the outside of a class
-
invokeStaticMethod
Description copied from interface:MetaObjectProtocolInvokes 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:
invokeStaticMethodin interfaceMetaObjectProtocol- Overrides:
invokeStaticMethodin 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:
-
setProperty
public void setProperty(Class sender, Object object, String name, Object newValue, boolean useSuper, boolean fromInsideClass) Description copied from class:MetaClassImplSets the property value on an object- Specified by:
setPropertyin interfaceMetaClass- Overrides:
setPropertyin 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- ??
-
getMethodWithoutCaching
public MetaMethod getMethodWithoutCaching(int index, Class sender, String methodName, Class[] arguments, boolean isCallToSuper) -
setProperties
Description copied from class:MetaClassImplSets 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:
setPropertiesin classMetaClassImpl
-
addMetaBeanProperty
Description copied from class:MetaClassImplAdds a new MetaBeanProperty to this MetaClass- Specified by:
addMetaBeanPropertyin interfaceMutableMetaClass- Overrides:
addMetaBeanPropertyin classMetaClassImpl- Parameters:
mp- The MetaBeanProperty
-
addMetaMethod
Description copied from class:MetaClassImpladds 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:
addMetaMethodin interfaceMutableMetaClass- Overrides:
addMetaMethodin classMetaClassImpl- Parameters:
method- the MetaMethod- See Also:
-
addNewInstanceMethod
Description copied from interface:MutableMetaClassadds a new instance method to this MetaClass. Instance methods are able to overwrite the original methods of the class. Calling this method should not be done after initialise was called.- Specified by:
addNewInstanceMethodin interfaceMutableMetaClass- Overrides:
addNewInstanceMethodin classMetaClassImpl- Parameters:
method- the method to be added
-
addNewStaticMethod
Description copied from interface:MutableMetaClassadds a new static method to this MetaClass. This is only possible as long as initialise was not called.- Specified by:
addNewStaticMethodin interfaceMutableMetaClass- Overrides:
addNewStaticMethodin classMetaClassImpl- Parameters:
method- the method to be added
-
retrieveConstructor
- Overrides:
retrieveConstructorin classMetaClassImpl
-
createPojoCallSite
- Overrides:
createPojoCallSitein classMetaClassImpl
-
createPogoCallSite
- Overrides:
createPogoCallSitein classMetaClassImpl
-
createPogoCallCurrentSite
- Overrides:
createPogoCallCurrentSitein classMetaClassImpl
-
respondsTo
Description copied from interface:MetaObjectProtocolReturns 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:
respondsToin interfaceMetaObjectProtocol- Overrides:
respondsToin 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:
-
respondsTo
Description copied from interface:MetaObjectProtocolReturns 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:
respondsToin interfaceMetaObjectProtocol- Overrides:
respondsToin 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:
-
applyPropertyDescriptors
- Overrides:
applyPropertyDescriptorsin classMetaClassImpl
-