Class ReflectionUtils
java.lang.Object
io.fluxcapacitor.common.reflection.ReflectionUtils
Utility class for high-performance reflection-based operations across the Flux platform.
This class is intended for internal use only. It provides a wide range of methods for accessing and manipulating object members via reflection, including:
- Resolving annotated fields and methods (with support for meta-annotations)
- Accessing nested property paths via getters and setters (e.g.,
"user/address/street"
) - Efficient member access using
DefaultMemberInvoker
, which leveragesLambdaMetafactory
for near-native invocation performance - Generic type resolution, including collection element types and supertype inference
- Annotation hierarchy traversal and support for Kotlin nullability reflection (if available)
- Utilities for determining override relationships, class hierarchies, and bean property metadata
- Robust handling of
Class
loading and safe access to field/method/property values
Performance Considerations
This class uses extensive caching and memoization to avoid redundant reflective operations at runtime. All public methods are safe to use in high-performance contexts such as annotation scanning, handler dispatching, and JSON schema validation.Modular Use
If Flux adopts JPMS (Project Jigsaw) in the future, this utility would likely be placed in an internal module and not exported to consumers, to preserve encapsulation and forward compatibility.- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Class
<?> static <T> T
asInstance
(Object classOrInstance) static boolean
classExists
(String className) static Class
<?> classForName
(String type) static Class
<?> classForName
(String type, Class<?> defaultClass) static <T> T
convertAnnotation
(Annotation annotation, Class<? extends T> returnType) static <V> V
copyFields
(V source, V target) static boolean
declaresField
(Class<?> target, String fieldName) determineCommonAncestors
(Collection<?> elements) static <T extends AccessibleObject>
TensureAccessible
(T member) getAllMethods
(Class<?> type) getAnnotatedFields
(Class<?> target, Class<? extends Annotation> annotation) getAnnotatedFields
(Object target, Class<? extends Annotation> annotation) getAnnotatedMethods
(Class<?> target, Class<? extends Annotation> annotation) getAnnotatedMethods
(Object target, Class<? extends Annotation> annotation) static List
<? extends AccessibleObject> getAnnotatedProperties
(Class<?> target, Class<? extends Annotation> annotation) static Optional
<? extends AccessibleObject> getAnnotatedProperty
(Class<?> target, Class<? extends Annotation> annotation) static Optional
<? extends AccessibleObject> getAnnotatedProperty
(Object target, Class<? extends Annotation> annotation) getAnnotatedPropertyValue
(Object target, Class<? extends Annotation> annotation) static Collection
<Object> getAnnotatedPropertyValues
(Object target, Class<? extends Annotation> annotation) static <A extends Annotation>
Optional<A> getAnnotation
(AnnotatedElement m, Class<A> a) static <T> Optional
<T> getAnnotationAs
(Annotation annotation, Class<? extends Annotation> targetAnnotation, Class<? extends T> returnType) static <T> Optional
<T> getAnnotationAs
(Class<?> target, Class<? extends Annotation> annotationType, Class<T> returnType) static <T> Optional
<T> getAnnotationAs
(AnnotatedElement member, Class<? extends Annotation> annotationType, Class<? extends T> returnType) static Class
<?> getCollectionElementType
(AccessibleObject fieldOrMethod) getCollectionElementType
(Type parameterizedType) static Class
<?> getEnclosingClass
(AccessibleObject fieldOrMethod) static <A extends Annotation>
Optional<A> getFieldAnnotation
(Field f, Class<? extends Annotation> a) static <T> Optional
<T> getFieldValue
(String fieldName, Object target) static <T extends Type>
TgetFirstTypeArgument
(Type genericType) static Type
getGenericPropertyType
(AccessibleObject fieldOrMethod) static Type
getGenericType
(Class<?> candidate, Class<?> wantedClass) static <A extends Annotation>
Optional<A> getMemberAnnotation
(Class<?> type, String memberName, Class<? extends Annotation> a) static <A extends Annotation>
Optional<A> getMethodAnnotation
(Executable m, Class<? extends Annotation> a) static <A extends Annotation>
List<A> getMethodAnnotations
(Executable m, Class<? extends Annotation> a) getMethodOverrideHierarchy
(Method method) static String
getName
(AccessibleObject fieldOrMethod) static <A extends Annotation>
Optional<A> getPackageAnnotation
(Package p, Class<A> annotationType) static Collection
<? extends Annotation> static Collection
<? extends Annotation> getPackageAnnotations
(Package p, boolean recursive) static int
getParameterIndex
(Parameter parameter) getParameterOverrideHierarchy
(Parameter parameter) static <T> Optional
<T> getPropertyAnnotation
(String propertyPath, Object target) static String
getPropertyName
(AccessibleObject property) static Class
<?> getPropertyType
(AccessibleObject fieldOrMethod) static String
getSimpleName
(Class<?> c) static String
static String
getSimpleName
(String fullyQualifiedName) static <A extends Annotation>
AgetTypeAnnotation
(Class<?> type, Class<? extends Annotation> annotationType) static Collection
<? extends Annotation> getTypeAnnotations
(Class<?> type) static <T extends Type>
TgetTypeArgument
(Type genericType, int index) getTypeArguments
(Type genericType) static Object
getValue
(AccessibleObject fieldOrMethod, Object target) static Object
getValue
(AccessibleObject fieldOrMethod, Object target, boolean forceAccess) static boolean
has
(Class<? extends Annotation> annotationClass, Method method) static boolean
has
(Class<? extends Annotation> annotationClass, Parameter parameter) static boolean
hasProperty
(String propertyPath, Object target) static Class
<?> static boolean
isAnnotationPresent
(Class<?> type, Class<? extends Annotation> annotationType) static boolean
isAnnotationPresent
(Parameter parameter, Class<? extends Annotation> annotationType) static boolean
static boolean
isLeafValue
(Object value) static boolean
isMethodAnnotationPresent
(Class<?> target, Class<? extends Annotation> annotation) static boolean
isNullable
(Parameter parameter) static boolean
isOrHas
(Annotation annotation, Class<? extends Annotation> annotationType) static boolean
isStatic
(Executable method) static <T> Optional
<T> readProperty
(String propertyPath, Object target) static void
static void
static void
writeProperty
(String propertyPath, Object target, Object value)
-
Constructor Details
-
ReflectionUtils
public ReflectionUtils()
-
-
Method Details
-
getMethodOverrideHierarchy
-
getParameterOverrideHierarchy
-
isKotlinReflectionSupported
public static boolean isKotlinReflectionSupported() -
ifClass
-
asClass
-
getAllMethods
-
getMethod
-
getAnnotatedProperties
public static List<? extends AccessibleObject> getAnnotatedProperties(Class<?> target, Class<? extends Annotation> annotation) -
getAnnotatedProperty
public static Optional<? extends AccessibleObject> getAnnotatedProperty(Object target, Class<? extends Annotation> annotation) -
getAnnotatedProperty
public static Optional<? extends AccessibleObject> getAnnotatedProperty(Class<?> target, Class<? extends Annotation> annotation) -
getAnnotatedPropertyValue
public static Optional<Object> getAnnotatedPropertyValue(Object target, Class<? extends Annotation> annotation) -
getAnnotatedPropertyValues
public static Collection<Object> getAnnotatedPropertyValues(Object target, Class<? extends Annotation> annotation) -
getPropertyName
-
getAnnotatedMethods
public static List<Method> getAnnotatedMethods(Class<?> target, Class<? extends Annotation> annotation) -
getAnnotatedMethods
public static List<Method> getAnnotatedMethods(Object target, Class<? extends Annotation> annotation) -
isMethodAnnotationPresent
public static boolean isMethodAnnotationPresent(Class<?> target, Class<? extends Annotation> annotation) -
getAnnotatedFields
public static List<Field> getAnnotatedFields(Class<?> target, Class<? extends Annotation> annotation) -
getAnnotatedFields
-
isAnnotationPresent
public static boolean isAnnotationPresent(Class<?> type, Class<? extends Annotation> annotationType) -
getTypeAnnotation
public static <A extends Annotation> A getTypeAnnotation(Class<?> type, Class<? extends Annotation> annotationType) -
getTypeAnnotations
-
getPackageAnnotation
public static <A extends Annotation> Optional<A> getPackageAnnotation(Package p, Class<A> annotationType) -
getPackageAnnotations
-
getPackageAnnotations
-
readProperty
-
getTypeArguments
-
getFirstTypeArgument
-
getTypeArgument
-
getPropertyAnnotation
-
hasProperty
-
getFieldValue
-
getValue
-
getValue
-
getName
-
getEnclosingClass
-
getPropertyType
-
getGenericPropertyType
-
writeProperty
-
isOrHas
-
getField
-
getCallerClass
-
isNullable
-
asInstance
-
getParameterIndex
-
determineCommonAncestors
-
getPackageAndParentPackages
-
getMemberAnnotation
public static <A extends Annotation> Optional<A> getMemberAnnotation(Class<?> type, String memberName, Class<? extends Annotation> a) -
isStatic
-
isLeafValue
-
isAnnotationPresent
public static boolean isAnnotationPresent(Parameter parameter, Class<? extends Annotation> annotationType) -
getGenericType
-
getCollectionElementType
-
getCollectionElementType
-
declaresField
-
setField
-
setField
-
ensureAccessible
-
getAnnotation
-
getAnnotationAs
public static <T> Optional<T> getAnnotationAs(Class<?> target, Class<? extends Annotation> annotationType, Class<T> returnType) -
getAnnotationAs
public static <T> Optional<T> getAnnotationAs(AnnotatedElement member, Class<? extends Annotation> annotationType, Class<? extends T> returnType) -
getAnnotationAs
public static <T> Optional<T> getAnnotationAs(Annotation annotation, Class<? extends Annotation> targetAnnotation, Class<? extends T> returnType) -
convertAnnotation
-
has
-
has
-
getFieldAnnotation
public static <A extends Annotation> Optional<A> getFieldAnnotation(Field f, Class<? extends Annotation> a) -
getMethodAnnotation
public static <A extends Annotation> Optional<A> getMethodAnnotation(Executable m, Class<? extends Annotation> a) -
getMethodAnnotations
public static <A extends Annotation> List<A> getMethodAnnotations(Executable m, Class<? extends Annotation> a) -
copyFields
public static <V> V copyFields(V source, V target) -
classForName
-
classForName
-
classExists
-
getSimpleName
-
getSimpleName
-
getSimpleName
-