Package com.jogamp.common.util
Class ReflectionUtil
- java.lang.Object
-
- com.jogamp.common.util.ReflectionUtil
-
public final class ReflectionUtil extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ReflectionUtil.AWTNames
static class
ReflectionUtil.MethodAccessor
Convenient Method access class
-
Field Summary
Fields Modifier and Type Field Description static boolean
DEBUG
static boolean
DEBUG_STATS_FORNAME
-
Constructor Summary
Constructors Constructor Description ReflectionUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Object
callMethod(Object instance, Method method, Object... args)
static Object
callStaticMethod(String clazzName, String methodName, Class<?>[] argTypes, Object[] args, ClassLoader cl)
static Object
createInstance(Class<?> clazz, Class<?>[] cstrArgTypes, Object... cstrArgs)
static Object
createInstance(Class<?> clazz, Object... cstrArgs)
static Object
createInstance(Constructor<?> cstr, Object... cstrArgs)
static Object
createInstance(String clazzName, Class<?>[] cstrArgTypes, Object[] cstrArgs, ClassLoader cl)
static Object
createInstance(String clazzName, ClassLoader cl)
static Object
createInstance(String clazzName, Object[] cstrArgs, ClassLoader cl)
static Class<?>
getClass(String clazzName, boolean initializeClazz, ClassLoader cl)
Loads and returns the class or null.static Constructor<?>
getConstructor(Class<?> clazz, Class<?>... cstrArgTypes)
Returns a compatible constructor if available, otherwise throws an exception.static Constructor<?>
getConstructor(String clazzName, Class<?>[] cstrArgTypes, boolean initializeClazz, ClassLoader cl)
static Constructor<?>
getConstructor(String clazzName, ClassLoader cl)
static StringBuilder
getForNameStats(StringBuilder sb)
static Method
getMethod(Class<?> clazz, String methodName, Class<?>... argTypes)
static Method
getMethod(String clazzName, String methodName, Class<?>[] argTypes, ClassLoader cl)
static boolean
implementationOf(Class<?> clazz, String faceName)
static boolean
implementationOf(Object obj, String faceName)
static boolean
instanceOf(Class<?> clazz, String clazzName)
static boolean
instanceOf(Object obj, String clazzName)
static boolean
isAWTComponent(Class<?> clazz)
static boolean
isAWTComponent(Object target)
static boolean
isClassAvailable(String clazzName, ClassLoader cl)
Returns true only if the class could be loaded.static void
resetForNameCount()
-
-
-
Method Detail
-
resetForNameCount
public static void resetForNameCount()
-
getForNameStats
public static StringBuilder getForNameStats(StringBuilder sb)
-
isClassAvailable
public static final boolean isClassAvailable(String clazzName, ClassLoader cl)
Returns true only if the class could be loaded.
-
getClass
public static final Class<?> getClass(String clazzName, boolean initializeClazz, ClassLoader cl) throws JogampRuntimeException
Loads and returns the class or null.
-
getConstructor
public static final Constructor<?> getConstructor(String clazzName, Class<?>[] cstrArgTypes, boolean initializeClazz, ClassLoader cl) throws JogampRuntimeException
- Parameters:
initializeClazz
- TODO- Throws:
JogampRuntimeException
- if the constructor can not be delivered.
-
getConstructor
public static final Constructor<?> getConstructor(Class<?> clazz, Class<?>... cstrArgTypes) throws JogampRuntimeException
Returns a compatible constructor if available, otherwise throws an exception.It first attempts to get the specific Constructor using the given
cstrArgTypes
. If this fails w/NoSuchMethodException
, a compatible Constructor is being looked-up w/ with parameter types assignable from the givencstrArgs
.- Throws:
JogampRuntimeException
- if the constructor can not be delivered.
-
getConstructor
public static final Constructor<?> getConstructor(String clazzName, ClassLoader cl) throws JogampRuntimeException
- Throws:
JogampRuntimeException
-
createInstance
public static final Object createInstance(Constructor<?> cstr, Object... cstrArgs) throws JogampRuntimeException, RuntimeException
- Throws:
JogampRuntimeException
- if the instance can not be created.RuntimeException
-
createInstance
public static final Object createInstance(Class<?> clazz, Class<?>[] cstrArgTypes, Object... cstrArgs) throws JogampRuntimeException, RuntimeException
- Throws:
JogampRuntimeException
- if the instance can not be created.RuntimeException
-
createInstance
public static final Object createInstance(Class<?> clazz, Object... cstrArgs) throws JogampRuntimeException, RuntimeException
-
createInstance
public static final Object createInstance(String clazzName, Class<?>[] cstrArgTypes, Object[] cstrArgs, ClassLoader cl) throws JogampRuntimeException, RuntimeException
-
createInstance
public static final Object createInstance(String clazzName, Object[] cstrArgs, ClassLoader cl) throws JogampRuntimeException, RuntimeException
-
createInstance
public static final Object createInstance(String clazzName, ClassLoader cl) throws JogampRuntimeException, RuntimeException
-
isAWTComponent
public static boolean isAWTComponent(Object target)
-
isAWTComponent
public static boolean isAWTComponent(Class<?> clazz)
-
getMethod
public static final Method getMethod(Class<?> clazz, String methodName, Class<?>... argTypes) throws JogampRuntimeException, RuntimeException
- Throws:
JogampRuntimeException
- if the Method can not be found.RuntimeException
-
getMethod
public static final Method getMethod(String clazzName, String methodName, Class<?>[] argTypes, ClassLoader cl) throws JogampRuntimeException, RuntimeException
- Throws:
JogampRuntimeException
- if the Method can not be found.RuntimeException
-
callMethod
public static final Object callMethod(Object instance, Method method, Object... args) throws JogampRuntimeException, RuntimeException
- Parameters:
instance
- may be null in case of a static methodmethod
- the method to be calledargs
- the method arguments- Returns:
- the methods result, maybe null if void
- Throws:
JogampRuntimeException
- if call failsRuntimeException
- if call fails
-
callStaticMethod
public static final Object callStaticMethod(String clazzName, String methodName, Class<?>[] argTypes, Object[] args, ClassLoader cl) throws JogampRuntimeException, RuntimeException
- Throws:
JogampRuntimeException
- if the instance can not be created.RuntimeException
-
-