public final class ReflectUtils
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
ReflectUtils.MethodKey
The method key
|
Modifier and Type | Field and Description |
---|---|
private static java.util.Map |
_classCache
the lookup cache *
|
private static boolean |
_classCaching
class caching setting
|
private static java.util.logging.Logger |
_logger
the logger *
|
private static java.util.Map |
_methodCache
the method cache
|
private static boolean |
_methodCaching
method caching setting
|
private static java.util.Map |
WIDENABLES
keep a primitive class and their compatible types
|
Modifier | Constructor and Description |
---|---|
private |
ReflectUtils() |
Modifier and Type | Method and Description |
---|---|
static int |
computeCompatibalityScore(java.lang.Class[] methodTypes,
java.lang.Class[] argTypes)
Return whether the types of arguments is compatible with the argument type spec of a method
|
private static int |
computeWideningScore(java.lang.Class primitiveClass,
java.lang.Class c)
Check if class c can be widen to targetClass and return the score.
|
static java.lang.Class |
getClass(java.lang.String name)
Get the class
|
static java.lang.reflect.Constructor |
getConstructor(java.lang.Class type,
java.lang.Object[] args)
Get the constructor of the type given the arguments to the constructor
|
static java.lang.reflect.Method |
getInterfaceMethod(java.lang.Class[] c,
java.lang.String methodName,
java.lang.Class[] argTypes)
Resolve the method from the interfaces
|
static java.lang.reflect.Method |
getMethod(java.lang.Class type,
java.lang.String methodName,
java.lang.Class[] argTypes)
Get a named method of class type with the argument type compatible with the argument passed in.
|
static java.lang.reflect.Method |
getMethod(java.lang.Class type,
java.lang.String methodName,
java.lang.Object[] args)
Get a named method of class type with the argument type compatible with the argument passed in.
|
static java.lang.Object |
invoke(java.lang.Object o,
java.lang.String methodName,
java.lang.Object[] args)
Invoke a named method on the object using the arguments
|
static boolean |
isCompatible(java.lang.Class[] types,
java.lang.Class[] argTypes) |
static boolean |
isCompatible(java.lang.Class[] types,
java.lang.Object[] args)
Return whether the argument objects is compatible with the argument types specification
|
static boolean |
isPrimitiveCompatible(java.lang.Class primitiveClass,
java.lang.Class clazz)
Return true if primitiveClass and clazz is both primitive and clazz is primitive compatible with primitiveClass
using java rules (unwrapping or widening)
|
static boolean |
isPrimitiveInstance(java.lang.Class primitiveClass,
java.lang.Object obj)
Return whether a given object is a primitive or compatible (through unwrapping and widening) instance of primitiveClass
|
static java.lang.Object |
newInstance(java.lang.Class type,
java.lang.Object[] args)
Create a new instance of the class type with the arguments to constructor
|
static java.lang.reflect.Constructor |
searchConstructor(java.lang.Class type,
java.lang.Class[] argTypes)
Search for a particular constructor based on arg types classes
|
private static java.lang.reflect.Method |
searchMethod(java.lang.Class type,
java.lang.String methodName,
java.lang.Class[] argTypes)
Search a named method of class type through the class's hierachy
|
protected static void |
setClassCaching(boolean caching)
Set the classCaching
|
protected static void |
setMethodCaching(boolean caching)
Set the _methodCaching
|
static java.lang.Class[] |
toArgTypes(java.lang.Object[] args)
Construct the argument type class array from a list of arg objects
|
static java.lang.String |
toMethodString(java.lang.String methodName,
java.lang.Object[] args)
To the method representation string e.g.
|
private static final java.util.logging.Logger _logger
private static final java.util.Map _classCache
private static final java.util.Map _methodCache
private static boolean _classCaching
private static boolean _methodCaching
private static final java.util.Map WIDENABLES
public static final java.lang.Class[] toArgTypes(java.lang.Object[] args)
args
- the argumentspublic static final java.lang.Class getClass(java.lang.String name) throws java.lang.ClassNotFoundException
name
- the name of the classjava.lang.ClassNotFoundException
- if the class cannot be foundpublic static final java.lang.reflect.Constructor getConstructor(java.lang.Class type, java.lang.Object[] args) throws java.lang.NoSuchMethodException
type
- the typeargs
- the argumentsjava.lang.NoSuchMethodException
- if the constructor cannot be foundpublic static final java.lang.String toMethodString(java.lang.String methodName, java.lang.Object[] args)
methodName
- the methodargs
- the argumentspublic static final java.lang.reflect.Constructor searchConstructor(java.lang.Class type, java.lang.Class[] argTypes)
type
- the typeargTypes
- the argument typespublic static final boolean isCompatible(java.lang.Class[] types, java.lang.Object[] args)
types
- the argument typesargs
- the argumentspublic static final boolean isCompatible(java.lang.Class[] types, java.lang.Class[] argTypes)
public static final int computeCompatibalityScore(java.lang.Class[] methodTypes, java.lang.Class[] argTypes)
methodTypes
- the argument type spec of a methodargTypes
- the argument typepublic static final java.lang.Object newInstance(java.lang.Class type, java.lang.Object[] args) throws java.lang.IllegalAccessException, java.lang.InstantiationException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
type
- the typeargs
- the argumentjava.lang.IllegalAccessException
- if there's access problemjava.lang.InstantiationException
- if there's instantiation problemjava.lang.reflect.InvocationTargetException
- if there's target exceptionjava.lang.NoSuchMethodException
- if there's no such constructorpublic static final java.lang.Object invoke(java.lang.Object o, java.lang.String methodName, java.lang.Object[] args) throws java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
o
- the objectmethodName
- the name of the methodargs
- the argumentsjava.lang.NoSuchMethodException
- if there's no such methodjava.lang.IllegalAccessException
- if there's access problemjava.lang.reflect.InvocationTargetException
- if there's target problempublic static final java.lang.reflect.Method getInterfaceMethod(java.lang.Class[] c, java.lang.String methodName, java.lang.Class[] argTypes)
c
- the classmethodName
- the methodargTypes
- the arg typespublic static final java.lang.reflect.Method getMethod(java.lang.Class type, java.lang.String methodName, java.lang.Object[] args) throws java.lang.NoSuchMethodException
type
- the classmethodName
- the method nameargs
- the argumentsjava.lang.NoSuchMethodException
- if the method cannot be foundpublic static final java.lang.reflect.Method getMethod(java.lang.Class type, java.lang.String methodName, java.lang.Class[] argTypes) throws java.lang.NoSuchMethodException
type
- the classmethodName
- the method nameargs
- the argumentsjava.lang.NoSuchMethodException
- if the method cannot be foundprivate static final java.lang.reflect.Method searchMethod(java.lang.Class type, java.lang.String methodName, java.lang.Class[] argTypes)
type
- the classmethodName
- the method nameargTypes
- the argument typesprotected static final void setClassCaching(boolean caching)
caching
- true to turn on class cachingprotected static final void setMethodCaching(boolean caching)
caching
- true to turn on method cachingpublic static final boolean isPrimitiveInstance(java.lang.Class primitiveClass, java.lang.Object obj)
primitiveClass
- the primitive classobj
- the objectprivate static final int computeWideningScore(java.lang.Class primitiveClass, java.lang.Class c)
primitiveClass
- c
- public static final boolean isPrimitiveCompatible(java.lang.Class primitiveClass, java.lang.Class clazz)
primitiveClass
- clazz
-