public abstract class OwnedMetaClass extends DelegatingMetaClass
delegate
Constructor and Description |
---|
OwnedMetaClass(MetaClass delegate) |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj) |
Object |
getAttribute(Class sender,
Object receiver,
String messageName,
boolean useSuper)
Retrieves the value of an attribute (field).
|
Object |
getAttribute(Object object,
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
|
MetaMethod |
getMetaMethod(String name,
Class[] argTypes) |
MetaMethod |
getMetaMethod(String name,
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
|
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 Methods held by the class
|
protected abstract Object |
getOwner() |
protected abstract MetaClass |
getOwnerMetaClass(Object owner) |
List<MetaProperty> |
getProperties()
Retrieves a list of MetaProperty instances that the MetaClass has
|
Object |
getProperty(Class sender,
Object receiver,
String messageName,
boolean useSuper,
boolean fromInsideClass)
Retrieves a property on the given receiver for the specified arguments.
|
Object |
getProperty(Object object,
String property)
Retrieves a property of an instance of the class returned by the getTheClass() method.
|
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
|
Class |
getTheClass()
Retrieves that Java Class that the attached Meta behaviours apply to
|
int |
hashCode() |
MetaProperty |
hasProperty(Object obj,
String name)
Returns true of the implementing MetaClass has a property of the given name
|
Object |
invokeConstructor(Object[] arguments)
Invokes a constructor for the given arguments.
|
Object |
invokeMethod(Class sender,
Object receiver,
String methodName,
Object[] arguments,
boolean isCallToSuper,
boolean fromInsideClass)
Invokes a method on the given receiver for the specified arguments.
|
Object |
invokeMethod(Object object,
String methodName,
Object arguments)
Invokes a method on the given object, with the given name and single argument.
|
Object |
invokeMethod(Object object,
String methodName,
Object[] arguments)
Invokes a method on the given Object with the given name and arguments.
|
Object |
invokeMissingMethod(Object instance,
String methodName,
Object[] arguments)
Attempts to invoke the methodMissing method otherwise throws a MissingMethodException
|
Object |
invokeMissingProperty(Object instance,
String propertyName,
Object optionalValue,
boolean isGetter)
Invokes the propertyMissing method otherwise throws a MissingPropertyException
|
Object |
invokeStaticMethod(Object object,
String methodName,
Object[] arguments)
Invokes a static method on the given Object with the given name and arguments.
|
boolean |
isGroovyObject() |
List<MetaMethod> |
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<MetaMethod> |
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.
|
int |
selectConstructorAndTransformArguments(int numberOfConstructors,
Object[] arguments)
Internal method to support Groovy runtime.
|
void |
setAttribute(Class sender,
Object receiver,
String messageName,
Object messageValue,
boolean useSuper,
boolean fromInsideClass)
Sets the value of an attribute (field).
|
void |
setAttribute(Object object,
String attribute,
Object newValue)
Sets an attribute of an instance of the class returned by the getTheClass() method.
|
void |
setProperty(Class sender,
Object receiver,
String messageName,
Object messageValue,
boolean useSuper,
boolean fromInsideClass)
Sets a property on the given receiver for the specified arguments.
|
void |
setProperty(Object object,
String property,
Object newValue)
Sets a property of an instance of the class returned by the getTheClass() method.
|
String |
toString() |
addMetaBeanProperty, addMetaMethod, addNewInstanceMethod, addNewStaticMethod, getAdaptee, getMetaClass, getProperty, initialize, invokeMethod, isModified, pickMethod, setAdaptee, setMetaClass, setProperty
public OwnedMetaClass(MetaClass delegate)
public Object getAttribute(Object object, 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
getAttribute
in class DelegatingMetaClass
object
- An instance of the class returned by the getTheClass() methodattribute
- The name of the attribute to retrieve the value forMetaClassImpl
protected abstract Object getOwner()
public ClassNode getClassNode()
MetaClass
getClassNode
in interface MetaClass
getClassNode
in class DelegatingMetaClass
public List<MetaMethod> getMetaMethods()
MetaClass
getMetaMethods
in interface MetaClass
getMetaMethods
in class DelegatingMetaClass
public List<MetaMethod> getMethods()
MetaClass
getMethods
in interface MetaClass
getMethods
in interface MetaObjectProtocol
getMethods
in class DelegatingMetaClass
MetaMethod
public List<MetaMethod> 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 DelegatingMetaClass
obj
- The object to inspectname
- The name of the method of interestargTypes
- The argument types to match againstpublic List<MetaMethod> 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 DelegatingMetaClass
obj
- The object to inspectname
- The name of the method of interestpublic MetaProperty hasProperty(Object obj, 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
hasProperty
in class DelegatingMetaClass
obj
- The object to inspectname
- The name of the propertypublic List<MetaProperty> getProperties()
MetaClass
getProperties
in interface MetaClass
getProperties
in interface MetaObjectProtocol
getProperties
in class DelegatingMetaClass
MetaProperty
public Object getProperty(Object object, 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
getProperty
in class DelegatingMetaClass
object
- An instance of the class returned by the getTheClass() methodproperty
- The name of the property to retrieve the value forMetaClassImpl
public Object invokeConstructor(Object[] arguments)
MetaObjectProtocol
invokeConstructor
in interface MetaObjectProtocol
invokeConstructor
in class DelegatingMetaClass
arguments
- The arguments to the constructorpublic Object invokeMethod(Object object, String methodName, Object arguments)
MetaObjectProtocol
invokeMethod
in interface MetaObjectProtocol
invokeMethod
in class DelegatingMetaClass
object
- The Object to invoke the method onmethodName
- The name of the methodarguments
- The argument to the methodMetaObjectProtocol.invokeMethod(Object, String, Object[])
public Object invokeMethod(Object object, String methodName, Object[] arguments)
MetaObjectProtocol
invokeMethod
in interface MetaObjectProtocol
invokeMethod
in class DelegatingMetaClass
object
- The instance which the method is invoked onmethodName
- The name of the methodarguments
- The arguments to the methodMissingMethodException
public 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 DelegatingMetaClass
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(Object object, String attribute, 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
setAttribute
in class DelegatingMetaClass
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(Object object, String property, 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
setProperty
in class DelegatingMetaClass
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(Object obj)
equals
in class DelegatingMetaClass
public int hashCode()
hashCode
in class DelegatingMetaClass
public String toString()
toString
in class DelegatingMetaClass
public Object getAttribute(Class sender, Object receiver, String messageName, boolean useSuper)
MetaClass
getAttribute
in interface MetaClass
getAttribute
in class DelegatingMetaClass
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 Object getProperty(Class sender, Object receiver, 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
getProperty
in class DelegatingMetaClass
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(String name)
MetaObjectProtocol
getMetaProperty
in interface MetaObjectProtocol
getMetaProperty
in class DelegatingMetaClass
name
- The name of the MetaPropertypublic MetaMethod getStaticMetaMethod(String name, Object[] args)
MetaObjectProtocol
getStaticMetaMethod
in interface MetaObjectProtocol
getStaticMetaMethod
in class DelegatingMetaClass
name
- The name of the MetaMethodargs
- The argument typespublic MetaMethod getStaticMetaMethod(String name, Class[] argTypes)
getStaticMetaMethod
in class DelegatingMetaClass
public MetaMethod getMetaMethod(String name, Object[] args)
MetaObjectProtocol
getMetaMethod
in interface MetaObjectProtocol
getMetaMethod
in class DelegatingMetaClass
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 MetaMethod getMetaMethod(String name, Class[] argTypes)
public Class getTheClass()
MetaObjectProtocol
getTheClass
in interface MetaObjectProtocol
getTheClass
in class DelegatingMetaClass
public Object invokeMethod(Class sender, Object receiver, String methodName, 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
invokeMethod
in class DelegatingMetaClass
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 Object invokeMissingMethod(Object instance, String methodName, Object[] arguments)
MetaClass
Attempts to invoke the methodMissing method otherwise throws a MissingMethodException
invokeMissingMethod
in interface MetaClass
invokeMissingMethod
in class DelegatingMetaClass
instance
- The instance to invoke methodMissing onmethodName
- The name of the methodarguments
- The arguments to the methodMissingMethodException
public Object invokeMissingProperty(Object instance, String propertyName, Object optionalValue, boolean isGetter)
MetaClass
invokeMissingProperty
in interface MetaClass
invokeMissingProperty
in class DelegatingMetaClass
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()
isGroovyObject
in class DelegatingMetaClass
public void setAttribute(Class sender, Object receiver, String messageName, Object messageValue, boolean useSuper, boolean fromInsideClass)
MetaClass
setAttribute
in interface MetaClass
setAttribute
in class DelegatingMetaClass
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(Class sender, Object receiver, String messageName, Object messageValue, boolean useSuper, boolean fromInsideClass)
MetaClass
Sets a property on the given receiver for the specified arguments. The sender is the class that is setting 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
setProperty
in class DelegatingMetaClass
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
- Whether the call was invoked from the inside or the outside of the classpublic int selectConstructorAndTransformArguments(int numberOfConstructors, Object[] arguments)
MetaClass
selectConstructorAndTransformArguments
in interface MetaClass
selectConstructorAndTransformArguments
in class DelegatingMetaClass
numberOfConstructors
- The number of constructorsarguments
- The arguments