Class ReflectionHelper
java.lang.Object
com.google.gson.internal.reflect.ReflectionHelper
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringconstructorToString(Constructor<?> constructor) Creates a string representation for a constructor.static 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 booleanisAnonymousOrNonStaticLocal(Class<?> clazz) Returns whether the class is anonymous or a non-static local class.static booleanIf records are supported on the JVM, this is equivalent to a call to Class.isRecord()static booleanstatic voidmakeAccessible(AccessibleObject object) Internal implementation of making anAccessibleObjectaccessible.static StringtryMakeAccessible(Constructor<?> constructor) Tries making the constructor accessible, returning an exception message if this fails.
-
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
-
constructorToString
Creates a string representation for a constructor. E.g.:java.lang.String(char[], int, int) -
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;
nullif successful, non-nullif unsuccessful
-
isRecord
If records are supported on the JVM, this is equivalent to a call to Class.isRecord() -
getRecordComponentNames
-
getAccessor
-
getCanonicalRecordConstructor
-
createExceptionForUnexpectedIllegalAccess
public static RuntimeException createExceptionForUnexpectedIllegalAccess(IllegalAccessException exception)
-