Class OwnedMetaClass
- All Implemented Interfaces:
GroovyObject,MetaClass,MetaObjectProtocol,MutableMetaClass
- Direct Known Subclasses:
MixedInMetaClass
public abstract class OwnedMetaClass extends DelegatingMetaClass
-
Field Summary
Fields inherited from class groovy.lang.DelegatingMetaClass
delegate -
Constructor Summary
Constructors Constructor Description OwnedMetaClass(MetaClass delegate) -
Method Summary
Modifier and Type Method Description booleanequals(java.lang.Object obj)java.lang.ObjectgetAttribute(java.lang.Class sender, java.lang.Object receiver, java.lang.String messageName, boolean useSuper)Retrieves the value of an attribute (field).java.lang.ObjectgetAttribute(java.lang.Object object, java.lang.String attribute)Retrieves an attribute of an instance of the class returned by the getTheClass() method.ClassNodegetClassNode()Obtains a reference to the original AST for the MetaClass if it is available at runtimeMetaMethodgetMetaMethod(java.lang.String name, java.lang.Class[] argTypes)MetaMethodgetMetaMethod(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 MetaMethodjava.util.List<MetaMethod>getMetaMethods()Retrieves a list of MetaMethods held by this class.MetaPropertygetMetaProperty(java.lang.String name)Returns a MetaProperty for the given name or null if it doesn't existjava.util.List<MetaMethod>getMethods()Retrieves a list of MetaMethods held by the class.protected abstract java.lang.ObjectgetOwner()protected abstract MetaClassgetOwnerMetaClass(java.lang.Object owner)java.util.List<MetaProperty>getProperties()Retrieves a list of MetaProperty instances that the MetaClass hasjava.lang.ObjectgetProperty(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.ObjectgetProperty(java.lang.Object object, java.lang.String property)Retrieves a property of an instance of the class returned by the getTheClass() method.MetaMethodgetStaticMetaMethod(java.lang.String name, java.lang.Class[] argTypes)MetaMethodgetStaticMetaMethod(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 MetaMethodjava.lang.ClassgetTheClass()Retrieves that Java Class that the attached Meta behaviours apply tointhashCode()MetaPropertyhasProperty(java.lang.Object obj, java.lang.String name)Returns true of the implementing MetaClass has a property of the given namejava.lang.ObjectinvokeConstructor(java.lang.Object[] arguments)Invokes a constructor for the given arguments.java.lang.ObjectinvokeMethod(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.ObjectinvokeMethod(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.ObjectinvokeMethod(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.ObjectinvokeMissingMethod(java.lang.Object instance, java.lang.String methodName, java.lang.Object[] arguments)Attempts to invoke the methodMissing method otherwise throws a MissingMethodExceptionjava.lang.ObjectinvokeMissingProperty(java.lang.Object instance, java.lang.String propertyName, java.lang.Object optionalValue, boolean isGetter)Invokes the propertyMissing method otherwise throws a MissingPropertyExceptionjava.lang.ObjectinvokeStaticMethod(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.booleanisGroovyObject()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.intselectConstructorAndTransformArguments(int numberOfConstructors, java.lang.Object[] arguments)Internal method to support Groovy runtime.voidsetAttribute(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).voidsetAttribute(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.voidsetProperty(java.lang.Class sender, java.lang.Object receiver, java.lang.String messageName, java.lang.Object messageValue, boolean useSuper, boolean fromInsideClass)Sets a property on the given receiver for the specified arguments.voidsetProperty(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.java.lang.StringtoString()Methods inherited from class groovy.lang.DelegatingMetaClass
addMetaBeanProperty, addMetaMethod, addNewInstanceMethod, addNewStaticMethod, getAdaptee, getMetaClass, getProperty, initialize, invokeMethod, isModified, pickMethod, setAdaptee, setMetaClass, setPropertyMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Constructor Details
-
OwnedMetaClass
-
-
Method Details
-
getAttribute
public java.lang.Object getAttribute(java.lang.Object object, java.lang.String attribute)Description copied from interface:MetaObjectProtocolRetrieves an attribute of an instance of the class returned by the getTheClass() method.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.
- Specified by:
getAttributein interfaceMetaObjectProtocol- Overrides:
getAttributein classDelegatingMetaClass- Parameters:
object- An instance of the class returned by the getTheClass() methodattribute- The name of the attribute to retrieve the value for- Returns:
- The attribute value
- See Also:
MetaClassImpl
-
getOwner
protected abstract java.lang.Object getOwner() -
getClassNode
Description copied from interface:MetaClassObtains a reference to the original AST for the MetaClass if it is available at runtime- Specified by:
getClassNodein interfaceMetaClass- Overrides:
getClassNodein classDelegatingMetaClass- Returns:
- The original AST or null if it cannot be returned
-
getMetaMethods
Description copied from interface:MetaClassRetrieves a list of MetaMethods held by this class. This list includes MetaMethods added by groovy.lang.ExpandoMetaClass.- Specified by:
getMetaMethodsin interfaceMetaClass- Overrides:
getMetaMethodsin classDelegatingMetaClass- Returns:
- A list of MetaMethods
-
getMethods
Description copied from interface:MetaClassRetrieves a list of MetaMethods held by the class. This list does not include MetaMethods added by groovy.lang.ExpandoMetaClass.- Specified by:
getMethodsin interfaceMetaClass- Specified by:
getMethodsin interfaceMetaObjectProtocol- Overrides:
getMethodsin classDelegatingMetaClass- Returns:
- A list of MetaMethods
- See Also:
MetaMethod
-
respondsTo
public java.util.List<MetaMethod> respondsTo(java.lang.Object obj, java.lang.String name, java.lang.Object[] argTypes)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 classDelegatingMetaClass- 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
-
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 classDelegatingMetaClass- 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
-
hasProperty
Description copied from interface:MetaObjectProtocolReturns 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
- Specified by:
hasPropertyin interfaceMetaObjectProtocol- Overrides:
hasPropertyin classDelegatingMetaClass- Parameters:
obj- The object to inspectname- The name of the property- Returns:
- The MetaProperty or null if it doesn't exist
-
getProperties
Description copied from interface:MetaClassRetrieves a list of MetaProperty instances that the MetaClass has- Specified by:
getPropertiesin interfaceMetaClass- Specified by:
getPropertiesin interfaceMetaObjectProtocol- Overrides:
getPropertiesin classDelegatingMetaClass- Returns:
- A list of MetaProperty instances
- See Also:
MetaProperty
-
getProperty
public java.lang.Object getProperty(java.lang.Object object, java.lang.String property)Description copied from interface:MetaObjectProtocolRetrieves a property of an instance of the class returned by the getTheClass() method.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.
- Specified by:
getPropertyin interfaceMetaObjectProtocol- Overrides:
getPropertyin classDelegatingMetaClass- Parameters:
object- An instance of the class returned by the getTheClass() methodproperty- The name of the property to retrieve the value for- Returns:
- The properties value
- See Also:
MetaClassImpl
-
invokeConstructor
public java.lang.Object invokeConstructor(java.lang.Object[] arguments)Description copied from interface:MetaObjectProtocolInvokes a constructor for the given arguments. The MetaClass will attempt to pick the best argument which matches the types of the objects passed within the arguments array- Specified by:
invokeConstructorin interfaceMetaObjectProtocol- Overrides:
invokeConstructorin classDelegatingMetaClass- Parameters:
arguments- The arguments to the constructor- Returns:
- An instance of the java.lang.Class that this MetaObjectProtocol object applies to
-
invokeMethod
public java.lang.Object invokeMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object arguments)Description copied from interface:MetaObjectProtocolInvokes a method on the given object, with the given name and single argument.- Specified by:
invokeMethodin interfaceMetaObjectProtocol- Overrides:
invokeMethodin classDelegatingMetaClass- Parameters:
object- The Object to invoke the method onmethodName- The name of the methodarguments- The argument to the method- Returns:
- The return value of the method which is null if the return type is void
- See Also:
MetaObjectProtocol.invokeMethod(Object, String, Object[])
-
invokeMethod
public java.lang.Object invokeMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object[] arguments)Description copied from interface:MetaObjectProtocolInvokes a method on the given Object with the given name and arguments. The MetaClass will attempt to pick the best method for the given name and arguments. If a method cannot be invoked a MissingMethodException will be thrown.- Specified by:
invokeMethodin interfaceMetaObjectProtocol- Overrides:
invokeMethodin classDelegatingMetaClass- Parameters:
object- The instance which the method is invoked onmethodName- 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:
MissingMethodException
-
getOwnerMetaClass
-
invokeStaticMethod
public java.lang.Object invokeStaticMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object[] arguments)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 classDelegatingMetaClass- 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:
MissingMethodException
-
setAttribute
public void setAttribute(java.lang.Object object, java.lang.String attribute, java.lang.Object newValue)Description copied from interface:MetaObjectProtocolSets an attribute of an instance of the class returned by the getTheClass() method.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.
- Specified by:
setAttributein interfaceMetaObjectProtocol- Overrides:
setAttributein classDelegatingMetaClass- Parameters:
object- An instance of the class returned by the getTheClass() methodattribute- The name of the attribute to setnewValue- The new value of the attribute- See Also:
MetaClassImpl
-
setProperty
public void setProperty(java.lang.Object object, java.lang.String property, java.lang.Object newValue)Description copied from interface:MetaObjectProtocolSets a property of an instance of the class returned by the getTheClass() method.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.
- Specified by:
setPropertyin interfaceMetaObjectProtocol- Overrides:
setPropertyin classDelegatingMetaClass- Parameters:
object- An instance of the class returned by the getTheClass() methodproperty- The name of the property to setnewValue- The new value of the property- See Also:
MetaClassImpl
-
equals
public boolean equals(java.lang.Object obj)- Overrides:
equalsin classDelegatingMetaClass
-
hashCode
public int hashCode()- Overrides:
hashCodein classDelegatingMetaClass
-
toString
public java.lang.String toString()- Overrides:
toStringin classDelegatingMetaClass
-
getAttribute
public java.lang.Object getAttribute(java.lang.Class sender, java.lang.Object receiver, java.lang.String messageName, boolean useSuper)Description copied from interface:MetaClassRetrieves the value of an attribute (field). This method is to support the Groovy runtime and not for general client API usage.- Specified by:
getAttributein interfaceMetaClass- Overrides:
getAttributein classDelegatingMetaClass- Parameters:
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 not- Returns:
- The attribute value
-
getProperty
public java.lang.Object getProperty(java.lang.Class sender, java.lang.Object receiver, java.lang.String messageName, 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 classDelegatingMetaClass- Parameters:
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- ??- Returns:
- The properties value
-
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 classDelegatingMetaClass- Parameters:
name- The name of the MetaProperty- Returns:
- A MetaProperty or null
-
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 classDelegatingMetaClass- Parameters:
name- The name of the MetaMethodargs- The argument types- Returns:
- A MetaMethod or null if it doesn't exist
-
getStaticMetaMethod
- Overrides:
getStaticMetaMethodin classDelegatingMetaClass
-
getMetaMethod
Description copied from interface:MetaObjectProtocolRetrieves an instance MetaMethod for the given name and argument values, using the types of the argument values to establish the chosen MetaMethod- Specified by:
getMetaMethodin interfaceMetaObjectProtocol- Overrides:
getMetaMethodin classDelegatingMetaClass- Parameters:
name- The name of the MetaMethodargs- Array containing - 1) the argument values (using which their types are then inferred), or 2) the corresponding argument types- Returns:
- A MetaMethod or null if it doesn't exist
-
getMetaMethod
-
getTheClass
public java.lang.Class getTheClass()Description copied from interface:MetaObjectProtocolRetrieves that Java Class that the attached Meta behaviours apply to- Specified by:
getTheClassin interfaceMetaObjectProtocol- Overrides:
getTheClassin classDelegatingMetaClass- Returns:
- The java.lang.Class instance
-
invokeMethod
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)Description copied from interface:MetaClassInvokes 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
- Specified by:
invokeMethodin interfaceMetaClass- Overrides:
invokeMethodin classDelegatingMetaClass- Parameters:
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 class- Returns:
- The return value of the method
-
invokeMissingMethod
public java.lang.Object invokeMissingMethod(java.lang.Object instance, java.lang.String methodName, java.lang.Object[] arguments)Description copied from interface:MetaClassAttempts to invoke the methodMissing method otherwise throws a MissingMethodException
- Specified by:
invokeMissingMethodin interfaceMetaClass- Overrides:
invokeMissingMethodin classDelegatingMetaClass- Parameters:
instance- The instance to invoke methodMissing onmethodName- The name of the methodarguments- The arguments to the method- Returns:
- The results of methodMissing or throws MissingMethodException
- See Also:
MissingMethodException
-
invokeMissingProperty
public java.lang.Object invokeMissingProperty(java.lang.Object instance, java.lang.String propertyName, java.lang.Object optionalValue, boolean isGetter)Description copied from interface:MetaClassInvokes the propertyMissing method otherwise throws a MissingPropertyException- Specified by:
invokeMissingPropertyin interfaceMetaClass- Overrides:
invokeMissingPropertyin classDelegatingMetaClass- Parameters:
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 setter- Returns:
- The result of the propertyMissing method or throws MissingPropertyException
-
isGroovyObject
public boolean isGroovyObject()- Overrides:
isGroovyObjectin classDelegatingMetaClass
-
setAttribute
public void setAttribute(java.lang.Class sender, java.lang.Object receiver, java.lang.String messageName, java.lang.Object messageValue, boolean useSuper, boolean fromInsideClass)Description copied from interface:MetaClassSets the value of an attribute (field). This method is to support the Groovy runtime and not for general client API usage.- Specified by:
setAttributein interfaceMetaClass- Overrides:
setAttributein classDelegatingMetaClass- Parameters:
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 class
-
setProperty
public void setProperty(java.lang.Class sender, java.lang.Object receiver, java.lang.String messageName, java.lang.Object messageValue, boolean useSuper, boolean fromInsideClass)Description copied from interface:MetaClassSets 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
- Specified by:
setPropertyin interfaceMetaClass- Overrides:
setPropertyin classDelegatingMetaClass- Parameters:
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 class
-
selectConstructorAndTransformArguments
public int selectConstructorAndTransformArguments(int numberOfConstructors, java.lang.Object[] arguments)Description copied from interface:MetaClassInternal method to support Groovy runtime. Not for client usage.- Specified by:
selectConstructorAndTransformArgumentsin interfaceMetaClass- Overrides:
selectConstructorAndTransformArgumentsin classDelegatingMetaClass- Parameters:
numberOfConstructors- The number of constructorsarguments- The arguments- Returns:
- selected index
-