|
|||||||||||
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 Object[] |
ARRAY_WITH_NULL
|
static Object[] |
EMPTY_ARRAY
|
static Class[] |
EMPTY_TYPE_ARRAY
|
Constructor Summary | |
MetaClass(MetaClassRegistry registry,
Class theClass)
|
Method Summary | |
protected void |
addMethod(MetaMethod method)
|
protected void |
addMethods(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 |
addNewInstanceMethod(MetaMethod method)
|
protected void |
addNewInstanceMethod(Method method)
Allows static method definitions to be added to a meta class as if it was an instance method |
protected void |
addNewStaticMethod(MetaMethod method)
|
protected void |
addNewStaticMethod(Method method)
|
protected void |
addNewStaticMethodsFrom(Class theClass)
Adds all of the newly defined methods from the given class to this metaclass |
protected Object[] |
asArray(Object arguments)
Converts the given object into an array; if its an array then just cast otherwise wrap it in an array |
protected String |
capitalize(String property)
|
protected void |
checkForInvalidOverloading(String name,
Class[] baseTypes,
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 Object |
chooseEmptyMethodParams(List methods)
|
protected Object |
chooseMethod(String methodName,
List methods,
Object[] arguments,
boolean coerce)
Chooses the correct method to use from a list of methods which match by name. |
protected Object |
chooseMostGeneralMethodWith1Param(List methods)
|
protected Object |
chooseMostSpecificParams(String name,
List matchingMethods,
Object[] arguments)
|
protected boolean |
coerceGStrings(Object[] arguments)
Coerces any GString instances into Strings |
protected boolean |
containsMatchingMethod(List list,
MetaMethod method)
|
protected Object |
createListenerProxy(Class listenerType,
String listenerMethodName,
Closure closure)
|
protected MetaMethod |
createMetaMethod(Method method)
|
protected Object |
doConstructorInvoke(Constructor constructor,
Object[] argumentArray)
|
protected Object |
doMethodInvoke(Object object,
MetaMethod method,
Object[] argumentArray)
|
protected MetaMethod |
findGetter(Object object,
String name)
|
protected MetaMethod |
findMethod(Method aMethod)
|
protected MetaMethod |
findStaticGetter(Class type,
String name)
|
protected void |
generateReflector()
|
ClassNode |
getClassNode()
|
protected List |
getInterfaceMethods()
|
List |
getMethods()
|
List |
getMethods(String name)
|
protected Class[] |
getParameterTypes(Object methodOrConstructor)
|
Object |
getProperty(Object object,
String property)
|
List |
getStaticMethods(String name)
|
protected Object |
getStaticProperty(Class aClass,
String property)
|
Object |
invokeConstructor(Object[] arguments)
|
Object |
invokeMethod(Object object,
String methodName,
Object arguments)
|
Object |
invokeMethod(Object object,
String methodName,
Object[] arguments)
Invokes the given method on the object. |
Object |
invokeStaticMethod(Object object,
String methodName,
Object[] arguments)
|
protected boolean |
isAssignableFrom(Class mostSpecificType,
Class type)
|
protected static boolean |
isCompatibleInstance(Class type,
Object value,
boolean includeCoerce)
|
protected boolean |
isGenericGetMethod(MetaMethod method)
|
protected boolean |
isGenericSetMethod(MetaMethod method)
|
static boolean |
isUseReflection()
|
protected static boolean |
isValidMethod(Class[] paramTypes,
Object[] arguments,
boolean includeCoerce)
|
protected boolean |
isValidMethod(Object method,
Object[] arguments,
boolean includeCoerce)
|
protected boolean |
isValidReflectorMethod(MetaMethod method)
|
protected Reflector |
loadReflector(List methods)
|
protected Class |
loadReflectorClass(String name)
|
protected Class |
loadReflectorClass(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(Object object,
String methodName,
Object[] arguments)
Picks which method to invoke for the given object, method name and arguments |
protected MetaMethod |
pickStaticMethod(Object object,
String methodName,
Object[] arguments)
|
protected void |
registerInstanceMethods()
|
protected void |
registerStaticMethods()
|
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(Object object,
String property,
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. |
String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final Object[] EMPTY_ARRAY
public static Class[] EMPTY_TYPE_ARRAY
protected static final Object[] ARRAY_WITH_NULL
Constructor Detail |
public MetaClass(MetaClassRegistry registry, Class theClass) throws IntrospectionException
Method Detail |
public static boolean isUseReflection()
public static void setUseReflection(boolean useReflection)
useReflection
- public List getMethods(String name)
public List getStaticMethods(String name)
protected void addNewInstanceMethod(Method method)
method
- protected void addNewInstanceMethod(MetaMethod method)
protected void addNewStaticMethod(Method method)
protected void addNewStaticMethod(MetaMethod method)
public Object invokeMethod(Object object, String methodName, Object arguments)
public Object invokeMethod(Object object, String methodName, Object[] arguments)
protected MetaMethod pickMethod(Object object, String methodName, Object[] arguments)
public Object invokeStaticMethod(Object object, String methodName, Object[] arguments)
protected MetaMethod pickStaticMethod(Object object, String methodName, Object[] arguments)
public Object invokeConstructor(Object[] arguments)
public void setProperties(Object bean, Map map)
public Object getProperty(Object object, String property)
public void setProperty(Object object, String property, Object newValue)
public ClassNode getClassNode()
public String toString()
protected Object[] asArray(Object arguments)
protected Object createListenerProxy(Class listenerType, 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(Class theClass)
theClass
- protected void addMethod(MetaMethod method)
protected boolean containsMatchingMethod(List list, MetaMethod method)
protected void addNewStaticMethodsFrom(Class theClass)
theClass
- protected Object getStaticProperty(Class aClass, String property)
protected MetaMethod findMethod(Method aMethod)
protected MetaMethod findGetter(Object object, String name)
protected MetaMethod findStaticGetter(Class type, String name)
protected Object doMethodInvoke(Object object, MetaMethod method, Object[] argumentArray)
protected Object doConstructorInvoke(Constructor constructor, Object[] argumentArray)
protected Object chooseMethod(String methodName, List methods, Object[] arguments, boolean coerce)
methods
- the possible methods to choose fromarguments
- the original argument to the method
protected boolean isValidMethod(Object method, Object[] arguments, boolean includeCoerce)
protected static boolean isValidMethod(Class[] paramTypes, Object[] arguments, boolean includeCoerce)
protected Object chooseMostSpecificParams(String name, List matchingMethods, Object[] arguments)
protected void checkForInvalidOverloading(String name, Class[] baseTypes, Class[] derivedTypes)
protected Class[] getParameterTypes(Object methodOrConstructor)
protected Object chooseMostGeneralMethodWith1Param(List methods)
protected Object chooseEmptyMethodParams(List methods)
protected static boolean isCompatibleInstance(Class type, Object value, boolean includeCoerce)
protected boolean isAssignableFrom(Class mostSpecificType, Class type)
protected boolean coerceGStrings(Object[] arguments)
protected boolean isGenericSetMethod(MetaMethod method)
protected boolean isGenericGetMethod(MetaMethod method)
protected void registerStaticMethods()
protected void registerInstanceMethods()
protected String capitalize(String property)
protected void onMethodChange()
protected void checkInitialised()
protected MetaMethod createMetaMethod(Method method)
protected boolean isValidReflectorMethod(MetaMethod method)
protected void generateReflector()
protected Reflector loadReflector(List methods)
protected Class loadReflectorClass(String name, byte[] bytecode) throws ClassNotFoundException
ClassNotFoundException
protected Class loadReflectorClass(String name) throws ClassNotFoundException
ClassNotFoundException
public List getMethods()
protected List getInterfaceMethods()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |