Class ReflectionHelper


  • public class ReflectionHelper
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ReflectionHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static void appendExecutableParameters​(java.lang.reflect.AccessibleObject executable, java.lang.StringBuilder stringBuilder)  
      static java.lang.String constructorToString​(java.lang.reflect.Constructor<?> constructor)
      Creates a string representation for a constructor.
      private static java.lang.RuntimeException createExceptionForRecordReflectionException​(java.lang.ReflectiveOperationException exception)  
      static java.lang.RuntimeException createExceptionForUnexpectedIllegalAccess​(java.lang.IllegalAccessException exception)  
      static java.lang.String fieldToString​(java.lang.reflect.Field field)
      Creates a string representation for a field, omitting modifiers and the field type.
      static java.lang.String getAccessibleObjectDescription​(java.lang.reflect.AccessibleObject object, boolean uppercaseFirstLetter)
      Returns a short string describing the AccessibleObject in a human-readable way.
      static java.lang.reflect.Method getAccessor​(java.lang.Class<?> raw, java.lang.reflect.Field field)
      Looks up the record accessor method that corresponds to the given record field
      static <T> java.lang.reflect.Constructor<T> getCanonicalRecordConstructor​(java.lang.Class<T> raw)  
      static java.lang.String[] getRecordComponentNames​(java.lang.Class<?> raw)  
      static boolean isRecord​(java.lang.Class<?> raw)
      If records are supported on the JVM, this is equivalent to a call to Class.isRecord()
      static void makeAccessible​(java.lang.reflect.AccessibleObject object)
      Internal implementation of making an AccessibleObject accessible.
      static java.lang.String tryMakeAccessible​(java.lang.reflect.Constructor<?> constructor)
      Tries making the constructor accessible, returning an exception message if this fails.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ReflectionHelper

        private ReflectionHelper()
    • Method Detail

      • makeAccessible

        public static void makeAccessible​(java.lang.reflect.AccessibleObject object)
                                   throws JsonIOException
        Internal implementation of making an AccessibleObject accessible.
        Parameters:
        object - the object that AccessibleObject.setAccessible(boolean) should be called on.
        Throws:
        JsonIOException - if making the object accessible fails
      • getAccessibleObjectDescription

        public static java.lang.String getAccessibleObjectDescription​(java.lang.reflect.AccessibleObject object,
                                                                      boolean uppercaseFirstLetter)
        Returns a short string describing the AccessibleObject in a human-readable way. The result is normally shorter than Object.toString() because it omits modifiers (e.g. final) and uses simple names for constructor and method parameter types.
        Parameters:
        object - object to describe
        uppercaseFirstLetter - whether the first letter of the description should be uppercased
      • fieldToString

        public static java.lang.String fieldToString​(java.lang.reflect.Field field)
        Creates a string representation for a field, omitting modifiers and the field type.
      • constructorToString

        public static java.lang.String constructorToString​(java.lang.reflect.Constructor<?> constructor)
        Creates a string representation for a constructor. E.g.: java.lang.String(char[], int, int)
      • appendExecutableParameters

        private static void appendExecutableParameters​(java.lang.reflect.AccessibleObject executable,
                                                       java.lang.StringBuilder stringBuilder)
      • tryMakeAccessible

        public static java.lang.String tryMakeAccessible​(java.lang.reflect.Constructor<?> constructor)
        Tries making the constructor accessible, returning an exception message if this fails.
        Parameters:
        constructor - constructor to make accessible
        Returns:
        exception message; null if successful, non-null if unsuccessful
      • isRecord

        public static boolean isRecord​(java.lang.Class<?> raw)
        If records are supported on the JVM, this is equivalent to a call to Class.isRecord()
      • getRecordComponentNames

        public static java.lang.String[] getRecordComponentNames​(java.lang.Class<?> raw)
      • getAccessor

        public static java.lang.reflect.Method getAccessor​(java.lang.Class<?> raw,
                                                           java.lang.reflect.Field field)
        Looks up the record accessor method that corresponds to the given record field
      • getCanonicalRecordConstructor

        public static <T> java.lang.reflect.Constructor<T> getCanonicalRecordConstructor​(java.lang.Class<T> raw)
      • createExceptionForUnexpectedIllegalAccess

        public static java.lang.RuntimeException createExceptionForUnexpectedIllegalAccess​(java.lang.IllegalAccessException exception)
      • createExceptionForRecordReflectionException

        private static java.lang.RuntimeException createExceptionForRecordReflectionException​(java.lang.ReflectiveOperationException exception)