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 an instance method to this metaclass.
|
void |
addNewStaticMethod(Method method)
Adds a static method to this metaclass.
|
protected void |
applyPropertyDescriptors(PropertyDescriptor[] propertyDescriptors) |
CallSite |
createPogoCallCurrentSite(CallSite site,
Class sender,
Object[] args)
Create a CallSite
|
CallSite |
createPogoCallSite(CallSite site,
Object[] args)
Create a CallSite
|
CallSite |
createPojoCallSite(CallSite site,
Object receiver,
Object[] args)
Create a CallSite
|
Object |
getAttribute(Class sender,
Object object,
String attribute,
boolean useSuper,
boolean fromInsideClass)
Retrieves the value of an attribute (field).
|
List<MetaMethod> |
getMetaMethods()
Retrieves the 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 the list of Methods 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 a method on the given receiver for the specified arguments.
|
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.
|
static void |
resetCachedMetaClasses() |
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 an attribute on the given receiver for the specified arguments.
|
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)
Retrieves a property on the given receiver for the specified arguments.
|
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 static void resetCachedMetaClasses()
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
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
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 classMetaClass.invokeMethod(Class, Object, String, Object[], boolean, boolean)
public void initialize()
MetaClassImpl
initialize
in interface MetaClass
initialize
in class MetaClassImpl
public List<MetaMethod> getMethods()
MetaClassImpl
getMethods
in interface MetaClass
getMethods
in interface MetaObjectProtocol
getMethods
in class MetaClassImpl
MetaMethod
public List<MetaMethod> getMetaMethods()
MetaClassImpl
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)
MetaClassImpl
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
sender
- The class of the object that requested the attributeobject
- The instance the attribute is to retrived 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.public void setAttribute(Class sender, Object object, String attribute, Object newValue, boolean useSuper, boolean fromInsideClass)
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
setAttribute
in interface MetaClass
setAttribute
in class MetaClassImpl
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 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
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
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
- Whether the call was invoked from the inside or the outside of the class.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)
MetaClassImpl
addNewInstanceMethod
in interface MutableMetaClass
addNewInstanceMethod
in class MetaClassImpl
method
- The method to be addedpublic void addNewStaticMethod(Method method)
MetaClassImpl
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)
MetaClassImpl
createPojoCallSite
in class MetaClassImpl
public CallSite createPogoCallSite(CallSite site, Object[] args)
MetaClassImpl
createPogoCallSite
in class MetaClassImpl
public CallSite createPogoCallCurrentSite(CallSite site, Class sender, Object[] args)
MetaClassImpl
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