|
|||||||||||
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 | |
private java.util.List |
allMethods
|
protected static java.lang.Object[] |
ARRAY_WITH_NULL
|
private MetaProperty |
arrayLengthProperty
|
private ClassNode |
classNode
|
private java.util.List |
constructors
|
static java.lang.Object[] |
EMPTY_ARRAY
|
static java.lang.Class[] |
EMPTY_TYPE_ARRAY
|
private MetaMethod |
genericGetMethod
|
private MetaMethod |
genericSetMethod
|
private boolean |
initialised
|
private java.util.List |
interfaceMethods
|
private java.util.Map |
listeners
|
private static java.util.logging.Logger |
log
|
private java.util.Map |
methodCache
|
private java.util.Map |
methodIndex
|
private java.util.List |
newGroovyMethodsList
|
private java.util.Map |
propertyMap
|
private Reflector |
reflector
|
private MetaClassRegistry |
registry
|
private java.util.Map |
staticMethodCache
|
private java.util.Map |
staticMethodIndex
|
private java.lang.Class |
theClass
|
private static boolean |
useReflection
|
Constructor Summary | |
MetaClass(MetaClassRegistry registry,
java.lang.Class theClass)
|
Method Summary | |
private void |
addInheritedMethods(java.lang.Class theClass)
|
private void |
addInterfaceMethods(java.util.List list,
java.lang.reflect.Method[] methods)
|
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 |
addNewInstanceMethod(MetaMethod method)
|
protected void |
addNewInstanceMethod(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 |
addNewStaticMethod(MetaMethod method)
|
protected void |
addNewStaticMethod(java.lang.reflect.Method 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 |
private java.lang.Object |
asPrimitiveArray(java.util.List list,
java.lang.Class parameterType)
|
private java.lang.Class |
autoboxType(java.lang.Class type)
|
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.Class[] arguments,
boolean coerce)
Chooses the correct method to use from a list of methods which match by name. |
protected java.lang.Object |
chooseMostGeneralMethodWith1NullParam(java.util.List methods)
|
protected java.lang.Object |
chooseMostSpecificParams(java.lang.String name,
java.util.List matchingMethods,
java.lang.Class[] arguments)
|
protected static boolean |
coerceGStrings(java.lang.Object[] arguments)
Coerces any GString instances into Strings |
private static java.lang.Object[] |
coerceNumbers(MetaMethod method,
java.lang.Object[] arguments)
|
protected boolean |
containsMatchingMethod(java.util.List list,
MetaMethod method)
|
(package private) java.lang.Class[] |
convertToTypeArray(java.lang.Object[] args)
param instance array to the type array |
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()
|
java.lang.Object |
getAttribute(java.lang.Object object,
java.lang.String attribute)
Looks up the given attribute (field) on the given object |
ClassNode |
getClassNode()
|
protected java.util.List |
getInterfaceMethods()
|
java.util.List |
getMetaMethods()
|
java.util.List |
getMethods()
|
java.util.List |
getMethods(java.lang.String name)
|
protected java.lang.Class[] |
getParameterTypes(java.lang.Object methodOrConstructor)
|
java.util.List |
getProperties()
Get all the properties defined for this type |
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 |
isCompatibleClass(java.lang.Class type,
java.lang.Class value,
boolean includeCoerce)
|
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()
|
static boolean |
isValidMethod(java.lang.Class[] paramTypes,
java.lang.Class[] arguments,
boolean includeCoerce)
|
protected boolean |
isValidMethod(java.lang.Object method,
java.lang.Class[] 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 |
pickMethod(java.lang.String methodName,
java.lang.Class[] arguments)
pick a method in a strict manner, i.e., without reinterpreting the first List argument. |
protected MetaMethod |
pickStaticMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object[] arguments)
|
protected MetaMethod |
pickStaticMethod(java.lang.String methodName,
java.lang.Class[] arguments)
|
protected void |
registerInstanceMethods()
|
private void |
registerMethods(boolean instanceMethods)
|
protected void |
registerStaticMethods()
|
java.lang.reflect.Constructor |
retrieveConstructor(java.lang.Class[] arguments)
|
protected MetaMethod |
retrieveMethod(java.lang.Object owner,
java.lang.String methodName,
java.lang.Object[] arguments)
|
MetaMethod |
retrieveMethod(java.lang.String methodName,
java.lang.Class[] arguments)
|
MetaMethod |
retrieveStaticMethod(java.lang.String methodName,
java.lang.Class[] arguments)
|
void |
setAttribute(java.lang.Object object,
java.lang.String attribute,
java.lang.Object newValue)
Sets the given attribute (field) on the given object |
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 |
protected void |
setupProperties(java.beans.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. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
private static final java.util.logging.Logger log
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
private static boolean useReflection
private MetaClassRegistry registry
private java.lang.Class theClass
private ClassNode classNode
private java.util.Map methodIndex
private java.util.Map staticMethodIndex
private java.util.List newGroovyMethodsList
private java.util.Map propertyMap
private java.util.Map listeners
private java.util.Map methodCache
private java.util.Map staticMethodCache
private MetaMethod genericGetMethod
private MetaMethod genericSetMethod
private java.util.List constructors
private java.util.List allMethods
private java.util.List interfaceMethods
private Reflector reflector
private boolean initialised
private MetaProperty arrayLengthProperty
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
- private void addInheritedMethods(java.lang.Class theClass)
public java.util.List getMethods(java.lang.String name)
public java.util.List getStaticMethods(java.lang.String name)
protected void addNewInstanceMethod(java.lang.reflect.Method method)
method
- protected void addNewInstanceMethod(MetaMethod method)
protected void addNewStaticMethod(java.lang.reflect.Method method)
protected void addNewStaticMethod(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 retrieveMethod(java.lang.Object owner, java.lang.String methodName, java.lang.Object[] arguments)
public MetaMethod retrieveMethod(java.lang.String methodName, java.lang.Class[] arguments)
public java.lang.reflect.Constructor retrieveConstructor(java.lang.Class[] arguments)
public MetaMethod retrieveStaticMethod(java.lang.String methodName, java.lang.Class[] arguments)
protected MetaMethod pickMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object[] arguments)
protected MetaMethod pickMethod(java.lang.String methodName, java.lang.Class[] arguments)
methodName
- 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)
protected MetaMethod pickStaticMethod(java.lang.String methodName, java.lang.Class[] 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 java.util.List getProperties()
protected void setupProperties(java.beans.PropertyDescriptor[] propertyDescriptors)
public void setProperty(java.lang.Object object, java.lang.String property, java.lang.Object newValue)
public java.lang.Object getAttribute(java.lang.Object object, java.lang.String attribute)
public void setAttribute(java.lang.Object object, java.lang.String attribute, java.lang.Object newValue)
private java.lang.Object asPrimitiveArray(java.util.List list, java.lang.Class parameterType)
list
- parameterType
-
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)
private static java.lang.Object[] coerceNumbers(MetaMethod method, java.lang.Object[] arguments)
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.Class[] 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.Class[] arguments, boolean includeCoerce)
public static boolean isValidMethod(java.lang.Class[] paramTypes, java.lang.Class[] arguments, boolean includeCoerce)
protected java.lang.Object chooseMostSpecificParams(java.lang.String name, java.util.List matchingMethods, java.lang.Class[] 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 chooseMostGeneralMethodWith1NullParam(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 static boolean isCompatibleClass(java.lang.Class type, java.lang.Class value, boolean includeCoerce)
protected boolean isAssignableFrom(java.lang.Class mostSpecificType, java.lang.Class type)
private java.lang.Class autoboxType(java.lang.Class type)
protected static boolean coerceGStrings(java.lang.Object[] arguments)
protected boolean isGenericSetMethod(MetaMethod method)
protected boolean isGenericGetMethod(MetaMethod method)
private void registerMethods(boolean instanceMethods)
protected void registerStaticMethods()
protected void registerInstanceMethods()
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()
public java.util.List getMetaMethods()
protected java.util.List getInterfaceMethods()
private void addInterfaceMethods(java.util.List list, java.lang.reflect.Method[] methods)
java.lang.Class[] convertToTypeArray(java.lang.Object[] args)
args
-
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |