public final class ReflectionUtil
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
ReflectionUtil.ConstructorNotFound |
static class |
ReflectionUtil.MultipleAnnotatedConstructorsFound |
static class |
ReflectionUtil.MultipleConstructorsFound |
| Modifier and Type | Method and Description |
|---|---|
static java.util.List<javax.lang.model.element.ExecutableElement> |
filterAnnotatedConstructors(java.util.List<javax.lang.model.element.ExecutableElement> constructorElements,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass) |
static <A extends java.lang.annotation.Annotation> |
findAllAnnotations(java.lang.Class<?> clazz,
java.lang.Class<A> annotationType)
Collects all instances of a specific annotation type from a class, its superclass hierarchy, and implemented interfaces.
|
static java.util.Optional<java.lang.reflect.Method> |
findFirstAnnotatedMethod(java.lang.Class<?> source,
java.lang.Class<? extends java.lang.annotation.Annotation> annotation) |
static java.util.Optional<java.lang.reflect.Method> |
findFirstMethodByName(java.lang.Class<?> source,
java.lang.String methodName) |
static java.lang.Class<?>[] |
getActualTypeArguments(java.lang.Class<?> clazz)
Retrieves the actual type arguments used in a class's generic superclass as Class objects.
|
static java.util.List<java.lang.reflect.Constructor<?>> |
getAnnotatedConstructors(java.lang.Class<?> source,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass) |
static java.lang.reflect.Constructor<?> |
getConstructorFromParameterTypeNames(java.lang.Class<?> targetClass,
java.util.List<java.lang.String> parameterTypeNames)
Finds a constructor that matches the provided parameter type names.
|
static java.util.List<java.lang.reflect.Constructor<?>> |
getConstructors(java.lang.Class<?> source) |
static java.util.List<javax.lang.model.element.ExecutableElement> |
getConstructors(javax.lang.model.element.TypeElement typeElement) |
static java.lang.reflect.Constructor<?> |
getConstructorWithAnnotationPreference(java.lang.Class<?> source,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass) |
static javax.lang.model.element.ExecutableElement |
getConstructorWithAnnotationPreference(javax.lang.model.element.TypeElement typeElement,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass) |
static java.lang.reflect.Method |
getDeclaredMethodFromParameterTypeNames(java.lang.Class<?> targetClass,
java.lang.String methodName,
java.util.List<java.lang.String> parameterTypeNames)
Finds a declared method by name using your 3-step heuristic:
1) Filter declared methods by name.
|
static java.lang.reflect.Constructor<?> |
getDefaultConstructor(java.lang.Class<?> targetClass)
Finds the default constructor of a class
|
static java.util.List<java.lang.Class<?>> |
getParameters(java.lang.reflect.Executable executable) |
static java.util.List<java.lang.String> |
getParametersTypesQualifiedNames(javax.lang.model.element.ExecutableElement element) |
static java.util.Collection<java.lang.Class<?>> |
loadAnnotatedClassesFromPackage(java.lang.String packagePath,
java.lang.Class<? extends java.lang.annotation.Annotation>... annotations) |
static java.lang.reflect.Type[] |
resolveTypeArguments(java.lang.Class<?> concreteClass,
java.lang.Class<?> targetGeneric)
Resolves the type arguments that
concreteClass supplies for the generic superclass or interface targetGeneric. |
static java.lang.reflect.Type[] |
resolveTypeArguments(java.lang.Object instance,
java.lang.Class<?> targetGeneric)
Convenience overload: uses the runtime class of the given instance.
|
static java.lang.Class<?>[] |
resolveTypeArgumentsAsClasses(java.lang.Class<?> concreteClass,
java.lang.Class<?> targetGeneric)
Variant returning raw classes (defaults to Object.class if resolution fails).
|
public static java.lang.Class<?>[] getActualTypeArguments(java.lang.Class<?> clazz)
clazz - The class to analyze for generic type argumentsjava.lang.IllegalStateException - If no parameterized superclass can be found in the hierarchyjava.lang.ClassCastException - If any type argument is not a Class (e.g., type variable, wildcard)public static java.lang.reflect.Type[] resolveTypeArguments(java.lang.Class<?> concreteClass,
java.lang.Class<?> targetGeneric)
concreteClass supplies for the generic superclass or interface targetGeneric.java.lang.IllegalArgumentException - if targetGeneric is not in the hierarchy of concreteClass.public static java.lang.reflect.Type[] resolveTypeArguments(java.lang.Object instance,
java.lang.Class<?> targetGeneric)
public static java.lang.Class<?>[] resolveTypeArgumentsAsClasses(java.lang.Class<?> concreteClass,
java.lang.Class<?> targetGeneric)
public static java.util.Optional<java.lang.reflect.Method> findFirstAnnotatedMethod(java.lang.Class<?> source,
java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
public static java.util.Optional<java.lang.reflect.Method> findFirstMethodByName(java.lang.Class<?> source,
java.lang.String methodName)
public static java.util.Collection<java.lang.Class<?>> loadAnnotatedClassesFromPackage(java.lang.String packagePath,
java.lang.Class<? extends java.lang.annotation.Annotation>... annotations)
public static java.util.List<java.lang.Class<?>> getParameters(java.lang.reflect.Executable executable)
public static java.util.List<java.lang.reflect.Constructor<?>> getAnnotatedConstructors(java.lang.Class<?> source,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
public static java.lang.reflect.Constructor<?> getConstructorWithAnnotationPreference(java.lang.Class<?> source,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
public static <A extends java.lang.annotation.Annotation> java.util.List<A> findAllAnnotations(java.lang.Class<?> clazz,
java.lang.Class<A> annotationType)
A - The annotation type to collectclazz - The class to start the search fromannotationType - The class object representing the annotation type to collectjava.lang.NullPointerException - if clazz or annotationType is nullpublic static java.util.List<java.lang.reflect.Constructor<?>> getConstructors(java.lang.Class<?> source)
public static javax.lang.model.element.ExecutableElement getConstructorWithAnnotationPreference(javax.lang.model.element.TypeElement typeElement,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
public static java.util.List<javax.lang.model.element.ExecutableElement> filterAnnotatedConstructors(java.util.List<javax.lang.model.element.ExecutableElement> constructorElements,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
public static java.util.List<javax.lang.model.element.ExecutableElement> getConstructors(javax.lang.model.element.TypeElement typeElement)
public static java.util.List<java.lang.String> getParametersTypesQualifiedNames(javax.lang.model.element.ExecutableElement element)
public static java.lang.reflect.Constructor<?> getDefaultConstructor(java.lang.Class<?> targetClass)
targetClass - the class where the constructor is declaredpublic static java.lang.reflect.Constructor<?> getConstructorFromParameterTypeNames(java.lang.Class<?> targetClass,
java.util.List<java.lang.String> parameterTypeNames)
targetClass - the class where the constructor is declaredparameterTypeNames - list of parameter type names (e.g., "java.lang.String", "int[]")public static java.lang.reflect.Method getDeclaredMethodFromParameterTypeNames(java.lang.Class<?> targetClass,
java.lang.String methodName,
java.util.List<java.lang.String> parameterTypeNames)