public final class ReflectionHelper extends Object
Modifier and Type | Field and Description |
---|---|
static int |
JAVA_VERSION |
static Class<?> |
LOCAL_DATE_CLASS |
static Class<?> |
LOCAL_DATE_TIME_CLASS |
static Class<?> |
LOCAL_DATE_TIME_FORMATTER_CLASS |
Constructor and Description |
---|
ReflectionHelper() |
Modifier and Type | Method and Description |
---|---|
static <T> T[] |
array(T... content) |
static List<Object> |
array2ObjectList(Object array)
Same as Arrays.asList(...), but does automatically conversion of primitive arrays.
|
static Object |
createOptional(Object value)
Create an instance of java.util.Optional for given value.
|
static Set<Class<?>> |
findAllCommonSuperInterfaces(Class<?> a,
Class<?> b) |
static List<Class<?>> |
findAllSuperInterfaces(Class<?> a)
Returns list of super interfaces,sorted from the top (super) to the bottom (extended).
|
static Method |
findMethodByName(Class<?> clazz,
String name)
Non exception throwing shortcut to find the first method with a given name.
|
static <T> Constructor<T> |
getCallableConstructorForParams(Class<T> type,
Class<?>... params)
Search for a suitable constructor which is invokable by the given parameter types.
|
static Method |
getCallableFactoryForParams(Class<?> type,
Class<?>... params)
Search for a static factory method returning the target type.
|
static Class<?> |
getCallerClass(int level) |
static Class<?> |
getDirectCallerClass() |
static Map<String,Integer> |
getMethodParameterIndexes(Method m)
Try to determine the names of the method parameters.
|
static Class<?> |
getParameterType(Type type) |
static boolean |
hasParameters(Method method) |
static boolean |
hasReturnType(Method method)
Defensive implemented method to determine if method has a return type.
|
static Object |
invokeDefaultMethod(Method method,
Object[] args,
Object proxy) |
static Object |
invokeMethod(Object obj,
Class<?> clazz,
String methodName,
Class<?>[] parameterTypes,
Object[] params) |
static boolean |
isDefaultMethod(Method m) |
static boolean |
isOptional(Type type)
Checks if given type is java.util.Optional with a generic type parameter.
|
static boolean |
isRawType(Type type)
Checks if a given type is a raw type.
|
static boolean |
isStreamClass(Class<?> returnType) |
static boolean |
mayProvideParameterNames() |
static void |
throwThrowable(Class<?> throwableType,
Object[] args,
Throwable optionalCause)
Throws a throwable of type throwableType.
|
static Object |
toStream(List<?> result) |
static Object |
unwrap(Class<?> type,
Object object)
Unwrap a given object until we assume it is a value.
|
public static final Class<?> LOCAL_DATE_CLASS
public static final Class<?> LOCAL_DATE_TIME_CLASS
public static final Class<?> LOCAL_DATE_TIME_FORMATTER_CLASS
public static final int JAVA_VERSION
public static <T> T[] array(T... content)
T
- content
- public static Set<Class<?>> findAllCommonSuperInterfaces(Class<?> a, Class<?> b)
a
- b
- public static Method findMethodByName(Class<?> clazz, String name)
clazz
- name
- public static List<Class<?>> findAllSuperInterfaces(Class<?> a)
a
- public static boolean hasReturnType(Method method)
method
- public static boolean hasParameters(Method method)
method
- public static List<Object> array2ObjectList(Object array)
array
- public static boolean isDefaultMethod(Method m)
m
- public static Map<String,Integer> getMethodParameterIndexes(Method m)
m
- public static <T> Constructor<T> getCallableConstructorForParams(Class<T> type, Class<?>... params)
Class.getConstructor(...)
, but does not require parameter equality and does not throw
exceptions.type
- params
- public static Method getCallableFactoryForParams(Class<?> type, Class<?>... params)
type
- params
- public static boolean mayProvideParameterNames()
public static Object unwrap(Class<?> type, Object object) throws Exception
type
- object
- Exception
- may be thrown by given objects methodpublic static Class<?> getParameterType(Type type)
type
- public static boolean isOptional(Type type)
type
- public static boolean isRawType(Type type)
type
- public static Object createOptional(Object value)
value
- public static Object invokeDefaultMethod(Method method, Object[] args, Object proxy) throws Throwable
method
- args
- proxy
- Throwable
- (whatever the invoked method throws)public static void throwThrowable(Class<?> throwableType, Object[] args, Throwable optionalCause) throws Throwable
throwableType
- type of throwable to be thrownargs
- for the throwable constructionoptionalCause
- cause to be set, may be nullThrowable
public static Class<?> getCallerClass(int level)
level
- public static Class<?> getDirectCallerClass()
public static boolean isStreamClass(Class<?> returnType)
returnType
- Copyright © 2012-12-21-2022. All Rights Reserved.