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