|
|||||||||||
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
|
protected MetaClassRegistry |
registry
|
protected Class |
theClass
|
Constructor Summary | |
MetaClass(MetaClassRegistry registry,
Class theClass)
|
Method Summary | |
protected void |
addMethod(MetaMethod method,
boolean forceOverwrite)
|
protected void |
addMethods(Class theClass,
boolean forceOverwrite)
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(Method method)
Allows static method definitions to be added to a meta class as if it was an instance 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,
Class[] arguments,
boolean coerce)
Chooses the correct method to use from a list of methods which match by name. |
protected Object |
chooseMostGeneralMethodWith1NullParam(List methods)
|
protected Object |
chooseMostSpecificParams(String name,
List matchingMethods,
Class[] arguments)
|
protected static 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()
|
Object |
getAttribute(Object object,
String attribute)
Looks up the given attribute (field) on the given object |
ClassNode |
getClassNode()
|
protected List |
getInterfaceMethods()
|
List |
getMetaMethods()
|
Closure |
getMethodPointer(Object object,
String methodName)
Returns a callable object for the given method name on the object. |
List |
getMethods()
|
List |
getMethods(String name)
|
protected Class[] |
getParameterTypes(Object methodOrConstructor)
|
List |
getProperties()
Get all the properties defined for this type |
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 |
isCompatibleClass(Class type,
Class value,
boolean includeCoerce)
|
protected static boolean |
isCompatibleInstance(Class type,
Object value,
boolean includeCoerce)
|
protected boolean |
isGenericGetMethod(MetaMethod method)
|
protected boolean |
isGenericSetMethod(MetaMethod method)
|
static boolean |
isUseReflection()
|
static boolean |
isValidMethod(Class[] paramTypes,
Class[] arguments,
boolean includeCoerce)
|
protected boolean |
isValidMethod(Object method,
Class[] 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 |
pickMethod(String methodName,
Class[] arguments)
pick a method in a strict manner, i.e., without reinterpreting the first List argument. |
protected MetaMethod |
pickStaticMethod(Object object,
String methodName,
Object[] arguments)
|
protected MetaMethod |
pickStaticMethod(String methodName,
Class[] arguments)
|
protected void |
registerInstanceMethods()
|
protected void |
registerStaticMethods()
|
protected void |
removeMatchingMethod(List list,
MetaMethod method)
remove a method of the same matching prototype was found in the list |
Constructor |
retrieveConstructor(Class[] arguments)
|
protected MetaMethod |
retrieveMethod(Object owner,
String methodName,
Object[] arguments)
|
MetaMethod |
retrieveMethod(String methodName,
Class[] arguments)
|
MetaMethod |
retrieveStaticMethod(String methodName,
Class[] arguments)
|
void |
setAttribute(Object object,
String attribute,
Object newValue)
Sets the given attribute (field) on the given object |
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 |
protected void |
setupProperties(PropertyDescriptor[] propertyDescriptors)
This will build up the property map (Map of MetaProperty objects, keyed on property name). |
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
protected MetaClassRegistry registry
protected Class theClass
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 addNewStaticMethod(Method method)
public Object invokeMethod(Object object, String methodName, Object arguments)
public Object invokeMethod(Object object, String methodName, Object[] arguments)
protected MetaMethod retrieveMethod(Object owner, String methodName, Object[] arguments)
public MetaMethod retrieveMethod(String methodName, Class[] arguments)
public Constructor retrieveConstructor(Class[] arguments)
public MetaMethod retrieveStaticMethod(String methodName, Class[] arguments)
protected MetaMethod pickMethod(Object object, String methodName, Object[] arguments)
protected MetaMethod pickMethod(String methodName, Class[] arguments)
methodName
- arguments
-
public Object invokeStaticMethod(Object object, String methodName, Object[] arguments)
protected MetaMethod pickStaticMethod(Object object, String methodName, Object[] arguments)
protected MetaMethod pickStaticMethod(String methodName, Class[] arguments)
public Object invokeConstructor(Object[] arguments)
public void setProperties(Object bean, Map map)
public Object getProperty(Object object, String property)
public List getProperties()
protected void setupProperties(PropertyDescriptor[] propertyDescriptors)
public void setProperty(Object object, String property, Object newValue)
public Object getAttribute(Object object, String attribute)
public void setAttribute(Object object, String attribute, Object newValue)
public Closure getMethodPointer(Object object, String methodName)
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, boolean forceOverwrite)
theClass
- protected void addMethod(MetaMethod method, boolean forceOverwrite)
protected boolean containsMatchingMethod(List list, MetaMethod method)
protected void removeMatchingMethod(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, Class[] arguments, boolean coerce)
methods
- the possible methods to choose fromarguments
- the original argument to the method
protected boolean isValidMethod(Object method, Class[] arguments, boolean includeCoerce)
public static boolean isValidMethod(Class[] paramTypes, Class[] arguments, boolean includeCoerce)
protected Object chooseMostSpecificParams(String name, List matchingMethods, Class[] arguments)
protected void checkForInvalidOverloading(String name, Class[] baseTypes, Class[] derivedTypes)
protected Class[] getParameterTypes(Object methodOrConstructor)
protected Object chooseMostGeneralMethodWith1NullParam(List methods)
protected Object chooseEmptyMethodParams(List methods)
protected static boolean isCompatibleInstance(Class type, Object value, boolean includeCoerce)
protected static boolean isCompatibleClass(Class type, Class value, boolean includeCoerce)
protected boolean isAssignableFrom(Class mostSpecificType, Class type)
protected static 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()
public List getMetaMethods()
protected List getInterfaceMethods()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |