Top Description Methods
groovy.lang

public Interface MetaClass

extends MetaObjectProtocol
Known Direct Subinterfaces
groovy.lang.MutableMetaClass, groovy.lang.AdaptingMetaClass
Known Direct Implementers
groovy.lang.MetaClassImpl, groovy.lang.DelegatingMetaClass
Imports
org.codehaus.groovy.ast.ClassNode, java.util.List

A MetaClass within Groovy defines the behaviour of any given Groovy or Java class. The MetaClass interface defines two parts. The client API, which is defined via the extend MetaObjectProtocol interface and the contract with the Groovy runtime system. In general the compiler and Groovy runtime engine interact with methods on this class whilst MetaClass clients interact with the method defined by the MetaObjectProtocol interface
See Also
MetaClassImpl, groovy.lang.MetaObjectProtocol

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

The attribute value
getAttribute
(Class<T>
The class of the object that requested the attribute
sender
,
Object
The instance
receiver
,
String
The name of the attribute
messageName
,
boolean
Whether to look-up on the super class or not
useSuper
)

Retrieves the value of an attribute (field).

public ClassNode

Returns:

The original AST or null if it cannot be returned
getClassNode
()

Obtains a reference to the original AST for the MetaClass if it is available at runtime

public List<MetaMethod>

Returns:

A list of MetaMethods
getMetaMethods
()

Retrieves a list of MetaMethods held by this class.

public List<MetaMethod>

Returns:

A list of MetaMethods
getMethods
()

Redeclares groovy.lang.MetaObjectProtocol.getMethods.

Retrieves a list of MetaMethods held by the class.
public List<MetaProperty>

Returns:

A list of MetaProperty instances
getProperties
()

Redeclares groovy.lang.MetaObjectProtocol.getProperties.

Retrieves a list of MetaProperty instances that the MetaClass has
public Object

Returns:

The properties value
getProperty
(Class<T>
The java.lang.Class instance that requested the property
sender
,
Object
The Object which the property is being retrieved from
receiver
,
String
The name of the property
property
,
boolean
Whether the call is to a super class property
isCallToSuper
,
boolean
??
fromInsideClass
)

Retrieves a property on the given receiver for the specified arguments.

public void
initialize()

Complete the initialisation process.

public Object

Returns:

The return value of the method
invokeMethod
(Class<T>
The java.lang.Class instance that invoked the method
sender
,
Object
The object which the method was invoked on
receiver
,
String
The name of the method
methodName
,
Object[]
The arguments to the method
arguments
,
boolean
Whether the method is a call to a super class method
isCallToSuper
,
boolean
Whether the call was invoked from the inside or the outside of the class
fromInsideClass
)

Invokes a method on the given receiver for the specified arguments.

public Object

Returns:

The results of methodMissing or throws MissingMethodException
invokeMissingMethod
(Object
The instance to invoke methodMissing on
instance
,
String
The name of the method
methodName
,
Object[]
The arguments to the method
arguments
)

Attempts to invoke the methodMissing method otherwise throws a MissingMethodException

public Object

Returns:

The result of the propertyMissing method or throws MissingPropertyException
invokeMissingProperty
(Object
The instance of the class
instance
,
String
The name of the property
propertyName
,
Object
The value of the property which could be null in the case of a getter
optionalValue
,
boolean
Whether the missing property event was the result of a getter or a setter
isGetter
)

Invokes the propertyMissing method otherwise throws a MissingPropertyException

public MetaMethod

Returns:

a matching MetaMethod or null
pickMethod
(String
the name of the method to pick
methodName
,
Class<T>[]
the method arguments
arguments
)

Selects a method by name and argument classes.

public int

Returns:

selected index
selectConstructorAndTransformArguments
(int
The number of constructors
numberOfConstructors
,
Object[]
The arguments
arguments
)

Internal method to support Groovy runtime.

public void
setAttribute(Class<T>
The class of the object that requested the attribute
sender
,
Object
The instance
receiver
,
String
The name of the attribute
messageName
,
Object
The value of the attribute
messageValue
,
boolean
Whether to look-up on the super class or not
useSuper
,
boolean
Whether the call happened from the inside or the outside of a class
fromInsideClass
)

Sets the value of an attribute (field).

public void
setProperty(Class<T>
The java.lang.Class instance that is mutating the property
sender
,
Object
The Object which the property is being set on
receiver
,
String
The name of the property
property
,
Object
The new value of the property to set
value
,
boolean
Whether the call is to a super class property
isCallToSuper
,
boolean
Whether the call was invoked from the inside or the outside of the class
fromInsideClass
)

Sets a property on the given receiver for the specified arguments.

Inherited from groovy.lang.MetaObjectProtocol:
getAttributegetMetaMethodgetMetaPropertygetPropertygetStaticMetaMethodgetTheClasshasPropertyinvokeConstructorinvokeMethodinvokeMethodinvokeStaticMethodrespondsTorespondsTosetAttributesetProperty

Method Detail

getAttributeback to summary
public Object getAttribute(Class<T> sender, Object receiver, String messageName, boolean useSuper)

Retrieves the value of an attribute (field). This method is to support the Groovy runtime and not for general client API usage.

Parameters
sender:Class<T>

The class of the object that requested the attribute

receiver:Object

The instance

messageName:String

The name of the attribute

useSuper:boolean

Whether to look-up on the super class or not

Returns:Object

The attribute value

getClassNodeback to summary
public ClassNode getClassNode()

Obtains a reference to the original AST for the MetaClass if it is available at runtime

Returns:ClassNode

The original AST or null if it cannot be returned

getMetaMethodsback to summary
public List<MetaMethod> getMetaMethods()

Retrieves a list of MetaMethods held by this class. This list includes MetaMethods added by groovy.lang.ExpandoMetaClass.

Returns:List<MetaMethod>

A list of MetaMethods

getMethodsback to summary
public List<MetaMethod> getMethods()

Redeclares groovy.lang.MetaObjectProtocol.getMethods.

Retrieves a list of MetaMethods held by the class. This list does not include MetaMethods added by groovy.lang.ExpandoMetaClass.

Returns:List<MetaMethod>

A list of MetaMethods

getPropertiesback to summary
public List<MetaProperty> getProperties()

Redeclares groovy.lang.MetaObjectProtocol.getProperties.

Retrieves a list of MetaProperty instances that the MetaClass has

Returns:List<MetaProperty>

A list of MetaProperty instances

See Also
MetaProperty
getPropertyback to summary
public Object getProperty(Class<T> 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:Class<T>

The java.lang.Class instance that requested the property

receiver:Object

The Object which the property is being retrieved from

property:String

The name of the property

isCallToSuper:boolean

Whether the call is to a super class property

fromInsideClass:boolean

??

Returns:Object

The properties value

initializeback to summary
public void initialize()

Complete the initialisation process. After this method is called no methods should be added to the meta class. 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.

invokeMethodback to summary
public Object invokeMethod(Class<T> 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:Class<T>

The java.lang.Class instance that invoked the method

receiver:Object

The object which the method was invoked on

methodName:String

The name of the method

arguments:Object[]

The arguments to the method

isCallToSuper:boolean

Whether the method is a call to a super class method

fromInsideClass:boolean

Whether the call was invoked from the inside or the outside of the class

Returns:Object

The return value of the method

invokeMissingMethodback to summary
public Object invokeMissingMethod(Object instance, String methodName, Object[] arguments)

Attempts to invoke the methodMissing method otherwise throws a MissingMethodException

Parameters
instance:Object

The instance to invoke methodMissing on

methodName:String

The name of the method

arguments:Object[]

The arguments to the method

Returns:Object

The results of methodMissing or throws MissingMethodException

See Also
groovy.lang.MissingMethodException
invokeMissingPropertyback to summary
public Object invokeMissingProperty(Object instance, String propertyName, Object optionalValue, boolean isGetter)

Invokes the propertyMissing method otherwise throws a MissingPropertyException

Parameters
instance:Object

The instance of the class

propertyName:String

The name of the property

optionalValue:Object

The value of the property which could be null in the case of a getter

isGetter:boolean

Whether the missing property event was the result of a getter or a setter

Returns:Object

The result of the propertyMissing method or throws MissingPropertyException

pickMethodback to summary
public MetaMethod pickMethod(String methodName, Class<T>[] arguments)

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:String

the name of the method to pick

arguments:Class<T>[]

the method arguments

Returns:MetaMethod

a matching MetaMethod or null

Exceptions
GroovyRuntimeException:
if there is more than one matching method
selectConstructorAndTransformArgumentsback to summary
public int selectConstructorAndTransformArguments(int numberOfConstructors, Object[] arguments)

Internal method to support Groovy runtime. Not for client usage.

Parameters
numberOfConstructors:int

The number of constructors

arguments:Object[]

The arguments

Returns:int

selected index

setAttributeback to summary
public void setAttribute(Class<T> 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:Class<T>

The class of the object that requested the attribute

receiver:Object

The instance

messageName:String

The name of the attribute

messageValue:Object

The value of the attribute

useSuper:boolean

Whether to look-up on the super class or not

fromInsideClass:boolean

Whether the call happened from the inside or the outside of a class

setPropertyback to summary
public void setProperty(Class<T> 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:Class<T>

The java.lang.Class instance that is mutating the property

receiver:Object

The Object which the property is being set on

property:String

The name of the property

value:Object

The new value of the property to set

isCallToSuper:boolean

Whether the call is to a super class property

fromInsideClass:boolean

Whether the call was invoked from the inside or the outside of the class