Package com.google.gson.internal.reflect
Class ReflectionHelper
- java.lang.Object
-
- com.google.gson.internal.reflect.ReflectionHelper
-
public class ReflectionHelper extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classReflectionHelper.RecordHelperInternal abstraction over reflection when Records are supported.private static classReflectionHelper.RecordNotSupportedHelperInstance used when records are not supportedprivate static classReflectionHelper.RecordSupportedHelper
-
Field Summary
Fields Modifier and Type Field Description private static ReflectionHelper.RecordHelperRECORD_HELPER
-
Constructor Summary
Constructors Modifier Constructor Description privateReflectionHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static voidappendExecutableParameters(java.lang.reflect.AccessibleObject executable, java.lang.StringBuilder stringBuilder)static java.lang.StringconstructorToString(java.lang.reflect.Constructor<?> constructor)Creates a string representation for a constructor.private static java.lang.RuntimeExceptioncreateExceptionForRecordReflectionException(java.lang.ReflectiveOperationException exception)static java.lang.RuntimeExceptioncreateExceptionForUnexpectedIllegalAccess(java.lang.IllegalAccessException exception)static java.lang.StringfieldToString(java.lang.reflect.Field field)Creates a string representation for a field, omitting modifiers and the field type.static java.lang.StringgetAccessibleObjectDescription(java.lang.reflect.AccessibleObject object, boolean uppercaseFirstLetter)Returns a short string describing theAccessibleObjectin a human-readable way.static java.lang.reflect.MethodgetAccessor(java.lang.Class<?> raw, java.lang.reflect.Field field)Looks up the record accessor method that corresponds to the given record fieldstatic <T> java.lang.reflect.Constructor<T>getCanonicalRecordConstructor(java.lang.Class<T> raw)private static java.lang.StringgetInaccessibleTroubleshootingSuffix(java.lang.Exception e)static java.lang.String[]getRecordComponentNames(java.lang.Class<?> raw)static booleanisAnonymousOrNonStaticLocal(java.lang.Class<?> clazz)Returns whether the class is anonymous or a non-static local class.static booleanisRecord(java.lang.Class<?> raw)If records are supported on the JVM, this is equivalent to a call to Class.isRecord()static booleanisStatic(java.lang.Class<?> clazz)static voidmakeAccessible(java.lang.reflect.AccessibleObject object)Internal implementation of making anAccessibleObjectaccessible.static java.lang.StringtryMakeAccessible(java.lang.reflect.Constructor<?> constructor)Tries making the constructor accessible, returning an exception message if this fails.
-
-
-
Field Detail
-
RECORD_HELPER
private static final ReflectionHelper.RecordHelper RECORD_HELPER
-
-
Method Detail
-
getInaccessibleTroubleshootingSuffix
private static java.lang.String getInaccessibleTroubleshootingSuffix(java.lang.Exception e)
-
makeAccessible
public static void makeAccessible(java.lang.reflect.AccessibleObject object) throws JsonIOExceptionInternal 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 java.lang.String getAccessibleObjectDescription(java.lang.reflect.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
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)
-
isStatic
public static boolean isStatic(java.lang.Class<?> clazz)
-
isAnonymousOrNonStaticLocal
public static boolean isAnonymousOrNonStaticLocal(java.lang.Class<?> clazz)
Returns whether the class is anonymous or a non-static local class.
-
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;
nullif successful, non-nullif 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)
-
-