Overview | Package | Class | Deprecated | Index | Help
| Groovy Documentation
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | METHOD | DETAIL: FIELD | METHOD

## groovy.lang
[Java] Interface MetaClass

    groovy.lang.MetaClass
      groovy.lang.MetaObjectProtocol

All Superinterfaces:
  MetaObjectProtocol

    public interface MetaClass
    extends MetaObjectProtocol

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

Authors:
  John Wilson
  Graeme Rocher

See Also:
  MetaClassImpl
  MetaObjectProtocol

Method Summary
`java.lang.Object` | `getAttribute(java.lang.Class sender, java.lang.Object receiver, java.lang.String messageName, boolean useSuper)` Retrieves the value of an attribute (field).
`ClassNode` | `getClassNode()` Obtains a reference to the original AST for the MetaClass if it is available at runtime
`java.util.List` | `getMetaMethods()` Retrieves a list of MetaMethods held by this class
`java.util.List` | `getMethods()` Retrieves a list of MetaMethods held by the class
`java.util.List` | `getProperties()` Retrieves a list of MetaProperty instances that the MetaClass has
`java.lang.Object` | `getProperty(java.lang.Class sender, java.lang.Object receiver, java.lang.String property, boolean isCallToSuper, boolean fromInsideClass)`
`void` | `initialize()` complete the initialisation process.
`java.lang.Object` | `invokeMethod(java.lang.Class sender, java.lang.Object receiver, java.lang.String methodName, java.lang.Object[] arguments, boolean isCallToSuper, boolean fromInsideClass)`
`java.lang.Object` | `invokeMissingMethod(java.lang.Object instance, java.lang.String methodName, java.lang.Object[] arguments)`
`java.lang.Object` | `invokeMissingProperty(java.lang.Object instance, java.lang.String propertyName, java.lang.Object optionalValue, boolean isGetter)` Invokes the propertyMissing method otherwise throws a MissingPropertyException
`MetaMethod` | `pickMethod(java.lang.String methodName, java.lang.Class[] arguments)` Selects a method by name and argument classes.
`int` | `selectConstructorAndTransformArguments(int numberOfConstructors, java.lang.Object[] arguments)` Internal method to support Groovy runtime.
`void` | `setAttribute(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).
`void` | `setProperty(java.lang.Class sender, java.lang.Object receiver, java.lang.String property, java.lang.Object value, boolean isCallToSuper, boolean fromInsideClass)`

Methods inherited from interface MetaObjectProtocol
getAttribute, getMetaMethod, getMetaProperty, getMethods, getProperties, getProperty, getStaticMetaMethod, getTheClass, hasProperty, invokeConstructor, invokeMethod, invokeMethod, invokeStaticMethod, respondsTo, respondsTo, setAttribute, setProperty

Method Detail

### getAttribute

    public java.lang.Object getAttribute(java.lang.Class sender, java.lang.Object receiver, java.lang.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` - The class of the object that requested the attribute
    `receiver` - The instance
    `messageName` - The name of the attribute
    `useSuper` - Whether to look-up on the super class or not
  Returns:
    The attribute value

### getClassNode

    public 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

    public java.util.List getMetaMethods()

  Retrieves a list of MetaMethods held by this class
  Returns:
    A list of MetaMethods

### getMethods

    public java.util.List getMethods()

  Retrieves a list of MetaMethods held by the class
  Returns:
    A list of MetaMethods

### getProperties

    public java.util.List getProperties()

  Retrieves a list of MetaProperty instances that the MetaClass has
  Returns:
    A list of MetaProperty instances
  See Also:
    MetaProperty

### getProperty

    public java.lang.Object getProperty(java.lang.Class sender, java.lang.Object receiver, java.lang.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 property
    `receiver` - The Object which the property is being retrieved from
    `property` - The name of the property
    `isCallToSuper` - Whether the call is to a super class property
    `fromInsideClass` - ??
  Returns:
    The properties value

### initialize

    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.

### 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)

  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 method
    `receiver` - The object which the method was invoked on
    `methodName` - The name of the method
    `arguments` - The arguments to the method
    `isCallToSuper` - Whether the method is a call to a super class method
    `fromInsideClass` - 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)

  Attempts to invoke the methodMissing method otherwise throws a MissingMethodException

  Parameters:
    `instance` - The instance to invoke methodMissing on
    `methodName` - The name of the method
    `arguments` - 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)

  Invokes the propertyMissing method otherwise throws a MissingPropertyException
  Parameters:
    `instance` - The instance of the class
    `propertyName` - The name of the property
    `optionalValue` - The value of the property which could be null in the case of a getter
    `isGetter` - Whether the missing property event was the result of a getter or a setter
  Returns:
    The result of the propertyMissing method or throws MissingPropertyException

### pickMethod

    public MetaMethod pickMethod(java.lang.String methodName, java.lang.Class[] 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.
  throws:
    GroovyRuntimeException if there is more than one matching method
  Parameters:
    `methodName` - the name of the method to pick
    `arguments` - the method arguments
  Returns:
    a matching MetaMethod or null

### selectConstructorAndTransformArguments

    public int selectConstructorAndTransformArguments(int numberOfConstructors, java.lang.Object[] arguments)

  Internal method to support Groovy runtime. Not for client usage.
  Parameters:
    `numberOfConstructors` - The number of constructors
    `arguments` - The arguments
  Returns:
    selected index

### setAttribute

    public void setAttribute(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). 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 attribute
    `receiver` - The instance
    `messageName` - The name of the attribute
    `messageValue` - The value of the attribute
    `useSuper` - Whether to look-up on the super class or not
    `fromInsideClass` - 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 property, java.lang.Object value, 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 is mutating the property
    `receiver` - The Object which the property is being set on
    `property` - The name of the property
    `value` - The new value of the property to set
    `isCallToSuper` - Whether the call is to a super class property
    `fromInsideClass` - ??

Groovy Documentation