groovy.lang
Class MetaClassImpl

java.lang.Object
  extended by groovy.lang.MetaClassImpl
All Implemented Interfaces:
MetaClass, MetaObjectProtocol, MutableMetaClass
Direct Known Subclasses:
ClosureMetaClass, ExpandoMetaClass, ProxyMetaClass

public class MetaClassImpl
extends java.lang.Object
implements MetaClass, MutableMetaClass

Allows methods to be dynamically added to existing classes at runtime

Version:
$Revision: 13294 $
Author:
James Strachan, Guillaume Laforge, Jochen Theodorou, Graeme Rocher, Alex Tkachman
See Also:
MetaClass

Nested Class Summary
private static class MetaClassImpl.DummyMetaMethod
           
static class MetaClassImpl.Index
           
(package private)  class MetaClassImpl.MethodIndex
           
private  class MetaClassImpl.MethodIndexAction
           
 
Field Summary
private  java.util.List allMethods
           
private static MetaMethod AMBIGUOUS_LISTENER_METHOD
           
private  MetaProperty arrayLengthProperty
           
private  ClassNode classNode
           
private  MetaClassImpl.Index classPropertyIndex
           
private  MetaClassImpl.Index classPropertyIndexForSuper
           
private static java.lang.String CLOSURE_CALL_METHOD
           
private static java.lang.String CLOSURE_CURRY_METHOD
           
private static java.lang.String CLOSURE_DO_CALL_METHOD
           
private  FastArray constructors
           
private static java.lang.Object[] EMPTY_ARGUMENTS
           
protected static java.lang.Class[] EMPTY_CLASS_ARRAY
           
private  MetaMethod genericGetMethod
           
private  MetaMethod genericSetMethod
           
private static java.lang.Class[] GETTER_MISSING_ARGS
           
private  boolean initialized
           
private  java.util.List interfaceMethods
           
protected  boolean isGroovyObject
           
protected  boolean isMap
           
private  java.util.Map listeners
           
protected static java.util.logging.Logger LOG
           
private  MetaMethodIndex.Header mainClassMethodHeader
           
private  MetaMethodIndex metaMethodIndex
           
private static SingleKeyHashMap.Copier METHOD_INDEX_COPIER
           
protected static java.lang.String METHOD_MISSING
           
private static java.lang.Class[] METHOD_MISSING_ARGS
           
private  MetaMethod methodMissing
           
private static SingleKeyHashMap.Copier NAME_INDEX_COPIER
           
private  java.util.Set newGroovyMethodsSet
           
private static MetaMethod NULL_METHOD
           
protected static java.lang.String PROPERTY_MISSING
           
private  MetaMethod propertyMissingGet
           
private  MetaMethod propertyMissingSet
           
private static java.util.HashMap propNames
           
protected  MetaClassRegistry registry
           
private static java.lang.Class[] SETTER_MISSING_ARGS
           
protected static java.lang.String STATIC_METHOD_MISSING
           
protected static java.lang.String STATIC_PROPERTY_MISSING
           
private  SingleKeyHashMap staticPropertyIndex
           
protected  CachedClass theCachedClass
           
protected  java.lang.Class theClass
           
 
Constructor Summary
MetaClassImpl(java.lang.Class theClass)
           
MetaClassImpl(MetaClassRegistry registry, java.lang.Class theClass)
           
 
Method Summary
private  java.lang.Object addElementToList(java.lang.Object ret, MetaMethod element)
           
private  void addFields(CachedClass klass, SingleKeyHashMap propertyIndex)
           
private  void addInterfaceMethods(java.util.Set interfaces)
           
 void addMetaBeanProperty(MetaBeanProperty mp)
          Adds a new MetaBeanProperty to this MetaClass
 void addMetaMethod(MetaMethod method)
          adds a MetaMethod to this class.
private  void addMetaMethodToIndex(MetaMethod method, MetaMethodIndex.Header header)
           
private  void addMetaMethodToSuperIndex(MetaMethod method, MetaMethodIndex.Header header)
           
 void addNewInstanceMethod(java.lang.reflect.Method method)
          adds a new instance method to this MetaClass.
private  void addNewInstanceMethodToIndex(MetaMethod newMethod, MetaMethodIndex.Header header)
           
 void addNewStaticMethod(java.lang.reflect.Method method)
          adds a new static method to this MetaClass.
private  void addNewStaticMethodToIndex(MetaMethod newMethod, MetaMethodIndex.Header header)
           
private  void addProperties()
           
private  void addToAllMethodsIfPublic(MetaMethod metaMethod)
           
private  void applyPropertyDescriptors(java.beans.PropertyDescriptor[] propertyDescriptors)
           
private  void applyStrayPropertyMethods(java.util.LinkedList superClasses, MetaClassImpl.Index classPropertyIndex, boolean isThis)
           
private  CachedClass calcFirstGroovySuperClass(java.util.Collection superClasses)
           
private  java.lang.Class[] castArgumentsToClassArray(java.lang.Object[] argTypes)
           
private  void checkIfStdMethod(MetaMethod method)
           
protected  void checkInitalised()
          checks if the initialisation of the class id complete.
private  java.lang.Object chooseMethod(java.lang.String methodName, java.lang.Object methodOrList, java.lang.Class[] argClasses, boolean coerce)
          Chooses the correct method to use from a list of methods which match by name.
private  java.lang.Object chooseMostSpecificParams(java.lang.String name, java.util.List matchingMethods, java.lang.Class[] arguments)
           
protected  void clearInvocationCaches()
          remove all method call cache entries.
private  void connectMultimethods(java.util.List superClasses, CachedClass firstGroovyClass)
           
private  void copyClassPropertyIndexForSuper(MetaClassImpl.Index dest)
           
private  void copyNonPrivateFields(SingleKeyHashMap from, SingleKeyHashMap to)
           
private  void createMetaBeanProperty(SingleKeyHashMap propertyIndex, java.lang.String propName, boolean isGetter, MetaMethod propertyMethod)
           
private static int distanceToObject(java.lang.Class c)
           
private static java.lang.Object doConstructorInvoke(java.lang.Class at, CachedConstructor constructor, java.lang.Object[] argumentArray, boolean setAccessible)
           
protected  void dropMethodCache(java.lang.String name)
           
protected  void dropStaticMethodCache(java.lang.String name)
           
private  MetaProperty establishStaticMetaProperty(MetaProperty mp)
           
private  void fillMethodIndex()
           
private  void filterMatchingMethodForCategory(FastArray list, MetaMethod method)
           
private  int findMatchingMethod(CachedMethod[] data, int from, int to, MetaMethod method)
           
private  MetaMethod findMethod(CachedMethod aMethod)
           
private  MetaMethod findPropertyMethod(java.lang.Object methodOrList, boolean isGetter)
           
 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).
 java.lang.Object getAttribute(java.lang.Class sender, java.lang.Object object, java.lang.String attribute, boolean useSuper, boolean fromInsideClass)
          Looks up the given attribute (field) on the given object
 java.lang.Object getAttribute(java.lang.Object object, java.lang.String attribute)
          Retrieves an attribute of an instance of the class returned by the getTheClass() method.
private  MetaMethod getCategoryMethodGetter(java.lang.Class sender, java.lang.String name, boolean useLongVersion)
           
private  MetaMethod getCategoryMethodSetter(java.lang.Class sender, java.lang.String name, boolean useLongVersion)
           
 ClassNode getClassNode()
          Obtains a reference to the original AST for the MetaClass if it is available at runtime
private  java.lang.Boolean getMatchKindForCategory(MetaMethod aMethod, MetaMethod categoryMethod)
          return false: add method null: ignore method true: replace
 MetaMethod getMetaMethod(java.lang.String name, java.lang.Object[] argTypes)
          Retrieves an instance MetaMethod for the given name and argument values, using the types of the argument values to establish the chosen MetaMethod
 java.util.List getMetaMethods()
          Retrieves a list of MetaMethod instances held by this class
private  MetaProperty getMetaProperty(CachedClass clazz, java.lang.String name, boolean useSuper, boolean useStatic)
           
 MetaProperty getMetaProperty(java.lang.String name)
          Returns a MetaProperty for the given name or null if it doesn't exist
 java.util.List getMethods()
          Retrieves a list of MetaMethods held by the class
private  java.lang.Object getMethods(java.lang.Class sender, java.lang.String name, boolean isCallToSuper)
           
 MetaMethod getMethodWithCaching(java.lang.Class sender, java.lang.String methodName, java.lang.Object[] arguments, boolean isCallToSuper)
           
 MetaMethod getMethodWithoutCaching(java.lang.Class sender, java.lang.String methodName, java.lang.Class[] arguments, boolean isCallToSuper)
           
private  MetaMethod getNormalMethodWithCaching(java.lang.Object[] arguments, MetaMethodIndex.Entry e)
           
 java.util.List getProperties()
          Get all the properties defined for this type
 java.lang.Object getProperty(java.lang.Class sender, java.lang.Object object, java.lang.String name, boolean useSuper, boolean fromInsideClass)
          Retrieves a property on the given receiver for the specified arguments.
 java.lang.Object getProperty(java.lang.Object object, java.lang.String property)
          Retrieves a property of an instance of the class returned by the getTheClass() method.
private  java.lang.String getPropName(java.lang.String methodName)
           
 MetaMethod getStaticMetaMethod(java.lang.String name, java.lang.Object[] argTypes)
          Retreives a static MetaMethod for the given name and argument values, using the types of the arguments to establish the chosen MetaMethod
private  java.lang.Object getStaticMethods(java.lang.Class sender, java.lang.String name)
           
private  java.util.LinkedList getSuperClasses()
           
private  MetaMethod getSuperMethodWithCaching(java.lang.Object[] arguments, MetaMethodIndex.Entry e)
           
 java.lang.Class getTheClass()
          Retrieves that Java Class that the attached Meta behaviours apply to
 MetaProperty hasProperty(java.lang.Object obj, java.lang.String name)
          Returns true of the implementing MetaClass has a property of the given name
private  void inheritFields(java.util.LinkedList superClasses)
           
private  void inheritInterfaceNewMetaMethods(java.util.Set interfaces)
           
private  void inheritMethods(java.util.Collection superClasses, CachedClass firstGroovySuper)
           
private  void inheritStaticInterfaceFields(java.util.LinkedList superClasses, java.util.Set interfaces)
           
 void initialize()
          complete the initlialisation process.
private  java.lang.Object invokeConstructor(java.lang.Class at, java.lang.Object[] arguments)
           
 java.lang.Object invokeConstructor(java.lang.Object[] arguments)
          Invokes a constructor for the given arguments.
 java.lang.Object invokeConstructorAt(java.lang.Class at, java.lang.Object[] arguments)
          Deprecated. use invokeConstructor instead
 java.lang.Object invokeMethod(java.lang.Class sender, java.lang.Object object, java.lang.String methodName, java.lang.Object[] originalArguments, boolean isCallToSuper, boolean fromInsideClass)
          Invokes the given method on the object.
 java.lang.Object invokeMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object arguments)
          Invokes a method on the given object, with the given name and single argument.
 java.lang.Object invokeMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object[] originalArguments)
          Invokes the given method on the object.
private  java.lang.Object invokeMethodOnGroovyObject(java.lang.String methodName, java.lang.Object[] originalArguments, java.lang.Object owner)
           
 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
private  java.lang.Object invokeMissingMethod(java.lang.Object instance, java.lang.String methodName, java.lang.Object[] arguments, java.lang.RuntimeException original)
           
 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
private  java.lang.Object invokeStaticClosureProperty(java.lang.Object[] originalArguments, java.lang.Object prop)
           
 java.lang.Object invokeStaticMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object[] arguments)
          Invokes a static method on the given Object with the given name and arguments.
private  java.lang.Object invokeStaticMissingMethod(java.lang.Class sender, java.lang.String methodName, java.lang.Object[] arguments)
           
protected  java.lang.Object invokeStaticMissingProperty(java.lang.Object instance, java.lang.String propertyName, java.lang.Object optionalValue, boolean isGetter)
          Hook to deal with the case of MissingProperty for static properties.
private  boolean isBeanDerivative(java.lang.Class theClass)
           
private  boolean isGenericGetMethod(MetaMethod method)
           
 boolean isGroovyObject()
           
protected  boolean isInitialized()
           
 boolean isModified()
          Return whether the MetaClass has been modified or not
private  MetaClass lookupObjectMetaClass(java.lang.Object object)
           
private  void makeStaticPropertyIndex()
           
 MetaMethod pickMethod(java.lang.String methodName, java.lang.Class[] arguments)
          Selects a method by name and argument classes.
private  MetaMethod pickStaticMethod(java.lang.String methodName, java.lang.Class[] arguments)
           
private  void populateInterfaces(java.util.Set interfaces)
           
private  void populateMethods(java.util.LinkedList superClasses, CachedClass firstGroovySuper)
           
private  void removeMultimethodsOverloadedWithPrivateMethods()
           
private  void replaceWithMOPCalls(CachedMethod[] mopMethods)
           
 java.util.List respondsTo(java.lang.Object obj, java.lang.String name)
          Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name regardless of arguments.
 java.util.List respondsTo(java.lang.Object obj, java.lang.String name, java.lang.Object[] argTypes)
          Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name and arguments types.
 java.lang.reflect.Constructor retrieveConstructor(java.lang.Class[] argClasses)
           
protected  MetaMethod retrieveMethod(java.lang.String methodName, java.lang.Class[] arguments)
          Deprecated. use pickMethod instead
 MetaMethod retrieveStaticMethod(java.lang.String methodName, java.lang.Object[] arguments)
           
private  boolean sameClasses(java.lang.Class[] params, java.lang.Object[] arguments, boolean weakNullCheck)
           
 int selectConstructorAndTransformArguments(int numberOfCosntructors, java.lang.Object[] arguments)
          Internal method to support Groovy runtime.
 void setAttribute(java.lang.Class sender, java.lang.Object object, java.lang.String attribute, java.lang.Object newValue, boolean useSuper, boolean fromInsideClass)
          Sets the given attribute (field) on the given object
 void setAttribute(java.lang.Object object, java.lang.String attribute, java.lang.Object newValue)
          Sets an attribute of an instance of the class returned by the getTheClass() method.
 void setProperties(java.lang.Object bean, java.util.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(java.lang.Class sender, java.lang.Object object, java.lang.String name, java.lang.Object newValue, boolean useSuper, boolean fromInsideClass)
          Sets the property value on an object
 void setProperty(java.lang.Object object, java.lang.String property, java.lang.Object newValue)
          Sets a property of an instance of the class returned by the getTheClass() method.
private  void setupProperties(java.beans.PropertyDescriptor[] propertyDescriptors)
          This will build up the property map (Map of MetaProperty objects, keyed on property name).
 java.lang.String toString()
           
private  void unwrap(java.lang.Object[] arguments)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLOSURE_CALL_METHOD

private static final java.lang.String CLOSURE_CALL_METHOD
See Also:
Constant Field Values

CLOSURE_DO_CALL_METHOD

private static final java.lang.String CLOSURE_DO_CALL_METHOD
See Also:
Constant Field Values

CLOSURE_CURRY_METHOD

private static final java.lang.String CLOSURE_CURRY_METHOD
See Also:
Constant Field Values

STATIC_METHOD_MISSING

protected static final java.lang.String STATIC_METHOD_MISSING
See Also:
Constant Field Values

STATIC_PROPERTY_MISSING

protected static final java.lang.String STATIC_PROPERTY_MISSING
See Also:
Constant Field Values

METHOD_MISSING

protected static final java.lang.String METHOD_MISSING
See Also:
Constant Field Values

PROPERTY_MISSING

protected static final java.lang.String PROPERTY_MISSING
See Also:
Constant Field Values

METHOD_MISSING_ARGS

private static final java.lang.Class[] METHOD_MISSING_ARGS

GETTER_MISSING_ARGS

private static final java.lang.Class[] GETTER_MISSING_ARGS

SETTER_MISSING_ARGS

private static final java.lang.Class[] SETTER_MISSING_ARGS

LOG

protected static final java.util.logging.Logger LOG

theClass

protected final java.lang.Class theClass

theCachedClass

protected final CachedClass theCachedClass

registry

protected MetaClassRegistry registry

isGroovyObject

protected final boolean isGroovyObject

isMap

protected final boolean isMap

classNode

private ClassNode classNode

classPropertyIndex

private final MetaClassImpl.Index classPropertyIndex

classPropertyIndexForSuper

private MetaClassImpl.Index classPropertyIndexForSuper

staticPropertyIndex

private final SingleKeyHashMap staticPropertyIndex

listeners

private final java.util.Map listeners

constructors

private FastArray constructors

allMethods

private final java.util.List allMethods

interfaceMethods

private java.util.List interfaceMethods

initialized

private boolean initialized

arrayLengthProperty

private final MetaProperty arrayLengthProperty

AMBIGUOUS_LISTENER_METHOD

private static final MetaMethod AMBIGUOUS_LISTENER_METHOD

EMPTY_ARGUMENTS

private static final java.lang.Object[] EMPTY_ARGUMENTS

newGroovyMethodsSet

private final java.util.Set newGroovyMethodsSet

genericGetMethod

private MetaMethod genericGetMethod

genericSetMethod

private MetaMethod genericSetMethod

propertyMissingGet

private MetaMethod propertyMissingGet

propertyMissingSet

private MetaMethod propertyMissingSet

NULL_METHOD

private static final MetaMethod NULL_METHOD

methodMissing

private MetaMethod methodMissing

mainClassMethodHeader

private MetaMethodIndex.Header mainClassMethodHeader

metaMethodIndex

private final MetaMethodIndex metaMethodIndex

EMPTY_CLASS_ARRAY

protected static final java.lang.Class[] EMPTY_CLASS_ARRAY

propNames

private static final java.util.HashMap propNames

NAME_INDEX_COPIER

private static final SingleKeyHashMap.Copier NAME_INDEX_COPIER

METHOD_INDEX_COPIER

private static final SingleKeyHashMap.Copier METHOD_INDEX_COPIER
Constructor Detail

MetaClassImpl

public MetaClassImpl(java.lang.Class theClass)

MetaClassImpl

public MetaClassImpl(MetaClassRegistry registry,
                     java.lang.Class theClass)
Method Detail

respondsTo

public java.util.List respondsTo(java.lang.Object obj,
                                 java.lang.String name,
                                 java.lang.Object[] argTypes)
Description copied from interface: MetaObjectProtocol

Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name and arguments types.

Note that this method's return value is based on realised methods and does not take into account objects or classes that implement invokeMethod or methodMissing

This method is "safe" in that it will always return a value and never throw an exception

Specified by:
respondsTo in interface MetaObjectProtocol
Parameters:
obj - The object to inspect
name - The name of the method of interest
argTypes - The argument types to match against
Returns:
A List of MetaMethods matching the argument types which will be empty if no matching methods exist
See Also:
MetaObjectProtocol.respondsTo(Object,String, Object[])

castArgumentsToClassArray

private java.lang.Class[] castArgumentsToClassArray(java.lang.Object[] argTypes)

respondsTo

public java.util.List respondsTo(java.lang.Object obj,
                                 java.lang.String name)
Description copied from interface: MetaObjectProtocol

Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name regardless of arguments. In other words this method will return for foo() and foo(String).

Note that this method's return value is based on realised methods and does not take into account objects or classes that implement invokeMethod or methodMissing

This method is "safe" in that it will always return a value and never throw an exception

Specified by:
respondsTo in interface MetaObjectProtocol
Parameters:
obj - The object to inspect
name - The name of the method of interest
Returns:
A List of MetaMethods which will be empty if no methods with the given name exist
See Also:
MetaObjectProtocol.respondsTo(Object,String, Object[])

hasProperty

public MetaProperty hasProperty(java.lang.Object obj,
                                java.lang.String name)
Description copied from interface: MetaObjectProtocol

Returns true of the implementing MetaClass has a property of the given name

Note that this method will only return true for realised properties and does not take into account implementation of getProperty or propertyMissing

Specified by:
hasProperty in interface MetaObjectProtocol
Parameters:
obj - The object to inspect
name - The name of the property
Returns:
The MetaProperty or null if it doesn't exist
See Also:
MetaObjectProtocol.hasProperty(Object,String)

getMetaProperty

public MetaProperty getMetaProperty(java.lang.String name)
Description copied from interface: MetaObjectProtocol
Returns a MetaProperty for the given name or null if it doesn't exist

Specified by:
getMetaProperty in interface MetaObjectProtocol
Parameters:
name - The name of the MetaProperty
Returns:
A MetaProperty or null
See Also:
MetaObjectProtocol.getMetaProperty(String)

getStaticMetaMethod

public MetaMethod getStaticMetaMethod(java.lang.String name,
                                      java.lang.Object[] argTypes)
Description copied from interface: MetaObjectProtocol
Retreives a static MetaMethod for the given name and argument values, using the types of the arguments to establish the chosen MetaMethod

Specified by:
getStaticMetaMethod in interface MetaObjectProtocol
Parameters:
name - The name of the MetaMethod
argTypes - The argument types
Returns:
A MetaMethod or null if it doesn't exist
See Also:
MetaObjectProtocol.getStaticMetaMethod(String, Object[])

getMetaMethod

public MetaMethod getMetaMethod(java.lang.String name,
                                java.lang.Object[] argTypes)
Description copied from interface: MetaObjectProtocol
Retrieves an instance MetaMethod for the given name and argument values, using the types of the argument values to establish the chosen MetaMethod

Specified by:
getMetaMethod in interface MetaObjectProtocol
Parameters:
name - The name of the MetaMethod
argTypes - The argument types
Returns:
A MetaMethod or null if it doesn't exist
See Also:
MetaObjectProtocol.getMetaMethod(String, Object[])

getTheClass

public java.lang.Class getTheClass()
Description copied from interface: MetaObjectProtocol
Retrieves that Java Class that the attached Meta behaviours apply to

Specified by:
getTheClass in interface MetaObjectProtocol
Returns:
The java.lang.Class instance

isGroovyObject

public boolean isGroovyObject()

fillMethodIndex

private void fillMethodIndex()

populateMethods

private void populateMethods(java.util.LinkedList superClasses,
                             CachedClass firstGroovySuper)

addInterfaceMethods

private void addInterfaceMethods(java.util.Set interfaces)

getSuperClasses

private java.util.LinkedList getSuperClasses()

removeMultimethodsOverloadedWithPrivateMethods

private void removeMultimethodsOverloadedWithPrivateMethods()

replaceWithMOPCalls

private void replaceWithMOPCalls(CachedMethod[] mopMethods)

inheritInterfaceNewMetaMethods

private void inheritInterfaceNewMetaMethods(java.util.Set interfaces)

populateInterfaces

private void populateInterfaces(java.util.Set interfaces)

connectMultimethods

private void connectMultimethods(java.util.List superClasses,
                                 CachedClass firstGroovyClass)

inheritMethods

private void inheritMethods(java.util.Collection superClasses,
                            CachedClass firstGroovySuper)

calcFirstGroovySuperClass

private CachedClass calcFirstGroovySuperClass(java.util.Collection superClasses)

getMethods

private java.lang.Object getMethods(java.lang.Class sender,
                                    java.lang.String name,
                                    boolean isCallToSuper)
Returns:
all the normal instance methods avaiable on this class for the given name

getStaticMethods

private java.lang.Object getStaticMethods(java.lang.Class sender,
                                          java.lang.String name)
Returns:
all the normal static methods avaiable on this class for the given name

isModified

public boolean isModified()
Description copied from interface: MutableMetaClass
Return whether the MetaClass has been modified or not

Specified by:
isModified in interface MutableMetaClass
Returns:
True if it has

addNewInstanceMethod

public void addNewInstanceMethod(java.lang.reflect.Method method)
Description copied from interface: MutableMetaClass
adds a new instance method to this MetaClass. Instance methods are able to overwrite the original methods of the class. Calling this method should not be done after initlise was called.

Specified by:
addNewInstanceMethod in interface MutableMetaClass
Parameters:
method - the method to be added

addNewInstanceMethodToIndex

private void addNewInstanceMethodToIndex(MetaMethod newMethod,
                                         MetaMethodIndex.Header header)

addNewStaticMethod

public void addNewStaticMethod(java.lang.reflect.Method method)
Description copied from interface: MutableMetaClass
adds a new static method to this MetaClass. This is only possible as long as initilise was not called.

Specified by:
addNewStaticMethod in interface MutableMetaClass
Parameters:
method - the method to be added

addNewStaticMethodToIndex

private void addNewStaticMethodToIndex(MetaMethod newMethod,
                                       MetaMethodIndex.Header header)

unwrap

private void unwrap(java.lang.Object[] arguments)

invokeMethod

public java.lang.Object invokeMethod(java.lang.Object object,
                                     java.lang.String methodName,
                                     java.lang.Object arguments)
Description copied from interface: MetaObjectProtocol

Invokes a method on the given object, with the given name and single argument.

Specified by:
invokeMethod in interface MetaObjectProtocol
Parameters:
object - The Object to invoke the method on
methodName - The name of the method
arguments - The argument to the method
Returns:
The return value of the method which is null if the return type is void
See Also:
MetaObjectProtocol.invokeMethod(Object, String, Object[])

invokeMissingMethod

public java.lang.Object invokeMissingMethod(java.lang.Object instance,
                                            java.lang.String methodName,
                                            java.lang.Object[] arguments)
Description copied from interface: MetaClass

Attempts to invoke the methodMissing method otherwise throws a MissingMethodException

Specified by:
invokeMissingMethod in interface MetaClass
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)
Description copied from interface: MetaClass
Invokes the propertyMissing method otherwise throws a MissingPropertyException

Specified by:
invokeMissingProperty in interface MetaClass
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

invokeMissingMethod

private java.lang.Object invokeMissingMethod(java.lang.Object instance,
                                             java.lang.String methodName,
                                             java.lang.Object[] arguments,
                                             java.lang.RuntimeException original)

invokeStaticMissingProperty

protected java.lang.Object invokeStaticMissingProperty(java.lang.Object instance,
                                                       java.lang.String propertyName,
                                                       java.lang.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

invokeMethod

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

Specified by:
invokeMethod in interface MetaObjectProtocol
Parameters:
object - The instance which the method is invoked on
methodName - The name of the method
originalArguments - The arguments to the method
Returns:
The return value of the method which is null if the return type is void
See Also:
MissingMethodException

invokeMethod

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

Specified by:
invokeMethod in interface MetaClass
Parameters:
sender - The java.lang.Class instance that invoked the method
object - The object which the method was invoked on
methodName - The name of the method
originalArguments - 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

lookupObjectMetaClass

private MetaClass lookupObjectMetaClass(java.lang.Object object)

invokeMethodOnGroovyObject

private java.lang.Object invokeMethodOnGroovyObject(java.lang.String methodName,
                                                    java.lang.Object[] originalArguments,
                                                    java.lang.Object owner)

getMethodWithCaching

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

getSuperMethodWithCaching

private MetaMethod getSuperMethodWithCaching(java.lang.Object[] arguments,
                                             MetaMethodIndex.Entry e)

getNormalMethodWithCaching

private MetaMethod getNormalMethodWithCaching(java.lang.Object[] arguments,
                                              MetaMethodIndex.Entry e)

sameClasses

private boolean sameClasses(java.lang.Class[] params,
                            java.lang.Object[] arguments,
                            boolean weakNullCheck)

retrieveConstructor

public java.lang.reflect.Constructor retrieveConstructor(java.lang.Class[] argClasses)

retrieveStaticMethod

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

getMethodWithoutCaching

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

invokeStaticMethod

public java.lang.Object invokeStaticMethod(java.lang.Object object,
                                           java.lang.String methodName,
                                           java.lang.Object[] arguments)
Description copied from interface: MetaObjectProtocol

Invokes a static method on the given Object with the given name and arguments.

The Object can either be an instance of the class that this MetaObjectProtocol instance applies to or the java.lang.Class instance itself. If a method cannot be invoked a MissingMethodException is will be thrown

Specified by:
invokeStaticMethod in interface MetaObjectProtocol
Parameters:
object - An instance of the class returned by the getTheClass() method or the class itself
methodName - The name of the method
arguments - The arguments to the method
Returns:
The return value of the method which is null if the return type is void
See Also:
MissingMethodException

invokeStaticClosureProperty

private java.lang.Object invokeStaticClosureProperty(java.lang.Object[] originalArguments,
                                                     java.lang.Object prop)

invokeStaticMissingMethod

private java.lang.Object invokeStaticMissingMethod(java.lang.Class sender,
                                                   java.lang.String methodName,
                                                   java.lang.Object[] arguments)

pickStaticMethod

private MetaMethod pickStaticMethod(java.lang.String methodName,
                                    java.lang.Class[] arguments)

invokeConstructorAt

public java.lang.Object invokeConstructorAt(java.lang.Class at,
                                            java.lang.Object[] arguments)
Deprecated. use invokeConstructor instead

Warning, this method will be removed


invokeConstructor

public java.lang.Object invokeConstructor(java.lang.Object[] arguments)
Description copied from interface: MetaObjectProtocol
Invokes a constructor for the given arguments. The MetaClass will attempt to pick the best argument which matches the types of the objects passed within the arguments array

Specified by:
invokeConstructor in interface MetaObjectProtocol
Parameters:
arguments - The arguments to the constructor
Returns:
An instance of the java.lang.Class that this MetaObjectProtocol object applies to

selectConstructorAndTransformArguments

public int selectConstructorAndTransformArguments(int numberOfCosntructors,
                                                  java.lang.Object[] arguments)
Description copied from interface: MetaClass
Internal method to support Groovy runtime. Not for client usage.

Specified by:
selectConstructorAndTransformArguments in interface MetaClass
Parameters:
numberOfCosntructors - The number of constructors
arguments - The arguments
Returns:
selected index

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:
java.lang.IllegalStateException - if the initialisation is incomplete yet

invokeConstructor

private java.lang.Object invokeConstructor(java.lang.Class at,
                                           java.lang.Object[] arguments)

setProperties

public void setProperties(java.lang.Object bean,
                          java.util.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


getProperty

public java.lang.Object getProperty(java.lang.Class sender,
                                    java.lang.Object object,
                                    java.lang.String name,
                                    boolean useSuper,
                                    boolean fromInsideClass)
Description copied from interface: MetaClass

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

Specified by:
getProperty in interface MetaClass
Parameters:
sender - The java.lang.Class instance that requested the property
object - The Object which the property is being retrieved from
name - The name of the property
useSuper - Whether the call is to a super class property
fromInsideClass - ??
Returns:
the given property's value on the object

getCategoryMethodGetter

private MetaMethod getCategoryMethodGetter(java.lang.Class sender,
                                           java.lang.String name,
                                           boolean useLongVersion)

getCategoryMethodSetter

private MetaMethod getCategoryMethodSetter(java.lang.Class sender,
                                           java.lang.String name,
                                           boolean useLongVersion)

getProperties

public java.util.List getProperties()
Get all the properties defined for this type

Specified by:
getProperties in interface MetaClass
Specified by:
getProperties in interface MetaObjectProtocol
Returns:
a list of MetaProperty objects
See Also:
MetaProperty

findPropertyMethod

private MetaMethod findPropertyMethod(java.lang.Object methodOrList,
                                      boolean isGetter)

addElementToList

private java.lang.Object addElementToList(java.lang.Object ret,
                                          MetaMethod element)

distanceToObject

private static int distanceToObject(java.lang.Class c)

setupProperties

private void setupProperties(java.beans.PropertyDescriptor[] propertyDescriptors)
This will build up the property map (Map of MetaProperty objects, keyed on property name).


makeStaticPropertyIndex

private void makeStaticPropertyIndex()

establishStaticMetaProperty

private MetaProperty establishStaticMetaProperty(MetaProperty mp)

copyClassPropertyIndexForSuper

private void copyClassPropertyIndexForSuper(MetaClassImpl.Index dest)

inheritStaticInterfaceFields

private void inheritStaticInterfaceFields(java.util.LinkedList superClasses,
                                          java.util.Set interfaces)

inheritFields

private void inheritFields(java.util.LinkedList superClasses)

addFields

private void addFields(CachedClass klass,
                       SingleKeyHashMap propertyIndex)

copyNonPrivateFields

private void copyNonPrivateFields(SingleKeyHashMap from,
                                  SingleKeyHashMap to)

applyStrayPropertyMethods

private void applyStrayPropertyMethods(java.util.LinkedList superClasses,
                                       MetaClassImpl.Index classPropertyIndex,
                                       boolean isThis)

getPropName

private java.lang.String getPropName(java.lang.String methodName)

createMetaBeanProperty

private void createMetaBeanProperty(SingleKeyHashMap propertyIndex,
                                    java.lang.String propName,
                                    boolean isGetter,
                                    MetaMethod propertyMethod)

applyPropertyDescriptors

private void applyPropertyDescriptors(java.beans.PropertyDescriptor[] propertyDescriptors)

addMetaBeanProperty

public void addMetaBeanProperty(MetaBeanProperty mp)
Adds a new MetaBeanProperty to this MetaClass

Specified by:
addMetaBeanProperty in interface MutableMetaClass
Parameters:
mp - The MetaBeanProperty

setProperty

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

Specified by:
setProperty in interface MetaClass
Parameters:
sender - The java.lang.Class instance that is mutating the property
object - The Object which the property is being set on
name - The name of the property
newValue - The new value of the property to set
useSuper - Whether the call is to a super class property
fromInsideClass - ??

getMetaProperty

private MetaProperty getMetaProperty(CachedClass clazz,
                                     java.lang.String name,
                                     boolean useSuper,
                                     boolean useStatic)

getAttribute

public java.lang.Object getAttribute(java.lang.Class sender,
                                     java.lang.Object receiver,
                                     java.lang.String messageName,
                                     boolean useSuper)
Description copied from interface: MetaClass
Retrieves the value of an attribute (field). This method is to support the Groovy runtime and not for general client API usage.

Specified by:
getAttribute in interface MetaClass
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

getAttribute

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


setAttribute

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

Specified by:
setAttribute in interface MetaClass
Parameters:
sender - The class of the object that requested the attribute
object - The instance
attribute - The name of the attribute
newValue - 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

getClassNode

public ClassNode getClassNode()
Description copied from interface: MetaClass
Obtains a reference to the original AST for the MetaClass if it is available at runtime

Specified by:
getClassNode in interface MetaClass
Returns:
The original AST or null if it cannot be returned

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

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 initalize, which means if you need these steps, you have to add the method before running initialize the first time.

Specified by:
addMetaMethod in interface MutableMetaClass
Parameters:
method - the MetaMethod
See Also:
initialize()

addMetaMethodToIndex

private void addMetaMethodToIndex(MetaMethod method,
                                  MetaMethodIndex.Header header)

addMetaMethodToSuperIndex

private void addMetaMethodToSuperIndex(MetaMethod method,
                                       MetaMethodIndex.Header header)

checkIfStdMethod

private void checkIfStdMethod(MetaMethod method)

isInitialized

protected boolean isInitialized()

getMatchKindForCategory

private java.lang.Boolean getMatchKindForCategory(MetaMethod aMethod,
                                                  MetaMethod categoryMethod)
return false: add method null: ignore method true: replace


filterMatchingMethodForCategory

private void filterMatchingMethodForCategory(FastArray list,
                                             MetaMethod method)

findMatchingMethod

private int findMatchingMethod(CachedMethod[] data,
                               int from,
                               int to,
                               MetaMethod method)

findMethod

private MetaMethod findMethod(CachedMethod aMethod)
Returns:
the matching method which should be found

doConstructorInvoke

private static java.lang.Object doConstructorInvoke(java.lang.Class at,
                                                    CachedConstructor constructor,
                                                    java.lang.Object[] argumentArray,
                                                    boolean setAccessible)

chooseMethod

private java.lang.Object chooseMethod(java.lang.String methodName,
                                      java.lang.Object methodOrList,
                                      java.lang.Class[] argClasses,
                                      boolean coerce)
Chooses the correct method to use from a list of methods which match by name.

Parameters:
methodOrList - the possible methods to choose from
argClasses - the argument types

chooseMostSpecificParams

private java.lang.Object chooseMostSpecificParams(java.lang.String name,
                                                  java.util.List matchingMethods,
                                                  java.lang.Class[] arguments)

isGenericGetMethod

private boolean isGenericGetMethod(MetaMethod method)

initialize

public void initialize()
Description copied from interface: MetaClass
complete the initlialisation process. After this method is called no methods should be added to the meta class. Invocation of methods or access to fields/proeprties 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.

Specified by:
initialize in interface MetaClass

addProperties

private void addProperties()

isBeanDerivative

private boolean isBeanDerivative(java.lang.Class theClass)

addToAllMethodsIfPublic

private void addToAllMethodsIfPublic(MetaMethod metaMethod)

getMethods

public java.util.List getMethods()
Description copied from interface: MetaClass
Retrieves a list of MetaMethods held by the class

Specified by:
getMethods in interface MetaClass
Specified by:
getMethods in interface MetaObjectProtocol
Returns:
A list of MetaMethods
See Also:
MetaMethod

getMetaMethods

public java.util.List getMetaMethods()
Description copied from interface: MetaClass
Retrieves a list of MetaMethod instances held by this class

Specified by:
getMetaMethods in interface MetaClass
Returns:
A list of MetaMethod instances

dropStaticMethodCache

protected void dropStaticMethodCache(java.lang.String name)

dropMethodCache

protected void dropMethodCache(java.lang.String name)

getProperty

public java.lang.Object getProperty(java.lang.Object object,
                                    java.lang.String property)
Description copied from interface: MetaObjectProtocol

Retrieves a property of an instance of the class returned by the getTheClass() method.

What this means is largely down to the MetaClass implementation, however the default case would result in an attempt to invoke a JavaBean getter, or if no such getter exists a public field of the instance.

Specified by:
getProperty in interface MetaObjectProtocol
Parameters:
object - An instance of the class returned by the getTheClass() method
property - The name of the property to retrieve the value for
Returns:
The properties value
See Also:
MetaClassImpl

setProperty

public void setProperty(java.lang.Object object,
                        java.lang.String property,
                        java.lang.Object newValue)
Description copied from interface: MetaObjectProtocol

Sets a property of an instance of the class returned by the getTheClass() method.

What this means is largely down to the MetaClass implementation, however the default case would result in an attempt to invoke a JavaBean setter, or if no such setter exists to set a public field of the instance.

Specified by:
setProperty in interface MetaObjectProtocol
Parameters:
object - An instance of the class returned by the getTheClass() method
property - The name of the property to set
newValue - The new value of the property
See Also:
MetaClassImpl

getAttribute

public java.lang.Object getAttribute(java.lang.Object object,
                                     java.lang.String attribute)
Description copied from interface: MetaObjectProtocol

Retrieves an attribute of an instance of the class returned by the getTheClass() method.

What this means is largely down to the MetaClass implementation, however the default case would result in attempt to read a field of the instance.

Specified by:
getAttribute in interface MetaObjectProtocol
Parameters:
object - An instance of the class returned by the getTheClass() method
attribute - The name of the attribute to retrieve the value for
Returns:
The attribute value
See Also:
MetaClassImpl

setAttribute

public void setAttribute(java.lang.Object object,
                         java.lang.String attribute,
                         java.lang.Object newValue)
Description copied from interface: MetaObjectProtocol

Sets an attribute of an instance of the class returned by the getTheClass() method.

What this means is largely down to the MetaClass implementation, however the default case would result in an attempt to set a field of the instance.

Specified by:
setAttribute in interface MetaObjectProtocol
Parameters:
object - An instance of the class returned by the getTheClass() method
attribute - The name of the attribute to set
newValue - The new value of the attribute
See Also:
MetaClassImpl

pickMethod

public MetaMethod pickMethod(java.lang.String methodName,
                             java.lang.Class[] arguments)
Description copied from interface: MetaClass
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 bye the implementation of this MetaClass. pickMethod may or may not used during the method selection process when invoking a method thereis no warranty for that.

Specified by:
pickMethod in interface MetaClass
Parameters:
methodName - the name of the method to pick
arguments - the method arguments
Returns:
a matching MetaMethod or null

retrieveMethod

protected MetaMethod retrieveMethod(java.lang.String methodName,
                                    java.lang.Class[] arguments)
Deprecated. use pickMethod instead


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.



Copyright © ${year} The Codehaus. All Rights Reserved.