Class OwnedMetaClass
java.lang.Object
groovy.lang.DelegatingMetaClass
org.codehaus.groovy.runtime.metaclass.OwnedMetaClass
- All Implemented Interfaces:
GroovyObject,MetaClass,MetaObjectProtocol,MutableMetaClass
- Direct Known Subclasses:
MixedInMetaClass
An abstract delegating MetaClass that delegates calls to an owner object's MetaClass.
Subclasses must provide an owner object via the
getOwner() method.
This is used in Groovy for features like mixins that require delegation to an owner's
metaclass for method and property access.
This class is for internal use by the Groovy runtime.
-
Field Summary
Fields inherited from class groovy.lang.DelegatingMetaClass
delegate -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanCompares this OwnedMetaClass with another object using the delegate's equality.getAttribute(Class sender, Object receiver, String messageName, boolean useSuper) Gets an attribute from the owner's MetaClass with caller context.getAttribute(Object object, String attribute) Retrieves the value of an attribute on the owner's MetaClass.Returns the AST ClassNode for the owner's class.getMetaMethod(String name, Class[] argTypes) Gets a metamethod from the owner's MetaClass by name and argument types.getMetaMethod(String name, Object[] args) Gets a metamethod from the owner's MetaClass by name and argument objects.Returns all metamethods from the owner's MetaClass.getMetaProperty(String name) Gets the MetaProperty with the given name from the owner's MetaClass.Returns all methods from the owner's MetaClass.protected abstract ObjectgetOwner()Returns the owner object whose MetaClass should be used for delegated operations.protected abstract MetaClassgetOwnerMetaClass(Object owner) Returns the MetaClass of the owner object.Returns all properties from the owner's MetaClass.getProperty(Class sender, Object receiver, String messageName, boolean useSuper, boolean fromInsideClass) Gets a property from the owner's MetaClass with caller context.getProperty(Object object, String property) Gets a property value from the owner's MetaClass.getStaticMetaMethod(String name, Class[] argTypes) Gets a static metamethod from the owner's MetaClass by name and argument types.getStaticMetaMethod(String name, Object[] args) Gets a static metamethod from the owner's MetaClass by name and argument objects.Returns the class that this MetaClass represents.inthashCode()Returns the hash code of the delegate MetaClass.hasProperty(Object obj, String name) Retrieves the MetaProperty with the given name from the owner's MetaClass.invokeConstructor(Object[] arguments) Invokes a constructor on the owner's MetaClass.invokeMethod(Class sender, Object receiver, String methodName, Object[] arguments, boolean isCallToSuper, boolean fromInsideClass) Invokes a method on the owner's MetaClass with caller context.invokeMethod(Object object, String methodName, Object arguments) Invokes a method on the owner's MetaClass with the specified arguments.invokeMethod(Object object, String methodName, Object[] arguments) Invokes a method on the owner's MetaClass with the specified array of arguments.invokeMissingMethod(Object instance, String methodName, Object[] arguments) Invokes a missing method on the owner's MetaClass.invokeMissingProperty(Object instance, String propertyName, Object optionalValue, boolean isGetter) Invokes a missing property on the owner's MetaClass.invokeStaticMethod(Object object, String methodName, Object[] arguments) Invokes a static method on the owner's MetaClass.booleanChecks if the owner's class is a GroovyObject.respondsTo(Object obj, String name) Returns all metamethods that respond to the given method name.respondsTo(Object obj, String name, Object[] argTypes) Returns all metamethods that respond to the given method name and argument types.intselectConstructorAndTransformArguments(int numberOfConstructors, Object[] arguments) Selects a constructor and transforms arguments for the owner's metaclass.voidsetAttribute(Class sender, Object receiver, String messageName, Object messageValue, boolean useSuper, boolean fromInsideClass) Sets an attribute on the owner's MetaClass with caller context.voidsetAttribute(Object object, String attribute, Object newValue) Sets the value of an attribute on the owner's MetaClass.voidsetProperty(Class sender, Object receiver, String messageName, Object messageValue, boolean useSuper, boolean fromInsideClass) Sets a property on the owner's MetaClass with caller context.voidsetProperty(Object object, String property, Object newValue) Sets a property value on the owner's MetaClass.toString()Returns a string representation of this OwnedMetaClass.Methods inherited from class groovy.lang.DelegatingMetaClass
addMetaBeanProperty, addMetaMethod, addNewInstanceMethod, addNewStaticMethod, getAdaptee, getMetaClass, getProperty, initialize, invokeMethod, isModified, pickMethod, setAdaptee, setMetaClass, setProperty
-
Constructor Details
-
OwnedMetaClass
Constructs a new OwnedMetaClass.- Parameters:
delegate- the MetaClass to delegate to
-
-
Method Details
-
getAttribute
Retrieves the value of an attribute on the owner's MetaClass.- Specified by:
getAttributein interfaceMetaObjectProtocol- Overrides:
getAttributein classDelegatingMetaClass- Parameters:
object- the object (ignored; the owner is used instead)attribute- the attribute name- Returns:
- the attribute value
- See Also:
-
getOwner
Returns the owner object whose MetaClass should be used for delegated operations.- Returns:
- the owner object
-
getClassNode
Returns the AST ClassNode for the owner's class.- Specified by:
getClassNodein interfaceMetaClass- Overrides:
getClassNodein classDelegatingMetaClass- Returns:
- the ClassNode of the owner's metaclass
-
getMetaMethods
Returns all metamethods from the owner's MetaClass.- Specified by:
getMetaMethodsin interfaceMetaClass- Overrides:
getMetaMethodsin classDelegatingMetaClass- Returns:
- a list of all metamethods
-
getMethods
Returns all methods from the owner's MetaClass.- Specified by:
getMethodsin interfaceMetaClass- Specified by:
getMethodsin interfaceMetaObjectProtocol- Overrides:
getMethodsin classDelegatingMetaClass- Returns:
- a list of all methods
- See Also:
-
respondsTo
Returns all metamethods that respond to the given method name and argument types.- Specified by:
respondsToin interfaceMetaObjectProtocol- Overrides:
respondsToin classDelegatingMetaClass- Parameters:
obj- the object (ignored; the owner is used instead)name- the method nameargTypes- the argument types- Returns:
- a list of matching metamethods
-
respondsTo
Returns all metamethods that respond to the given method name.- Specified by:
respondsToin interfaceMetaObjectProtocol- Overrides:
respondsToin classDelegatingMetaClass- Parameters:
obj- the object (ignored; the owner is used instead)name- the method name- Returns:
- a list of matching metamethods
-
hasProperty
Retrieves the MetaProperty with the given name from the owner's MetaClass.- Specified by:
hasPropertyin interfaceMetaObjectProtocol- Overrides:
hasPropertyin classDelegatingMetaClass- Parameters:
obj- the object (ignored; the owner is used instead)name- the property name- Returns:
- the MetaProperty or null if not found
-
getProperties
Returns all properties from the owner's MetaClass.- Specified by:
getPropertiesin interfaceMetaClass- Specified by:
getPropertiesin interfaceMetaObjectProtocol- Overrides:
getPropertiesin classDelegatingMetaClass- Returns:
- a list of all properties
- See Also:
-
getProperty
Gets a property value from the owner's MetaClass.- Specified by:
getPropertyin interfaceMetaObjectProtocol- Overrides:
getPropertyin classDelegatingMetaClass- Parameters:
object- the object (ignored; the owner is used instead)property- the property name- Returns:
- the property value
- See Also:
-
invokeConstructor
Invokes a constructor on the owner's MetaClass.- Specified by:
invokeConstructorin interfaceMetaObjectProtocol- Overrides:
invokeConstructorin classDelegatingMetaClass- Parameters:
arguments- the constructor arguments- Returns:
- the newly constructed instance
-
invokeMethod
Invokes a method on the owner's MetaClass with the specified arguments.- Specified by:
invokeMethodin interfaceMetaObjectProtocol- Overrides:
invokeMethodin classDelegatingMetaClass- Parameters:
object- the object (ignored; the owner is used instead)methodName- the method namearguments- the method arguments (as a single object or varargs)- Returns:
- the method result
- See Also:
-
invokeMethod
Invokes a method on the owner's MetaClass with the specified array of arguments.- Specified by:
invokeMethodin interfaceMetaObjectProtocol- Overrides:
invokeMethodin classDelegatingMetaClass- Parameters:
object- the object (ignored; the owner is used instead)methodName- the method namearguments- the method arguments as an array- Returns:
- the method result
- See Also:
-
getOwnerMetaClass
Returns the MetaClass of the owner object.- Parameters:
owner- the owner object- Returns:
- the owner's MetaClass
-
invokeStaticMethod
Invokes a static method on the owner's MetaClass.- Specified by:
invokeStaticMethodin interfaceMetaObjectProtocol- Overrides:
invokeStaticMethodin classDelegatingMetaClass- Parameters:
object- the class objectmethodName- the method namearguments- the method arguments- Returns:
- the method result
- See Also:
-
setAttribute
Sets the value of an attribute on the owner's MetaClass.- Specified by:
setAttributein interfaceMetaObjectProtocol- Overrides:
setAttributein classDelegatingMetaClass- Parameters:
object- the object (ignored; the owner is used instead)attribute- the attribute namenewValue- the new attribute value- See Also:
-
setProperty
Sets a property value on the owner's MetaClass.- Specified by:
setPropertyin interfaceMetaObjectProtocol- Overrides:
setPropertyin classDelegatingMetaClass- Parameters:
object- the object (ignored; the owner is used instead)property- the property namenewValue- the new property value- See Also:
-
equals
Compares this OwnedMetaClass with another object using the delegate's equality.- Overrides:
equalsin classDelegatingMetaClass- Parameters:
obj- the object to compare with- Returns:
- true if equal to the delegate
-
hashCode
public int hashCode()Returns the hash code of the delegate MetaClass.- Overrides:
hashCodein classDelegatingMetaClass- Returns:
- the hash code
-
toString
Returns a string representation of this OwnedMetaClass.- Overrides:
toStringin classDelegatingMetaClass- Returns:
- a string describing this metaclass and its delegate
-
getAttribute
Gets an attribute from the owner's MetaClass with caller context.- Specified by:
getAttributein interfaceMetaClass- Overrides:
getAttributein classDelegatingMetaClass- Parameters:
sender- the class making the requestreceiver- the receiver object (ignored; the owner is used instead)messageName- the attribute nameuseSuper- whether to use the super method- Returns:
- the attribute value
-
getProperty
public Object getProperty(Class sender, Object receiver, String messageName, boolean useSuper, boolean fromInsideClass) Gets a property from the owner's MetaClass with caller context.- Specified by:
getPropertyin interfaceMetaClass- Overrides:
getPropertyin classDelegatingMetaClass- Parameters:
sender- the class making the requestreceiver- the receiver object (ignored; the owner is used instead)messageName- the property nameuseSuper- whether to use the super methodfromInsideClass- whether this is called from inside the class- Returns:
- the property value
-
getMetaProperty
Gets the MetaProperty with the given name from the owner's MetaClass.- Specified by:
getMetaPropertyin interfaceMetaObjectProtocol- Overrides:
getMetaPropertyin classDelegatingMetaClass- Parameters:
name- the property name- Returns:
- the MetaProperty or null if not found
-
getStaticMetaMethod
Gets a static metamethod from the owner's MetaClass by name and argument objects.- Specified by:
getStaticMetaMethodin interfaceMetaObjectProtocol- Overrides:
getStaticMetaMethodin classDelegatingMetaClass- Parameters:
name- the method nameargs- the argument objects- Returns:
- the MetaMethod or null if not found
-
getStaticMetaMethod
Gets a static metamethod from the owner's MetaClass by name and argument types.- Overrides:
getStaticMetaMethodin classDelegatingMetaClass- Parameters:
name- the method nameargTypes- the argument types- Returns:
- the MetaMethod or null if not found
-
getMetaMethod
Gets a metamethod from the owner's MetaClass by name and argument objects.- Specified by:
getMetaMethodin interfaceMetaObjectProtocol- Overrides:
getMetaMethodin classDelegatingMetaClass- Parameters:
name- the method nameargs- the argument objects- Returns:
- the MetaMethod or null if not found
-
getMetaMethod
Gets a metamethod from the owner's MetaClass by name and argument types.- Parameters:
name- the method nameargTypes- the argument types- Returns:
- the MetaMethod or null if not found
-
getTheClass
Returns the class that this MetaClass represents.- Specified by:
getTheClassin interfaceMetaObjectProtocol- Overrides:
getTheClassin classDelegatingMetaClass- Returns:
- the owner's class
-
invokeMethod
public Object invokeMethod(Class sender, Object receiver, String methodName, Object[] arguments, boolean isCallToSuper, boolean fromInsideClass) Invokes a method on the owner's MetaClass with caller context.- Specified by:
invokeMethodin interfaceMetaClass- Overrides:
invokeMethodin classDelegatingMetaClass- Parameters:
sender- the class making the requestreceiver- the receiver object (ignored; the owner is used instead)methodName- the method namearguments- the method argumentsisCallToSuper- whether this is a super method callfromInsideClass- whether this is called from inside the class- Returns:
- the method result
-
invokeMissingMethod
Invokes a missing method on the owner's MetaClass.- Specified by:
invokeMissingMethodin interfaceMetaClass- Overrides:
invokeMissingMethodin classDelegatingMetaClass- Parameters:
instance- the instance (ignored; the owner is used instead)methodName- the method name that was missingarguments- the method arguments- Returns:
- the method result
- See Also:
-
invokeMissingProperty
public Object invokeMissingProperty(Object instance, String propertyName, Object optionalValue, boolean isGetter) Invokes a missing property on the owner's MetaClass.- Specified by:
invokeMissingPropertyin interfaceMetaClass- Overrides:
invokeMissingPropertyin classDelegatingMetaClass- Parameters:
instance- the instance (ignored; the owner is used instead)propertyName- the property name that was missingoptionalValue- the optional value (for setters)isGetter- whether this is a getter operation- Returns:
- the property value (or null for setters)
-
isGroovyObject
public boolean isGroovyObject()Checks if the owner's class is a GroovyObject.- Overrides:
isGroovyObjectin classDelegatingMetaClass- Returns:
- true if the owner's class implements GroovyObject
-
setAttribute
public void setAttribute(Class sender, Object receiver, String messageName, Object messageValue, boolean useSuper, boolean fromInsideClass) Sets an attribute on the owner's MetaClass with caller context.- Specified by:
setAttributein interfaceMetaClass- Overrides:
setAttributein classDelegatingMetaClass- Parameters:
sender- the class making the requestreceiver- the receiver object (ignored; the owner is used instead)messageName- the attribute namemessageValue- the new attribute valueuseSuper- whether to use the super methodfromInsideClass- whether this is called from inside the class
-
setProperty
public void setProperty(Class sender, Object receiver, String messageName, Object messageValue, boolean useSuper, boolean fromInsideClass) Sets a property on the owner's MetaClass with caller context.- Specified by:
setPropertyin interfaceMetaClass- Overrides:
setPropertyin classDelegatingMetaClass- Parameters:
sender- the class making the requestreceiver- the receiver object (ignored; the owner is used instead)messageName- the property namemessageValue- the new property valueuseSuper- whether to use the super methodfromInsideClass- whether this is called from inside the class
-
selectConstructorAndTransformArguments
Selects a constructor and transforms arguments for the owner's metaclass.- Specified by:
selectConstructorAndTransformArgumentsin interfaceMetaClass- Overrides:
selectConstructorAndTransformArgumentsin classDelegatingMetaClass- Parameters:
numberOfConstructors- the number of constructors availablearguments- the constructor arguments to transform- Returns:
- the selected constructor index
-