Package com.google.gson.internal.reflect
Class ReflectionHelper
java.lang.Object
com.google.gson.internal.reflect.ReflectionHelper
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Internal abstraction over reflection when Records are supported.private static class
Instance used when records are not supportedprivate static class
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
appendExecutableParameters
(AccessibleObject executable, StringBuilder stringBuilder) static String
constructorToString
(Constructor<?> constructor) Creates a string representation for a constructor.private static RuntimeException
static RuntimeException
static String
fieldToString
(Field field) Creates a string representation for a field, omitting modifiers and the field type.static String
getAccessibleObjectDescription
(AccessibleObject object, boolean uppercaseFirstLetter) Returns a short string describing theAccessibleObject
in a human-readable way.static Method
getAccessor
(Class<?> raw, Field field) Looks up the record accessor method that corresponds to the given record fieldstatic <T> Constructor
<T> getCanonicalRecordConstructor
(Class<T> raw) private static String
static String[]
getRecordComponentNames
(Class<?> raw) static boolean
isAnonymousOrNonStaticLocal
(Class<?> clazz) Returns whether the class is anonymous or a non-static local class.static boolean
If records are supported on the JVM, this is equivalent to a call to Class.isRecord()static boolean
static void
makeAccessible
(AccessibleObject object) Internal implementation of making anAccessibleObject
accessible.static String
tryMakeAccessible
(Constructor<?> constructor) Tries making the constructor accessible, returning an exception message if this fails.
-
Field Details
-
RECORD_HELPER
-
-
Constructor Details
-
ReflectionHelper
private ReflectionHelper()
-
-
Method Details
-
getInaccessibleTroubleshootingSuffix
-
makeAccessible
Internal implementation of making anAccessibleObject
accessible.- Parameters:
object
- the object thatAccessibleObject.setAccessible(boolean)
should be called on.- Throws:
JsonIOException
- if making the object accessible fails
-
getAccessibleObjectDescription
public static String getAccessibleObjectDescription(AccessibleObject object, boolean uppercaseFirstLetter) Returns a short string describing theAccessibleObject
in a human-readable way. The result is normally shorter thanObject.toString()
because it omits modifiers (e.g.final
) and uses simple names for constructor and method parameter types.- Parameters:
object
- object to describeuppercaseFirstLetter
- whether the first letter of the description should be uppercased
-
fieldToString
Creates a string representation for a field, omitting modifiers and the field type. -
constructorToString
Creates a string representation for a constructor. E.g.:java.lang.String(char[], int, int)
-
appendExecutableParameters
private static void appendExecutableParameters(AccessibleObject executable, StringBuilder stringBuilder) -
isStatic
-
isAnonymousOrNonStaticLocal
Returns whether the class is anonymous or a non-static local class. -
tryMakeAccessible
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
If records are supported on the JVM, this is equivalent to a call to Class.isRecord() -
getRecordComponentNames
-
getAccessor
Looks up the record accessor method that corresponds to the given record field -
getCanonicalRecordConstructor
-
createExceptionForUnexpectedIllegalAccess
public static RuntimeException createExceptionForUnexpectedIllegalAccess(IllegalAccessException exception) -
createExceptionForRecordReflectionException
private static RuntimeException createExceptionForRecordReflectionException(ReflectiveOperationException exception)
-