public class DelegatingMetaClass extends java.lang.Object implements MetaClass, MutableMetaClass, GroovyObject
Constructor and Description |
---|
DelegatingMetaClass(java.lang.Class theClass) |
DelegatingMetaClass(MetaClass delegate) |
Modifier and Type | Method and Description |
---|---|
void |
addMetaBeanProperty(MetaBeanProperty metaBeanProperty)
Adds a new MetaBeanProperty to the MetaClass
|
void |
addMetaMethod(MetaMethod metaMethod)
Adds a new MetaMethod to the MetaClass
|
void |
addNewInstanceMethod(java.lang.reflect.Method method)
adds a new instance method to this MetaClass.
|
void |
addNewStaticMethod(java.lang.reflect.Method method)
adds a new static method to this MetaClass.
|
boolean |
equals(java.lang.Object obj) |
MetaClass |
getAdaptee() |
java.lang.Object |
getAttribute(java.lang.Class sender,
java.lang.Object receiver,
java.lang.String messageName,
boolean useSuper)
Retrieves the value of an attribute (field).
|
java.lang.Object |
getAttribute(java.lang.Object object,
java.lang.String attribute)
Retrieves an attribute of an instance of the class returned by the getTheClass() method.
|
ClassNode |
getClassNode()
Obtains a reference to the original AST for the MetaClass if it is available at runtime
|
MetaClass |
getMetaClass()
Returns the metaclass for a given class.
|
MetaMethod |
getMetaMethod(java.lang.String name,
java.lang.Object[] args)
Retrieves an instance MetaMethod for the given name and argument values, using the types of the
argument values to establish the chosen MetaMethod
|
java.util.List<MetaMethod> |
getMetaMethods()
Retrieves a 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 exist
|
java.util.List<MetaMethod> |
getMethods()
Retrieves a list of MetaMethods held by the class
|
java.util.List<MetaProperty> |
getProperties()
Retrieves a list of MetaProperty instances that the MetaClass has
|
java.lang.Object |
getProperty(java.lang.Class sender,
java.lang.Object receiver,
java.lang.String messageName,
boolean useSuper,
boolean fromInsideClass)
Retrieves a property on the given receiver for the specified arguments.
|
java.lang.Object |
getProperty(java.lang.Object object,
java.lang.String property)
Retrieves a property of an instance of the class returned by the getTheClass() method.
|
java.lang.Object |
getProperty(java.lang.String property)
Retrieves a property value.
|
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 MetaMethod
|
java.lang.Class |
getTheClass()
Retrieves that Java Class that the attached Meta behaviours apply to
|
int |
hashCode() |
MetaProperty |
hasProperty(java.lang.Object obj,
java.lang.String name)
Returns true of the implementing MetaClass has a property of the given name
Note that this method will only return true for realised properties and does not take into
account implementation of getProperty or propertyMissing
|
void |
initialize()
complete the initialisation process.
|
java.lang.Object |
invokeConstructor(java.lang.Object[] arguments)
Invokes a constructor for the given arguments.
|
java.lang.Object |
invokeMethod(java.lang.Class sender,
java.lang.Object receiver,
java.lang.String methodName,
java.lang.Object[] arguments,
boolean isCallToSuper,
boolean fromInsideClass)
Invokes a method on the given receiver for the specified arguments.
|
java.lang.Object |
invokeMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object arguments)
Invokes a method on the given object, with the given name and single argument.
|
java.lang.Object |
invokeMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object[] arguments)
Invokes a method on the given Object with the given name and arguments.
|
java.lang.Object |
invokeMethod(java.lang.String name,
java.lang.Object args)
Invokes the given method.
|
java.lang.Object |
invokeMissingMethod(java.lang.Object instance,
java.lang.String methodName,
java.lang.Object[] arguments)
Attempts to invoke the methodMissing method otherwise throws a MissingMethodException
|
java.lang.Object |
invokeMissingProperty(java.lang.Object instance,
java.lang.String propertyName,
java.lang.Object optionalValue,
boolean isGetter)
Invokes the propertyMissing method otherwise throws a MissingPropertyException
|
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.
|
boolean |
isGroovyObject() |
boolean |
isModified()
Return whether the MetaClass has been modified or not
|
MetaMethod |
pickMethod(java.lang.String methodName,
java.lang.Class[] arguments)
Deprecated.
|
java.util.List<MetaMethod> |
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<MetaMethod> |
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.
|
int |
selectConstructorAndTransformArguments(int numberOfConstructors,
java.lang.Object[] arguments)
Internal method to support Groovy runtime.
|
void |
setAdaptee(MetaClass adaptee) |
void |
setAttribute(java.lang.Class sender,
java.lang.Object receiver,
java.lang.String messageName,
java.lang.Object messageValue,
boolean useSuper,
boolean fromInsideClass)
Sets the value of an attribute (field).
|
void |
setAttribute(java.lang.Object object,
java.lang.String attribute,
java.lang.Object newValue)
Sets an attribute of an instance of the class returned by the getTheClass() method.
|
void |
setMetaClass(MetaClass metaClass)
Allows the MetaClass to be replaced with a derived implementation.
|
void |
setProperty(java.lang.Class sender,
java.lang.Object receiver,
java.lang.String messageName,
java.lang.Object messageValue,
boolean useSuper,
boolean fromInsideClass)
Retrieves a property on the given receiver for the specified arguments.
|
void |
setProperty(java.lang.Object object,
java.lang.String property,
java.lang.Object newValue)
Sets a property of an instance of the class returned by the getTheClass() method.
|
void |
setProperty(java.lang.String property,
java.lang.Object newValue)
Sets the given property to the new value.
|
java.lang.String |
toString() |
protected MetaClass delegate
public DelegatingMetaClass(MetaClass delegate)
public DelegatingMetaClass(java.lang.Class theClass)
public boolean isModified()
MutableMetaClass
isModified
in interface MutableMetaClass
public void addNewInstanceMethod(java.lang.reflect.Method method)
MutableMetaClass
addNewInstanceMethod
in interface MutableMetaClass
method
- the method to be addedpublic void addNewStaticMethod(java.lang.reflect.Method method)
MutableMetaClass
addNewStaticMethod
in interface MutableMetaClass
method
- the method to be addedpublic void addMetaMethod(MetaMethod metaMethod)
MutableMetaClass
addMetaMethod
in interface MutableMetaClass
metaMethod
- The MetaMethod to addpublic void addMetaBeanProperty(MetaBeanProperty metaBeanProperty)
MutableMetaClass
addMetaBeanProperty
in interface MutableMetaClass
metaBeanProperty
- The MetaBeanProperty instancepublic void initialize()
MetaClass
initialize
in interface MetaClass
public java.lang.Object getAttribute(java.lang.Object object, java.lang.String attribute)
MetaObjectProtocol
What this means is largely down to the MetaClass implementation, however the default case would result in attempt to read a field of the instance.
getAttribute
in interface MetaObjectProtocol
object
- An instance of the class returned by the getTheClass() methodattribute
- The name of the attribute to retrieve the value forMetaClassImpl
public ClassNode getClassNode()
MetaClass
getClassNode
in interface MetaClass
public java.util.List<MetaMethod> getMetaMethods()
MetaClass
getMetaMethods
in interface MetaClass
public java.util.List<MetaMethod> getMethods()
MetaClass
getMethods
in interface MetaClass
getMethods
in interface MetaObjectProtocol
MetaMethod
public java.util.List<MetaMethod> respondsTo(java.lang.Object obj, java.lang.String name, java.lang.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
obj
- The object to inspectname
- The name of the method of interestargTypes
- The argument types to match againstpublic java.util.List<MetaMethod> respondsTo(java.lang.Object obj, java.lang.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
obj
- The object to inspectname
- The name of the method of interestpublic MetaProperty hasProperty(java.lang.Object obj, java.lang.String name)
MetaObjectProtocol
Returns true of the implementing MetaClass has a property of the given name
Note that this method will only return true for realised properties and does not take into account implementation of getProperty or propertyMissing
hasProperty
in interface MetaObjectProtocol
obj
- The object to inspectname
- The name of the propertypublic java.util.List<MetaProperty> getProperties()
MetaClass
getProperties
in interface MetaClass
getProperties
in interface MetaObjectProtocol
MetaProperty
public java.lang.Object getProperty(java.lang.Object object, java.lang.String property)
MetaObjectProtocol
What this means is largely down to the MetaClass implementation, however the default case would result in an attempt to invoke a JavaBean getter, or if no such getter exists a public field of the instance.
getProperty
in interface MetaObjectProtocol
object
- An instance of the class returned by the getTheClass() methodproperty
- The name of the property to retrieve the value forMetaClassImpl
public java.lang.Object invokeConstructor(java.lang.Object[] arguments)
MetaObjectProtocol
invokeConstructor
in interface MetaObjectProtocol
arguments
- The arguments to the constructorpublic java.lang.Object invokeMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object arguments)
MetaObjectProtocol
invokeMethod
in interface MetaObjectProtocol
object
- The Object to invoke the method onmethodName
- The name of the methodarguments
- The argument to the methodMetaObjectProtocol.invokeMethod(Object, String, Object[])
public java.lang.Object invokeMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object[] arguments)
MetaObjectProtocol
invokeMethod
in interface MetaObjectProtocol
object
- The instance which the method is invoked onmethodName
- The name of the methodarguments
- The arguments to the methodMissingMethodException
public java.lang.Object invokeStaticMethod(java.lang.Object object, java.lang.String methodName, java.lang.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
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 setAttribute(java.lang.Object object, java.lang.String attribute, java.lang.Object newValue)
MetaObjectProtocol
What this means is largely down to the MetaClass implementation, however the default case would result in an attempt to set a field of the instance.
setAttribute
in interface MetaObjectProtocol
object
- An instance of the class returned by the getTheClass() methodattribute
- The name of the attribute to setnewValue
- The new value of the attributeMetaClassImpl
public void setProperty(java.lang.Object object, java.lang.String property, java.lang.Object newValue)
MetaObjectProtocol
What this means is largely down to the MetaClass implementation, however the default case would result in an attempt to invoke a JavaBean setter, or if no such setter exists to set a public field of the instance.
setProperty
in interface MetaObjectProtocol
object
- An instance of the class returned by the getTheClass() methodproperty
- The name of the property to setnewValue
- The new value of the propertyMetaClassImpl
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public MetaMethod pickMethod(java.lang.String methodName, java.lang.Class[] arguments)
MetaClass
pickMethod
in interface MetaClass
methodName
- the name of the method to pickarguments
- the method argumentspublic java.lang.Object getAttribute(java.lang.Class sender, java.lang.Object receiver, java.lang.String messageName, boolean useSuper)
MetaClass
getAttribute
in interface MetaClass
sender
- The class of the object that requested the attributereceiver
- The instancemessageName
- The name of the attributeuseSuper
- Whether to look-up on the super class or notpublic java.lang.Object getProperty(java.lang.Class sender, java.lang.Object receiver, java.lang.String messageName, 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
sender
- The java.lang.Class instance that requested the propertyreceiver
- The Object which the property is being retrieved frommessageName
- The name of the propertyuseSuper
- Whether the call is to a super class propertyfromInsideClass
- ??public MetaProperty getMetaProperty(java.lang.String name)
MetaObjectProtocol
getMetaProperty
in interface MetaObjectProtocol
name
- The name of the MetaPropertypublic MetaMethod getStaticMetaMethod(java.lang.String name, java.lang.Object[] args)
MetaObjectProtocol
getStaticMetaMethod
in interface MetaObjectProtocol
name
- The name of the MetaMethodargs
- The argument typespublic MetaMethod getStaticMetaMethod(java.lang.String name, java.lang.Class[] argTypes)
public MetaMethod getMetaMethod(java.lang.String name, java.lang.Object[] args)
MetaObjectProtocol
getMetaMethod
in interface MetaObjectProtocol
name
- The name of the MetaMethodargs
- Array containing - 1) the argument values (using which their types are then inferred), or 2) the corresponding argument typespublic java.lang.Class getTheClass()
MetaObjectProtocol
getTheClass
in interface MetaObjectProtocol
public java.lang.Object invokeMethod(java.lang.Class sender, java.lang.Object receiver, java.lang.String methodName, java.lang.Object[] arguments, boolean isCallToSuper, boolean fromInsideClass)
MetaClass
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
sender
- The java.lang.Class instance that invoked the methodreceiver
- The object which the method was invoked onmethodName
- The name of the methodarguments
- 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 java.lang.Object invokeMissingMethod(java.lang.Object instance, java.lang.String methodName, java.lang.Object[] arguments)
MetaClass
Attempts to invoke the methodMissing method otherwise throws a MissingMethodException
invokeMissingMethod
in interface MetaClass
instance
- The instance to invoke methodMissing onmethodName
- The name of the methodarguments
- The arguments to the methodMissingMethodException
public java.lang.Object invokeMissingProperty(java.lang.Object instance, java.lang.String propertyName, java.lang.Object optionalValue, boolean isGetter)
MetaClass
invokeMissingProperty
in interface MetaClass
instance
- The instance of the classpropertyName
- The name of the propertyoptionalValue
- The value of the property which could be null in the case of a getterisGetter
- Whether the missing property event was the result of a getter or a setterpublic boolean isGroovyObject()
public void setAttribute(java.lang.Class sender, java.lang.Object receiver, java.lang.String messageName, java.lang.Object messageValue, boolean useSuper, boolean fromInsideClass)
MetaClass
setAttribute
in interface MetaClass
sender
- The class of the object that requested the attributereceiver
- The instancemessageName
- The name of the attributemessageValue
- 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 void setProperty(java.lang.Class sender, java.lang.Object receiver, java.lang.String messageName, java.lang.Object messageValue, 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
setProperty
in interface MetaClass
sender
- The java.lang.Class instance that is mutating the propertyreceiver
- The Object which the property is being set onmessageName
- The name of the propertymessageValue
- The new value of the property to setuseSuper
- Whether the call is to a super class propertyfromInsideClass
- ??public int selectConstructorAndTransformArguments(int numberOfConstructors, java.lang.Object[] arguments)
MetaClass
selectConstructorAndTransformArguments
in interface MetaClass
numberOfConstructors
- The number of constructorsarguments
- The argumentspublic void setAdaptee(MetaClass adaptee)
public MetaClass getAdaptee()
public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args)
GroovyObject
invokeMethod
in interface GroovyObject
name
- the name of the method to callargs
- the arguments to use for the method callpublic java.lang.Object getProperty(java.lang.String property)
GroovyObject
getProperty
in interface GroovyObject
property
- the name of the property of interestpublic void setProperty(java.lang.String property, java.lang.Object newValue)
GroovyObject
setProperty
in interface GroovyObject
property
- the name of the property of interestnewValue
- the new value for the propertypublic MetaClass getMetaClass()
GroovyObject
getMetaClass
in interface GroovyObject
public void setMetaClass(MetaClass metaClass)
GroovyObject
setMetaClass
in interface GroovyObject
metaClass
- the new metaclass