@Internal public class ReflectionUtils extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.lang.Class[] |
EMPTY_CLASS_ARRAY
Constant for empty class array.
|
| Constructor and Description |
|---|
ReflectionUtils() |
| Modifier and Type | Method and Description |
|---|---|
static <T> java.util.Optional<java.lang.reflect.Constructor<T>> |
findConstructor(java.lang.Class<T> type,
java.lang.Class... argTypes)
Obtains a declared method.
|
static java.util.Optional<java.lang.reflect.Field> |
findDeclaredField(java.lang.Class type,
java.lang.String name) |
static java.util.Optional<java.lang.reflect.Field> |
findField(java.lang.Class type,
java.lang.String name)
Finds a field in the type or super type.
|
static java.util.Optional<java.lang.reflect.Method> |
findMethod(java.lang.Class type,
java.lang.String name,
java.lang.Class... argumentTypes)
Finds a method on the given type for the given name.
|
static java.util.stream.Stream<java.lang.reflect.Method> |
findMethodsByName(java.lang.Class type,
java.lang.String name)
Finds a method on the given type for the given name.
|
static java.util.Set<java.lang.Class> |
getAllInterfaces(java.lang.Class<?> aClass) |
static java.util.Optional<java.lang.reflect.Method> |
getDeclaredMethod(java.lang.Class type,
java.lang.String methodName,
java.lang.Class... argTypes)
Obtains a declared method.
|
static java.util.Optional<java.lang.reflect.Method> |
getMethod(java.lang.Class type,
java.lang.String methodName,
java.lang.Class... argTypes)
Obtains a method.
|
static java.lang.Class |
getPrimitiveType(java.lang.Class wrapperType)
Obtain the primitive type for the given wrapper type.
|
static java.lang.reflect.Field |
getRequiredField(java.lang.Class type,
java.lang.String name)
Finds a field on the given type for the given name.
|
static <T> java.lang.reflect.Constructor<T> |
getRequiredInternalConstructor(java.lang.Class<T> type,
java.lang.Class... argumentTypes)
Finds an internal constructor defined by the Micronaut API and throws a
NoSuchMethodError if it doesn't exist. |
static java.lang.reflect.Method |
getRequiredInternalMethod(java.lang.Class type,
java.lang.String name,
java.lang.Class... argumentTypes)
Finds an internal method defined by the Micronaut API and throws a
NoSuchMethodError if it doesn't exist. |
static java.lang.reflect.Method |
getRequiredMethod(java.lang.Class type,
java.lang.String name,
java.lang.Class... argumentTypes)
Finds a method on the given type for the given name.
|
static java.lang.Class |
getWrapperType(java.lang.Class primitiveType)
Obtain the wrapper type for the given primitive.
|
static <R,T> R |
invokeMethod(T instance,
java.lang.reflect.Method method,
java.lang.Object... arguments)
Invokes a method.
|
static boolean |
isSetter(java.lang.String name,
java.lang.Class[] args)
Is the method a setter.
|
static java.lang.NoSuchMethodError |
newNoSuchMethodError(java.lang.Class declaringType,
java.lang.String name,
java.lang.Class[] argumentTypes) |
protected static java.util.Set<java.lang.Class> |
populateInterfaces(java.lang.Class<?> aClass,
java.util.Set<java.lang.Class> interfaces) |
static void |
setFieldIfPossible(java.lang.Class type,
java.lang.String name,
java.lang.Object value)
Deprecated.
This method uses reflection. Do not use.
|
public static final java.lang.Class[] EMPTY_CLASS_ARRAY
public static boolean isSetter(java.lang.String name,
java.lang.Class[] args)
name - The method nameargs - The argumentspublic static java.lang.Class getWrapperType(java.lang.Class primitiveType)
primitiveType - The primitive typepublic static java.lang.Class getPrimitiveType(java.lang.Class wrapperType)
wrapperType - The primitive typepublic static java.util.Optional<java.lang.reflect.Method> getDeclaredMethod(java.lang.Class type,
java.lang.String methodName,
java.lang.Class... argTypes)
type - The typemethodName - The method nameargTypes - The argument typespublic static java.util.Optional<java.lang.reflect.Method> getMethod(java.lang.Class type,
java.lang.String methodName,
java.lang.Class... argTypes)
type - The typemethodName - The method nameargTypes - The argument typesMethodpublic static <T> java.util.Optional<java.lang.reflect.Constructor<T>> findConstructor(java.lang.Class<T> type,
java.lang.Class... argTypes)
T - The generic typetype - The typeargTypes - The argument typespublic static <R,T> R invokeMethod(T instance,
java.lang.reflect.Method method,
java.lang.Object... arguments)
R - The return typeT - The instance typeinstance - The instancemethod - The methodarguments - The arguments@Internal public static java.util.Optional<java.lang.reflect.Method> findMethod(java.lang.Class type, java.lang.String name, java.lang.Class... argumentTypes)
type - The typename - The nameargumentTypes - The argument typesOptional contains the method or empty@Internal public static java.lang.reflect.Method getRequiredMethod(java.lang.Class type, java.lang.String name, java.lang.Class... argumentTypes)
type - The typename - The nameargumentTypes - The argument typesOptional contains the method or empty@Internal public static java.lang.reflect.Method getRequiredInternalMethod(java.lang.Class type, java.lang.String name, java.lang.Class... argumentTypes)
NoSuchMethodError if it doesn't exist.type - The typename - The nameargumentTypes - The argument typesOptional contains the method or emptyjava.lang.NoSuchMethodError - If the method doesn't exist@Internal public static <T> java.lang.reflect.Constructor<T> getRequiredInternalConstructor(java.lang.Class<T> type, java.lang.Class... argumentTypes)
NoSuchMethodError if it doesn't exist.T - The typetype - The typeargumentTypes - The argument typesOptional contains the method or emptyjava.lang.NoSuchMethodError - If the method doesn't exist@Internal public static java.lang.reflect.Field getRequiredField(java.lang.Class type, java.lang.String name)
type - The typename - The nameOptional contains the method or empty@Internal public static java.util.Optional<java.lang.reflect.Field> findField(java.lang.Class type, java.lang.String name)
type - The typename - The field nameOptional of field@Deprecated
public static void setFieldIfPossible(java.lang.Class type,
java.lang.String name,
java.lang.Object value)
type - The typename - The field namevalue - The valuepublic static java.util.stream.Stream<java.lang.reflect.Method> findMethodsByName(java.lang.Class type,
java.lang.String name)
type - The typename - The nameOptional contains the method or emptypublic static java.util.Optional<java.lang.reflect.Field> findDeclaredField(java.lang.Class type,
java.lang.String name)
type - The typename - The field namepublic static java.util.Set<java.lang.Class> getAllInterfaces(java.lang.Class<?> aClass)
aClass - A classprotected static java.util.Set<java.lang.Class> populateInterfaces(java.lang.Class<?> aClass,
java.util.Set<java.lang.Class> interfaces)
aClass - A classinterfaces - The interfacespublic static java.lang.NoSuchMethodError newNoSuchMethodError(java.lang.Class declaringType,
java.lang.String name,
java.lang.Class[] argumentTypes)
declaringType - The declaring typename - The method nameargumentTypes - The argument typesNoSuchMethodError