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 classInternal abstraction over reflection when Records are supported.private static classInstance used when records are not supportedprivate static class -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidappendExecutableParameters(AccessibleObject executable, StringBuilder stringBuilder) static StringconstructorToString(Constructor<?> constructor) Creates a string representation for a constructor.private static RuntimeExceptionstatic RuntimeExceptionstatic StringfieldToString(Field field) Creates a string representation for a field, omitting modifiers and the field type.static StringgetAccessibleObjectDescription(AccessibleObject object, boolean uppercaseFirstLetter) Returns a short string describing theAccessibleObjectin a human-readable way.static MethodgetAccessor(Class<?> raw, Field field) Looks up the record accessor method that corresponds to the given record fieldstatic <T> Constructor<T> getCanonicalRecordConstructor(Class<T> raw) static String[]getRecordComponentNames(Class<?> raw) static booleanIf records are supported on the JVM, this is equivalent to a call to Class.isRecord()static voidmakeAccessible(AccessibleObject object) Internal implementation of making anAccessibleObjectaccessible.static StringtryMakeAccessible(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
-
makeAccessible
Internal implementation of making anAccessibleObjectaccessible.- 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 theAccessibleObjectin 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) -
tryMakeAccessible
Tries making the constructor accessible, returning an exception message if this fails.- Parameters:
constructor- constructor to make accessible- Returns:
- exception message;
nullif successful, non-nullif 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)
-