|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgroovy.lang.MetaClass
Allows methods to be dynamically added to existing classes at runtime
Field Summary | |
protected static java.lang.Object[] |
ARRAY_WITH_NULL
|
static java.lang.Object[] |
EMPTY_ARRAY
|
static java.lang.Class[] |
EMPTY_TYPE_ARRAY
|
Constructor Summary | |
MetaClass(MetaClassRegistry registry,
java.lang.Class theClass)
|
Method Summary | |
protected void |
addMethod(MetaMethod method)
|
protected void |
addMethods(java.lang.Class theClass)
Adds all the methods declared in the given class to the metaclass ignoring any matching methods already defined by a derived class |
protected void |
addNewStaticInstanceMethod(MetaMethod method)
|
protected void |
addNewStaticInstanceMethod(java.lang.reflect.Method method)
Allows static method definitions to be added to a meta class as if it was an instance method |
protected void |
addNewStaticMethodsFrom(java.lang.Class theClass)
Adds all of the newly defined methods from the given class to this metaclass |
protected java.lang.Object[] |
asArray(java.lang.Object arguments)
Converts the given object into an array; if its an array then just cast otherwise wrap it in an array |
protected java.lang.String |
capitalize(java.lang.String property)
|
protected void |
checkForInvalidOverloading(java.lang.String name,
java.lang.Class[] baseTypes,
java.lang.Class[] derivedTypes)
Checks that one of the parameter types is a superset of the other and that the two lists of types don't conflict. |
protected void |
checkInitialised()
|
protected java.lang.Object |
chooseEmptyMethodParams(java.util.List methods)
|
protected java.lang.Object |
chooseMethod(java.lang.String methodName,
java.util.List methods,
java.lang.Object[] arguments,
boolean coerce)
Chooses the correct method to use from a list of methods which match by name. |
protected java.lang.Object |
chooseMostGeneralMethodWith1Param(java.util.List methods)
|
protected java.lang.Object |
chooseMostSpecificParams(java.lang.String name,
java.util.List matchingMethods,
java.lang.Object[] arguments)
|
protected boolean |
coerceGStrings(java.lang.Object[] arguments)
Coerces any GString instances into Strings |
protected boolean |
containsMatchingMethod(java.util.List list,
MetaMethod method)
|
protected java.lang.Object |
createListenerProxy(java.lang.Class listenerType,
java.lang.String listenerMethodName,
Closure closure)
|
protected MetaMethod |
createMetaMethod(java.lang.reflect.Method method)
|
protected java.lang.Object |
doConstructorInvoke(java.lang.reflect.Constructor constructor,
java.lang.Object[] argumentArray)
|
protected java.lang.Object |
doMethodInvoke(java.lang.Object object,
MetaMethod method,
java.lang.Object[] argumentArray)
|
protected MetaMethod |
findGetter(java.lang.Object object,
java.lang.String name)
|
protected MetaMethod |
findMethod(java.lang.reflect.Method aMethod)
|
protected MetaMethod |
findStaticGetter(java.lang.Class type,
java.lang.String name)
|
protected void |
generateReflector()
|
ClassNode |
getClassNode()
|
protected java.util.List |
getInterfaceMethods()
|
java.util.List |
getMethods()
|
java.util.List |
getMethods(java.lang.String name)
|
protected java.lang.Class[] |
getParameterTypes(java.lang.Object methodOrConstructor)
|
java.lang.Object |
getProperty(java.lang.Object object,
java.lang.String property)
|
java.util.List |
getStaticMethods(java.lang.String name)
|
protected java.lang.Object |
getStaticProperty(java.lang.Class aClass,
java.lang.String property)
|
java.lang.Object |
invokeConstructor(java.lang.Object[] arguments)
|
java.lang.Object |
invokeMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object arguments)
|
java.lang.Object |
invokeMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object[] arguments)
Invokes the given method on the object. |
java.lang.Object |
invokeStaticMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object[] arguments)
|
protected boolean |
isAssignableFrom(java.lang.Class mostSpecificType,
java.lang.Class type)
|
protected static boolean |
isCompatibleInstance(java.lang.Class type,
java.lang.Object value,
boolean includeCoerce)
|
protected boolean |
isGenericGetMethod(MetaMethod method)
|
protected boolean |
isGenericSetMethod(MetaMethod method)
|
static boolean |
isUseReflection()
|
protected static boolean |
isValidMethod(java.lang.Class[] paramTypes,
java.lang.Object[] arguments,
boolean includeCoerce)
|
protected boolean |
isValidMethod(java.lang.Object method,
java.lang.Object[] arguments,
boolean includeCoerce)
|
protected boolean |
isValidReflectorMethod(MetaMethod method)
|
protected Reflector |
loadReflector(java.util.List methods)
|
protected java.lang.Class |
loadReflectorClass(java.lang.String name)
|
protected java.lang.Class |
loadReflectorClass(java.lang.String name,
byte[] bytecode)
|
protected void |
onMethodChange()
Call this method when any mutation method is called, such as adding a new method to this MetaClass so that any caching or bytecode generation can be regenerated. |
protected MetaMethod |
pickMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object[] arguments)
Picks which method to invoke for the given object, method name and arguments |
protected MetaMethod |
pickStaticMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object[] arguments)
|
protected void |
registerStaticMethods()
|
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.Object object,
java.lang.String property,
java.lang.Object newValue)
Sets the property value on an object |
static void |
setUseReflection(boolean useReflection)
Allows reflection to be enabled in situations where bytecode generation of method invocations causes issues. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final java.lang.Object[] EMPTY_ARRAY
public static java.lang.Class[] EMPTY_TYPE_ARRAY
protected static final java.lang.Object[] ARRAY_WITH_NULL
Constructor Detail |
public MetaClass(MetaClassRegistry registry, java.lang.Class theClass) throws java.beans.IntrospectionException
Method Detail |
public static boolean isUseReflection()
public static void setUseReflection(boolean useReflection)
useReflection
- public java.util.List getMethods(java.lang.String name)
public java.util.List getStaticMethods(java.lang.String name)
protected void addNewStaticInstanceMethod(java.lang.reflect.Method method)
method
- protected void addNewStaticInstanceMethod(MetaMethod method)
public java.lang.Object invokeMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object arguments)
public java.lang.Object invokeMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object[] arguments)
protected MetaMethod pickMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object[] arguments)
public java.lang.Object invokeStaticMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object[] arguments)
protected MetaMethod pickStaticMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object[] arguments)
public java.lang.Object invokeConstructor(java.lang.Object[] arguments)
public void setProperties(java.lang.Object bean, java.util.Map map)
public java.lang.Object getProperty(java.lang.Object object, java.lang.String property)
public void setProperty(java.lang.Object object, java.lang.String property, java.lang.Object newValue)
public ClassNode getClassNode()
public java.lang.String toString()
protected java.lang.Object[] asArray(java.lang.Object arguments)
protected java.lang.Object createListenerProxy(java.lang.Class listenerType, java.lang.String listenerMethodName, Closure closure)
listenerType
- the interface of the listener to proxylistenerMethodName
- the name of the method in the listener API to call the
closure onclosure
- the closure to invoke on the listenerMethodName method
invocation
protected void addMethods(java.lang.Class theClass)
theClass
- protected void addMethod(MetaMethod method)
protected boolean containsMatchingMethod(java.util.List list, MetaMethod method)
protected void addNewStaticMethodsFrom(java.lang.Class theClass)
theClass
- protected java.lang.Object getStaticProperty(java.lang.Class aClass, java.lang.String property)
protected MetaMethod findMethod(java.lang.reflect.Method aMethod)
protected MetaMethod findGetter(java.lang.Object object, java.lang.String name)
protected MetaMethod findStaticGetter(java.lang.Class type, java.lang.String name)
protected java.lang.Object doMethodInvoke(java.lang.Object object, MetaMethod method, java.lang.Object[] argumentArray)
protected java.lang.Object doConstructorInvoke(java.lang.reflect.Constructor constructor, java.lang.Object[] argumentArray)
protected java.lang.Object chooseMethod(java.lang.String methodName, java.util.List methods, java.lang.Object[] arguments, boolean coerce)
methods
- the possible methods to choose fromarguments
- the original argument to the method
protected boolean isValidMethod(java.lang.Object method, java.lang.Object[] arguments, boolean includeCoerce)
protected static boolean isValidMethod(java.lang.Class[] paramTypes, java.lang.Object[] arguments, boolean includeCoerce)
protected java.lang.Object chooseMostSpecificParams(java.lang.String name, java.util.List matchingMethods, java.lang.Object[] arguments)
protected void checkForInvalidOverloading(java.lang.String name, java.lang.Class[] baseTypes, java.lang.Class[] derivedTypes)
protected java.lang.Class[] getParameterTypes(java.lang.Object methodOrConstructor)
protected java.lang.Object chooseMostGeneralMethodWith1Param(java.util.List methods)
protected java.lang.Object chooseEmptyMethodParams(java.util.List methods)
protected static boolean isCompatibleInstance(java.lang.Class type, java.lang.Object value, boolean includeCoerce)
protected boolean isAssignableFrom(java.lang.Class mostSpecificType, java.lang.Class type)
protected boolean coerceGStrings(java.lang.Object[] arguments)
protected boolean isGenericSetMethod(MetaMethod method)
protected boolean isGenericGetMethod(MetaMethod method)
protected void registerStaticMethods()
protected java.lang.String capitalize(java.lang.String property)
protected void onMethodChange()
protected void checkInitialised()
protected MetaMethod createMetaMethod(java.lang.reflect.Method method)
protected boolean isValidReflectorMethod(MetaMethod method)
protected void generateReflector()
protected Reflector loadReflector(java.util.List methods)
protected java.lang.Class loadReflectorClass(java.lang.String name, byte[] bytecode) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
protected java.lang.Class loadReflectorClass(java.lang.String name) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
public java.util.List getMethods()
protected java.util.List getInterfaceMethods()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |