public final class ClosureMetaClass extends MetaClassImpl
The Closure and Class MetaClasses are not replaceable.
This MetaClass is for internal usage only!
MetaClassImpl.Index, MetaClassImpl.MetaConstructor
getPropertyMethod, INVOKE_METHOD_METHOD, invokeMethodMethod, isGroovyObject, isMap, metaMethodIndex, METHOD_MISSING, PROPERTY_MISSING, registry, setPropertyMethod, STATIC_METHOD_MISSING, STATIC_PROPERTY_MISSING, theCachedClass, theClass
Constructor and Description |
---|
ClosureMetaClass(MetaClassRegistry registry,
Class theClass) |
Modifier and Type | Method and Description |
---|---|
void |
addMetaBeanProperty(MetaBeanProperty mp)
Adds a new MetaBeanProperty to this MetaClass
|
void |
addMetaMethod(MetaMethod method)
adds a MetaMethod to this class.
|
void |
addNewInstanceMethod(Method method)
adds a new instance method to this MetaClass.
|
void |
addNewStaticMethod(Method method)
adds a new static method to this MetaClass.
|
protected void |
applyPropertyDescriptors(PropertyDescriptor[] propertyDescriptors) |
CallSite |
createPogoCallCurrentSite(CallSite site,
Class sender,
Object[] args) |
CallSite |
createPogoCallSite(CallSite site,
Object[] args) |
CallSite |
createPojoCallSite(CallSite site,
Object receiver,
Object[] args) |
Object |
getAttribute(Class sender,
Object object,
String attribute,
boolean useSuper,
boolean fromInsideClass)
Looks up the given attribute (field) on the given object
|
List<MetaMethod> |
getMetaMethods()
Retrieves a list of MetaMethods held by this class
|
MetaProperty |
getMetaProperty(String name)
Returns a MetaProperty for the given name or null if it doesn't exist
|
List<MetaMethod> |
getMethods()
Retrieves a list of MetaMethods held by the class
|
MetaMethod |
getMethodWithoutCaching(int index,
Class sender,
String methodName,
Class[] arguments,
boolean isCallToSuper) |
List<MetaProperty> |
getProperties()
Get all the properties defined for this type
|
Object |
getProperty(Class sender,
Object object,
String name,
boolean useSuper,
boolean fromInsideClass)
Retrieves a property on the given receiver for the specified arguments.
|
MetaMethod |
getStaticMetaMethod(String name,
Class[] argTypes) |
MetaMethod |
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 MetaMethod
|
void |
initialize()
complete the initialisation process.
|
Object |
invokeMethod(Class sender,
Object object,
String methodName,
Object[] originalArguments,
boolean isCallToSuper,
boolean fromInsideClass)
Invokes the given method on the object.
|
Object |
invokeStaticMethod(Object object,
String methodName,
Object[] arguments)
Invokes a static method on the given Object with the given name and arguments.
|
protected boolean |
isInitialized() |
MetaMethod |
pickMethod(String name,
Class[] argTypes)
Selects a method by name and argument classes.
|
List |
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.
|
List |
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.
|
Constructor |
retrieveConstructor(Class[] arguments) |
MetaMethod |
retrieveStaticMethod(String methodName,
Class[] arguments) |
void |
setAttribute(Class sender,
Object object,
String attribute,
Object newValue,
boolean useSuper,
boolean fromInsideClass)
Sets the given attribute (field) on the given object
|
void |
setProperties(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 set
|
void |
setProperty(Class sender,
Object object,
String name,
Object newValue,
boolean useSuper,
boolean fromInsideClass)
Sets the property value on an object
|
addMetaMethodToIndex, checkIfGroovyObjectMethod, checkInitalised, chooseMethod, clearInvocationCaches, createConstructorSite, createStaticSite, dropMethodCache, dropStaticMethodCache, findMethodInClassHierarchy, findMixinMethod, findOwnMethod, findPropertyInClassHierarchy, getAdditionalMetaMethods, getAttribute, getAttribute, getClassInfo, getClassNode, getEffectiveGetMetaProperty, getMetaMethod, getMethodWithCaching, getMethodWithoutCaching, getProperty, getRegistry, getSubclassMetaMethods, getSuperClasses, getTheCachedClass, getTheClass, getVersion, hasProperty, incVersion, invokeConstructor, invokeMethod, invokeMethod, invokeMissingMethod, invokeMissingProperty, invokeStaticMissingProperty, isGroovyObject, isModified, onGetPropertyFoundInHierarchy, onInvokeMethodFoundInHierarchy, onMixinMethodFound, onSetPropertyFoundInHierarchy, onSuperMethodFoundInHierarchy, onSuperPropertyFoundInHierarchy, retrieveConstructor, retrieveStaticMethod, selectConstructorAndTransformArguments, setAttribute, setProperty, toString
public ClosureMetaClass(MetaClassRegistry registry, Class theClass)
public MetaProperty getMetaProperty(String name)
MetaObjectProtocol
getMetaProperty
in interface MetaObjectProtocol
getMetaProperty
in class MetaClassImpl
name
- The name of the MetaPropertyMetaObjectProtocol.getMetaProperty(String)
public Object invokeMethod(Class sender, Object object, String methodName, Object[] originalArguments, boolean isCallToSuper, boolean fromInsideClass)
MetaClassImpl
invokeMethod
in interface MetaClass
invokeMethod
in class MetaClassImpl
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 classpublic void initialize()
MetaClass
initialize
in interface MetaClass
initialize
in class MetaClassImpl
public List<MetaMethod> getMethods()
MetaClass
getMethods
in interface MetaClass
getMethods
in interface MetaObjectProtocol
getMethods
in class MetaClassImpl
MetaMethod
public List<MetaMethod> getMetaMethods()
MetaClass
getMetaMethods
in interface MetaClass
getMetaMethods
in class MetaClassImpl
public List<MetaProperty> getProperties()
MetaClassImpl
getProperties
in interface MetaClass
getProperties
in interface MetaObjectProtocol
getProperties
in class MetaClassImpl
MetaProperty
public MetaMethod pickMethod(String name, Class[] argTypes)
MetaClass
pickMethod
in interface MetaClass
pickMethod
in class MetaClassImpl
name
- the name of the method to pickargTypes
- the method argumentspublic MetaMethod retrieveStaticMethod(String methodName, Class[] arguments)
protected boolean isInitialized()
isInitialized
in class MetaClassImpl
public MetaMethod getStaticMetaMethod(String name, Object[] args)
MetaObjectProtocol
getStaticMetaMethod
in interface MetaObjectProtocol
getStaticMetaMethod
in class MetaClassImpl
name
- The name of the MetaMethodargs
- The argument typesMetaObjectProtocol.getStaticMetaMethod(String, Object[])
public MetaMethod getStaticMetaMethod(String name, Class[] argTypes)
public Object getProperty(Class sender, Object object, String name, boolean useSuper, boolean fromInsideClass)
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
getProperty
in interface MetaClass
getProperty
in class MetaClassImpl
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
- ??public Object getAttribute(Class sender, Object object, String attribute, boolean useSuper, boolean fromInsideClass)
MetaClassImpl
getAttribute
in class MetaClassImpl
public void setAttribute(Class sender, Object object, String attribute, Object newValue, boolean useSuper, boolean fromInsideClass)
MetaClassImpl
setAttribute
in interface MetaClass
setAttribute
in class MetaClassImpl
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 classpublic Object invokeStaticMethod(Object object, String methodName, Object[] arguments)
MetaObjectProtocol
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
invokeStaticMethod
in interface MetaObjectProtocol
invokeStaticMethod
in class MetaClassImpl
object
- An instance of the class returned by the getTheClass() method or the class itselfmethodName
- The name of the methodarguments
- The arguments to the methodMissingMethodException
public void setProperty(Class sender, Object object, String name, Object newValue, boolean useSuper, boolean fromInsideClass)
MetaClassImpl
setProperty
in interface MetaClass
setProperty
in class MetaClassImpl
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
- ??public MetaMethod getMethodWithoutCaching(int index, Class sender, String methodName, Class[] arguments, boolean isCallToSuper)
public void setProperties(Object bean, Map map)
MetaClassImpl
setProperties
in class MetaClassImpl
public void addMetaBeanProperty(MetaBeanProperty mp)
MetaClassImpl
addMetaBeanProperty
in interface MutableMetaClass
addMetaBeanProperty
in class MetaClassImpl
mp
- The MetaBeanPropertypublic void addMetaMethod(MetaMethod method)
MetaClassImpl
addMetaMethod
in interface MutableMetaClass
addMetaMethod
in class MetaClassImpl
method
- the MetaMethodMetaClassImpl.initialize()
public void addNewInstanceMethod(Method method)
MutableMetaClass
addNewInstanceMethod
in interface MutableMetaClass
addNewInstanceMethod
in class MetaClassImpl
method
- the method to be addedpublic void addNewStaticMethod(Method method)
MutableMetaClass
addNewStaticMethod
in interface MutableMetaClass
addNewStaticMethod
in class MetaClassImpl
method
- the method to be addedpublic Constructor retrieveConstructor(Class[] arguments)
retrieveConstructor
in class MetaClassImpl
public CallSite createPojoCallSite(CallSite site, Object receiver, Object[] args)
createPojoCallSite
in class MetaClassImpl
public CallSite createPogoCallSite(CallSite site, Object[] args)
createPogoCallSite
in class MetaClassImpl
public CallSite createPogoCallCurrentSite(CallSite site, Class sender, Object[] args)
createPogoCallCurrentSite
in class MetaClassImpl
public List respondsTo(Object obj, String name, Object[] argTypes)
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
respondsTo
in interface MetaObjectProtocol
respondsTo
in class MetaClassImpl
obj
- The object to inspectname
- The name of the method of interestargTypes
- The argument types to match againstMetaObjectProtocol.respondsTo(Object, String, Object[])
public List respondsTo(Object obj, String name)
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
respondsTo
in interface MetaObjectProtocol
respondsTo
in class MetaClassImpl
obj
- The object to inspectname
- The name of the method of interestMetaObjectProtocol.respondsTo(Object, String)
protected void applyPropertyDescriptors(PropertyDescriptor[] propertyDescriptors)
applyPropertyDescriptors
in class MetaClassImpl