Groovy 1.8.4

groovy.lang
[Java] Class MetaClassImpl

java.lang.Object
  groovy.lang.MetaClassImpl
All Implemented Interfaces:
MetaClass, MutableMetaClass

public class MetaClassImpl
extends Object

Allows methods to be dynamically added to existing classes at runtime

Authors:
James Strachan
Guillaume Laforge
Jochen Theodorou
Graeme Rocher
Alex Tkachman
Roshan Dawrani
Version:
\$Revision\$
See Also:
MetaClass


Nested Class Summary
static class MetaClassImpl.Index

 
Field Summary
protected static String INVOKE_METHOD_METHOD

protected static String METHOD_MISSING

protected static String PROPERTY_MISSING

protected static String STATIC_METHOD_MISSING

protected static String STATIC_PROPERTY_MISSING

protected MetaMethod getPropertyMethod

protected MetaMethod invokeMethodMethod

protected boolean isGroovyObject

protected boolean isMap

protected MetaMethodIndex metaMethodIndex

protected MetaClassRegistry registry

protected MetaMethod setPropertyMethod

protected CachedClass theCachedClass

protected Class theClass

 
Constructor Summary
MetaClassImpl(Class theClass, MetaMethod[] add)

MetaClassImpl(Class theClass)

MetaClassImpl(MetaClassRegistry registry, Class theClass, MetaMethod[] add)

MetaClassImpl(MetaClassRegistry registry, Class theClass)

 
Method Summary
void addMetaBeanProperty(MetaBeanProperty mp)

Adds a new MetaBeanProperty to this MetaClass

void addMetaMethod(MetaMethod method)

adds a MetaMethod to this class.

protected void addMetaMethodToIndex(MetaMethod method, Header header)

void addNewInstanceMethod(Method method)

void addNewStaticMethod(Method method)

protected void applyPropertyDescriptors(PropertyDescriptor[] propertyDescriptors)

protected void checkIfGroovyObjectMethod(MetaMethod metaMethod)

Checks if the metaMethod is a method from the GroovyObject interface such as setProperty, getProperty and invokeMethod

protected void checkInitalised()

checks if the initialisation of the class id complete.

protected Object chooseMethod(String methodName, Object methodOrList, Class[] arguments)

Chooses the correct method to use from a list of methods which match by name.

protected void clearInvocationCaches()

remove all method call cache entries.

CallSite createConstructorSite(CallSite site, Object[] args)

CallSite createPogoCallCurrentSite(CallSite site, Class sender, Object[] args)

CallSite createPogoCallSite(CallSite site, Object[] args)

CallSite createPojoCallSite(CallSite site, Object receiver, Object[] args)

CallSite createStaticSite(CallSite site, Object[] args)

protected void dropMethodCache(String name)

protected void dropStaticMethodCache(String name)

protected static MetaMethod findMethodInClassHierarchy(Class instanceKlazz, String methodName, Class[] arguments, MetaClass metaClass)

protected MetaMethod findMixinMethod(String methodName, Class[] arguments)

protected static MetaMethod findOwnMethod(Class instanceKlazz, String methodName, Class[] arguments, MetaClass metaClass, MetaMethod method)

protected MetaBeanProperty findPropertyInClassHierarchy(String propertyName, CachedClass theClass)

MetaMethod[] getAdditionalMetaMethods()

Object getAttribute(Class sender, Object receiver, String messageName, boolean useSuper)

Object getAttribute(Class sender, Object object, String attribute, boolean useSuper, boolean fromInsideClass)

Looks up the given attribute (field) on the given object

Object getAttribute(Object object, String attribute)

ClassInfo getClassInfo()

ClassNode getClassNode()

MetaProperty getEffectiveGetMetaProperty(Class sender, Object object, String name, boolean useSuper)

todo these special cases should be special MetaClasses maybe

MetaMethod getMetaMethod(String name, Object[] argTypes)

@see MetaObjectProtocol#getMetaMethod(String, Object[])

List getMetaMethods()

MetaProperty getMetaProperty(String name)

@see MetaObjectProtocol#getMetaProperty(String)

MetaMethod getMethodWithCaching(Class sender, String methodName, Object[] arguments, boolean isCallToSuper)

MetaMethod getMethodWithoutCaching(Class sender, String methodName, Class[] arguments, boolean isCallToSuper)

List getMethods()

List getProperties()

Get all the properties defined for this type

Object getProperty(Class sender, Object object, String name, boolean useSuper, boolean fromInsideClass)

@return the given property's value on the object

Object getProperty(Object object, String property)

MetaMethod getStaticMetaMethod(String name, Object[] argTypes)

@see MetaObjectProtocol#getStaticMetaMethod(String, Object[])

protected Object getSubclassMetaMethods(String methodName)

protected LinkedList getSuperClasses()

CachedClass getTheCachedClass()

Class getTheClass()

int getVersion()

MetaProperty hasProperty(Object obj, String name)

@see MetaObjectProtocol#hasProperty(Object,String)

void incVersion()

void initialize()

Object invokeConstructor(Object[] arguments)

Object invokeConstructorAt(Class at, Object[] arguments)

Warning, this method will be removed

Object invokeMethod(Object object, String methodName, Object arguments)

Object invokeMethod(Object object, String methodName, Object[] originalArguments)

Invokes the given method on the object.

Object invokeMethod(Class sender, Object object, String methodName, Object[] originalArguments, boolean isCallToSuper, boolean fromInsideClass)

Invokes the given method on the object.

Object invokeMissingMethod(Object instance, String methodName, Object[] arguments)

Object invokeMissingProperty(Object instance, String propertyName, Object optionalValue, boolean isGetter)

Object invokeStaticMethod(Object object, String methodName, Object[] arguments)

protected Object invokeStaticMissingProperty(Object instance, String propertyName, Object optionalValue, boolean isGetter)

Hook to deal with the case of MissingProperty for static properties.

boolean isGroovyObject()

protected boolean isInitialized()

boolean isModified()

protected void onGetPropertyFoundInHierarchy(MetaMethod method)

protected void onInvokeMethodFoundInHierarchy(MetaMethod method)

protected void onMixinMethodFound(MetaMethod method)

protected void onSetPropertyFoundInHierarchy(MetaMethod method)

protected void onSuperMethodFoundInHierarchy(MetaMethod method)

protected void onSuperPropertyFoundInHierarchy(MetaBeanProperty property)

MetaMethod pickMethod(String methodName, Class[] arguments)

List respondsTo(Object obj, String name, Object[] argTypes)

@see MetaObjectProtocol#respondsTo(Object, String, Object[])

List respondsTo(Object obj, String name)

@see MetaObjectProtocol#respondsTo(Object, String)

Constructor retrieveConstructor(Class[] arguments)

protected MetaMethod retrieveMethod(String methodName, Class[] arguments)

@deprecated use pickMethod instead

MetaMethod retrieveStaticMethod(String methodName, Object[] arguments)

int selectConstructorAndTransformArguments(int numberOfConstructors, Object[] arguments)

void setAttribute(Class sender, Object object, String attribute, Object newValue, boolean useSuper, boolean fromInsideClass)

Sets the given attribute (field) on the given object

void setAttribute(Object object, String attribute, Object newValue)

void setProperties(Object bean, Map map)

Sets a number of bean properties from the given Map where the keys are the String names of properties and the values are the values of the properties to set

void setProperty(Class sender, Object object, String name, Object newValue, boolean useSuper, boolean fromInsideClass)

Sets the property value on an object

void setProperty(Object object, String property, Object newValue)

String toString()

todo there is no CompileUnit in scope so class name checking won't work but that mostly affects the bytecode generation rather than viewing the AST

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

INVOKE_METHOD_METHOD

protected static final String INVOKE_METHOD_METHOD


METHOD_MISSING

protected static final String METHOD_MISSING


PROPERTY_MISSING

protected static final String PROPERTY_MISSING


STATIC_METHOD_MISSING

protected static final String STATIC_METHOD_MISSING


STATIC_PROPERTY_MISSING

protected static final String STATIC_PROPERTY_MISSING


getPropertyMethod

protected MetaMethod getPropertyMethod


invokeMethodMethod

protected MetaMethod invokeMethodMethod


isGroovyObject

protected final boolean isGroovyObject


isMap

protected final boolean isMap


metaMethodIndex

protected final MetaMethodIndex metaMethodIndex


registry

protected MetaClassRegistry registry


setPropertyMethod

protected MetaMethod setPropertyMethod


theCachedClass

protected final CachedClass theCachedClass


theClass

protected final Class theClass


 
Constructor Detail

MetaClassImpl

public MetaClassImpl(Class theClass, MetaMethod[] add)


MetaClassImpl

public MetaClassImpl(Class theClass)


MetaClassImpl

public MetaClassImpl(MetaClassRegistry registry, Class theClass, MetaMethod[] add)


MetaClassImpl

public MetaClassImpl(MetaClassRegistry registry, Class theClass)


 
Method Detail

addMetaBeanProperty

public void addMetaBeanProperty(MetaBeanProperty mp)
Adds a new MetaBeanProperty to this MetaClass
Parameters:
mp - The MetaBeanProperty


addMetaMethod

public void addMetaMethod(MetaMethod method)
adds a MetaMethod to this class. WARNING: this method will not do the neccessary steps for multimethod logic and using this method doesn't mean, that a method added here is replacing another method from a parent class completely. These steps are usually done by initialize, which means if you need these steps, you have to add the method before running initialize the first time.
Parameters:
method - the MetaMethod
See Also:
initialize()


addMetaMethodToIndex

protected void addMetaMethodToIndex(MetaMethod method, Header header)


addNewInstanceMethod

public void addNewInstanceMethod(Method method)


addNewStaticMethod

public void addNewStaticMethod(Method method)


applyPropertyDescriptors

protected void applyPropertyDescriptors(PropertyDescriptor[] propertyDescriptors)


checkIfGroovyObjectMethod

protected final void checkIfGroovyObjectMethod(MetaMethod metaMethod)
Checks if the metaMethod is a method from the GroovyObject interface such as setProperty, getProperty and invokeMethod
Parameters:
metaMethod - The metaMethod instance
See Also:
GroovyObject


checkInitalised

protected void checkInitalised()
checks if the initialisation of the class id complete. This method should be called as a form of assert, it is no way to test if there is still initialisation work to be done. Such logic must be implemented in a different way.
throws:
IllegalStateException if the initialisation is incomplete yet


chooseMethod

protected Object chooseMethod(String methodName, Object methodOrList, Class[] arguments)
Chooses the correct method to use from a list of methods which match by name.
Parameters:
methodOrList - the possible methods to choose from
arguments


clearInvocationCaches

protected void clearInvocationCaches()
remove all method call cache entries. This should be done if a method is added during runtime, but not by using a category.


createConstructorSite

public CallSite createConstructorSite(CallSite site, Object[] args)


createPogoCallCurrentSite

public CallSite createPogoCallCurrentSite(CallSite site, Class sender, Object[] args)


createPogoCallSite

public CallSite createPogoCallSite(CallSite site, Object[] args)


createPojoCallSite

public CallSite createPojoCallSite(CallSite site, Object receiver, Object[] args)


createStaticSite

public CallSite createStaticSite(CallSite site, Object[] args)


dropMethodCache

protected void dropMethodCache(String name)


dropStaticMethodCache

protected void dropStaticMethodCache(String name)


findMethodInClassHierarchy

protected static MetaMethod findMethodInClassHierarchy(Class instanceKlazz, String methodName, Class[] arguments, MetaClass metaClass)


findMixinMethod

protected MetaMethod findMixinMethod(String methodName, Class[] arguments)


findOwnMethod

protected static MetaMethod findOwnMethod(Class instanceKlazz, String methodName, Class[] arguments, MetaClass metaClass, MetaMethod method)


findPropertyInClassHierarchy

protected MetaBeanProperty findPropertyInClassHierarchy(String propertyName, CachedClass theClass)


getAdditionalMetaMethods

public MetaMethod[] getAdditionalMetaMethods()


getAttribute

public Object getAttribute(Class sender, Object receiver, String messageName, boolean useSuper)


getAttribute

public Object getAttribute(Class sender, Object object, String attribute, boolean useSuper, boolean fromInsideClass)
Looks up the given attribute (field) on the given object


getAttribute

public Object getAttribute(Object object, String attribute)


getClassInfo

public ClassInfo getClassInfo()


getClassNode

public ClassNode getClassNode()


getEffectiveGetMetaProperty

public MetaProperty getEffectiveGetMetaProperty(Class sender, Object object, String name, boolean useSuper)
todo these special cases should be special MetaClasses maybe


getMetaMethod

public MetaMethod getMetaMethod(String name, Object[] argTypes)
See Also:
MetaObjectProtocol.getMetaMethod


getMetaMethods

public List getMetaMethods()


getMetaProperty

public MetaProperty getMetaProperty(String name)
See Also:
MetaObjectProtocol.getMetaProperty


getMethodWithCaching

public MetaMethod getMethodWithCaching(Class sender, String methodName, Object[] arguments, boolean isCallToSuper)


getMethodWithoutCaching

public MetaMethod getMethodWithoutCaching(Class sender, String methodName, Class[] arguments, boolean isCallToSuper)


getMethods

public List getMethods()


getProperties

public List getProperties()
Get all the properties defined for this type
Returns:
a list of MetaProperty objects


getProperty

public Object getProperty(Class sender, Object object, String name, boolean useSuper, boolean fromInsideClass)
Returns:
the given property's value on the object


getProperty

public Object getProperty(Object object, String property)


getStaticMetaMethod

public MetaMethod getStaticMetaMethod(String name, Object[] argTypes)
See Also:
MetaObjectProtocol.getStaticMetaMethod


getSubclassMetaMethods

protected Object getSubclassMetaMethods(String methodName)


getSuperClasses

protected LinkedList getSuperClasses()


getTheCachedClass

public final CachedClass getTheCachedClass()


getTheClass

public Class getTheClass()


getVersion

public int getVersion()


hasProperty

public MetaProperty hasProperty(Object obj, String name)
See Also:
MetaObjectProtocol.hasProperty


incVersion

public void incVersion()


initialize

public void initialize()


invokeConstructor

public Object invokeConstructor(Object[] arguments)


invokeConstructorAt

public Object invokeConstructorAt(Class at, Object[] arguments)
Warning, this method will be removed
deprecated:
use invokeConstructor instead


invokeMethod

public Object invokeMethod(Object object, String methodName, Object arguments)


invokeMethod

public Object invokeMethod(Object object, String methodName, Object[] originalArguments)
Invokes the given method on the object. TODO: should this be deprecated? If so, we have to propogate to many places.


invokeMethod

public Object invokeMethod(Class sender, Object object, String methodName, Object[] originalArguments, boolean isCallToSuper, boolean fromInsideClass)
Invokes the given method on the object.


invokeMissingMethod

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


invokeMissingProperty

public Object invokeMissingProperty(Object instance, String propertyName, Object optionalValue, boolean isGetter)


invokeStaticMethod

public Object invokeStaticMethod(Object object, String methodName, Object[] arguments)


invokeStaticMissingProperty

protected Object invokeStaticMissingProperty(Object instance, String propertyName, Object optionalValue, boolean isGetter)
Hook to deal with the case of MissingProperty for static properties. The method will look attempt to look up "propertyMissing" handlers and invoke them otherwise thrown a MissingPropertyException
Parameters:
instance - The instance
propertyName - The name of the property
optionalValue - The value in the case of a setter
isGetter - True if its a getter
Returns:
The value in the case of a getter or a MissingPropertyException


isGroovyObject

public boolean isGroovyObject()


isInitialized

protected boolean isInitialized()


isModified

public boolean isModified()


onGetPropertyFoundInHierarchy

protected void onGetPropertyFoundInHierarchy(MetaMethod method)


onInvokeMethodFoundInHierarchy

protected void onInvokeMethodFoundInHierarchy(MetaMethod method)


onMixinMethodFound

protected void onMixinMethodFound(MetaMethod method)


onSetPropertyFoundInHierarchy

protected void onSetPropertyFoundInHierarchy(MetaMethod method)


onSuperMethodFoundInHierarchy

protected void onSuperMethodFoundInHierarchy(MetaMethod method)


onSuperPropertyFoundInHierarchy

protected void onSuperPropertyFoundInHierarchy(MetaBeanProperty property)


pickMethod

public MetaMethod pickMethod(String methodName, Class[] arguments)


respondsTo

public List respondsTo(Object obj, String name, Object[] argTypes)
See Also:
MetaObjectProtocol.respondsTo


respondsTo

public List respondsTo(Object obj, String name)
See Also:
MetaObjectProtocol.respondsTo


retrieveConstructor

public Constructor retrieveConstructor(Class[] arguments)


retrieveMethod

protected MetaMethod retrieveMethod(String methodName, Class[] arguments)
deprecated:
use pickMethod instead


retrieveStaticMethod

public MetaMethod retrieveStaticMethod(String methodName, Object[] arguments)


selectConstructorAndTransformArguments

public int selectConstructorAndTransformArguments(int numberOfConstructors, Object[] arguments)


setAttribute

public void setAttribute(Class sender, Object object, String attribute, Object newValue, boolean useSuper, boolean fromInsideClass)
Sets the given attribute (field) on the given object


setAttribute

public void setAttribute(Object object, String attribute, Object newValue)


setProperties

public void setProperties(Object bean, Map map)
Sets a number of bean properties from the given Map where the keys are the String names of properties and the values are the values of the properties to set


setProperty

public void setProperty(Class sender, Object object, String name, Object newValue, boolean useSuper, boolean fromInsideClass)
Sets the property value on an object


setProperty

public void setProperty(Object object, String property, Object newValue)


toString

public String toString()
todo there is no CompileUnit in scope so class name checking won't work but that mostly affects the bytecode generation rather than viewing the AST


 

Copyright © 2003-2011 The Codehaus. All rights reserved.