Interface MetaClass
- All Superinterfaces:
MetaObjectProtocol
- All Known Subinterfaces:
AdaptingMetaClass
,MutableMetaClass
- All Known Implementing Classes:
ClosureMetaClass
,DelegatingMetaClass
,ExpandoMetaClass
,HandleMetaClass
,MetaClassImpl
,MixedInMetaClass
,MockProxyMetaClass
,OwnedMetaClass
,ProxyMetaClass
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiongetAttribute
(Class sender, Object receiver, String messageName, boolean useSuper) Retrieves the value of an attribute (field).Obtains a reference to the original AST for the MetaClass if it is available at runtimeRetrieves a list of MetaMethods held by this class.Retrieves a list of MetaMethods held by the class.Retrieves a list of MetaProperty instances that the MetaClass hasgetProperty
(Class sender, Object receiver, String property, boolean isCallToSuper, boolean fromInsideClass) Retrieves a property on the given receiver for the specified arguments.void
Complete the initialisation process.invokeMethod
(Class sender, Object receiver, String methodName, Object[] arguments, boolean isCallToSuper, boolean fromInsideClass) Invokes a method on the given receiver for the specified arguments.invokeMissingMethod
(Object instance, String methodName, Object[] arguments) Attempts to invoke the methodMissing method otherwise throws a MissingMethodExceptioninvokeMissingProperty
(Object instance, String propertyName, Object optionalValue, boolean isGetter) Invokes the propertyMissing method otherwise throws a MissingPropertyExceptionpickMethod
(String methodName, Class[] arguments) Selects a method by name and argument classes.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
setProperty
(Class sender, Object receiver, String property, Object value, boolean isCallToSuper, boolean fromInsideClass) Sets a property on the given receiver for the specified arguments.Methods inherited from interface groovy.lang.MetaObjectProtocol
getAttribute, getMetaMethod, getMetaProperty, getProperty, getStaticMetaMethod, getTheClass, hasProperty, invokeConstructor, invokeMethod, invokeMethod, invokeStaticMethod, respondsTo, respondsTo, setAttribute, setProperty
-
Method Details
-
invokeMethod
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. 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
- 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
-
getProperty
Object getProperty(Class sender, Object receiver, String property, boolean isCallToSuper, boolean fromInsideClass) 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
- Parameters:
sender
- The java.lang.Class instance that requested the propertyreceiver
- The Object which the property is being retrieved fromproperty
- The name of the propertyisCallToSuper
- Whether the call is to a super class propertyfromInsideClass
- ??- Returns:
- The properties value
-
setProperty
void setProperty(Class sender, Object receiver, String property, Object value, boolean isCallToSuper, boolean fromInsideClass) 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
- Parameters:
sender
- The java.lang.Class instance that is mutating the propertyreceiver
- The Object which the property is being set onproperty
- The name of the propertyvalue
- The new value of the property to setisCallToSuper
- Whether the call is to a super class propertyfromInsideClass
- Whether the call was invoked from the inside or the outside of the class
-
invokeMissingMethod
Attempts to invoke the methodMissing method otherwise throws a MissingMethodException
- 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:
-
invokeMissingProperty
Object invokeMissingProperty(Object instance, String propertyName, Object optionalValue, boolean isGetter) Invokes the propertyMissing method otherwise throws a MissingPropertyException- 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
-
getAttribute
Retrieves the value of an attribute (field). This method is to support the Groovy runtime and not for general client API usage.- 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
-
setAttribute
void setAttribute(Class sender, Object receiver, String messageName, Object messageValue, boolean useSuper, boolean fromInsideClass) Sets the value of an attribute (field). This method is to support the Groovy runtime and not for general client API usage.- 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
-
initialize
void initialize()Complete the initialisation process. After this method is called no methods should be added to the metaclass. Invocation of methods or access to fields/properties is forbidden unless this method is called. This method should contain any initialisation code, taking a longer time to complete. An example is the creation of the Reflector. It is suggested to synchronize this method. -
getProperties
List<MetaProperty> getProperties()Retrieves a list of MetaProperty instances that the MetaClass has- Specified by:
getProperties
in interfaceMetaObjectProtocol
- Returns:
- A list of MetaProperty instances
- See Also:
-
getMethods
List<MetaMethod> getMethods()Retrieves a list of MetaMethods held by the class. This list does not include MetaMethods added by groovy.lang.ExpandoMetaClass.- Specified by:
getMethods
in interfaceMetaObjectProtocol
- Returns:
- A list of MetaMethods
- See Also:
-
getClassNode
ClassNode getClassNode()Obtains a reference to the original AST for the MetaClass if it is available at runtime- Returns:
- The original AST or null if it cannot be returned
-
getMetaMethods
List<MetaMethod> getMetaMethods()Retrieves a list of MetaMethods held by this class. This list includes MetaMethods added by groovy.lang.ExpandoMetaClass.- Returns:
- A list of MetaMethods
-
selectConstructorAndTransformArguments
Internal method to support Groovy runtime. Not for client usage.- Parameters:
numberOfConstructors
- The number of constructorsarguments
- The arguments- Returns:
- selected index
-
pickMethod
Selects a method by name and argument classes. This method does not search for an exact match, it searches for a compatible method. For this the method selection mechanism is used as provided by the implementation of this MetaClass. pickMethod may or may not be used during the method selection process when invoking a method. There is no warranty for that.- Parameters:
methodName
- the name of the method to pickarguments
- the method arguments- Returns:
- a matching MetaMethod or null
- Throws:
GroovyRuntimeException
- if there is more than one matching method
-