Top Inners Fields Constructors Methods
com.google.gson.internal.reflect

public Class ReflectionHelper

extends Object
Class Inheritance
Imports
com.google.gson.JsonIOException, com.google.gson.internal.GsonBuildConfig, .TroubleshootingGuide, java.lang.reflect.AccessibleObject, .Constructor, .Field, .Method, .Modifier

Nested and Inner Type Summary

Modifier and TypeClass and Description
private abstract static class
ReflectionHelper.RecordHelper

Internal abstraction over reflection when Records are supported.

private static class
ReflectionHelper.RecordNotSupportedHelper

Instance used when records are not supported

private static class

Field Summary

Modifier and TypeField and Description
private static final ReflectionHelper.RecordHelper

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static void
public static String
constructorToString(Constructor<?> constructor)

Creates a string representation for a constructor.

private static RuntimeException
public static RuntimeException
public static String
fieldToString(Field field)

Creates a string representation for a field, omitting modifiers and the field type.

public static String
getAccessibleObjectDescription(AccessibleObject
object to describe
object
,
boolean
whether the first letter of the description should be uppercased
uppercaseFirstLetter
)

Returns a short string describing the AccessibleObject in a human-readable way.

public static Method
getAccessor(Class<?> raw, Field field)

Looks up the record accessor method that corresponds to the given record field

public static <T> Constructor<T>
private static String
public static String[]
public static boolean
isAnonymousOrNonStaticLocal(Class<?> clazz)

Returns whether the class is anonymous or a non-static local class.

public static boolean
isRecord(Class<?> raw)

If records are supported on the JVM, this is equivalent to a call to Class.isRecord()

public static boolean
isStatic(Class<?> clazz)

public static void
makeAccessible(AccessibleObject
the object that AccessibleObject#setAccessible(boolean) should be called on.
object
)

Internal implementation of making an AccessibleObject accessible.

public static String

Returns:

exception message; null if successful, non-null if unsuccessful
tryMakeAccessible
(Constructor<?>
constructor to make accessible
constructor
)

Tries making the constructor accessible, returning an exception message if this fails.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

RECORD_HELPERback to summary
private static final ReflectionHelper.RecordHelper RECORD_HELPER

Constructor Detail

ReflectionHelperback to summary
private ReflectionHelper()

Method Detail

appendExecutableParametersback to summary
private static void appendExecutableParameters(AccessibleObject executable, StringBuilder stringBuilder)
constructorToStringback to summary
public static String constructorToString(Constructor<?> constructor)

Creates a string representation for a constructor. E.g.: java.lang.String(char[], int, int)

createExceptionForRecordReflectionExceptionback to summary
private static RuntimeException createExceptionForRecordReflectionException(ReflectiveOperationException exception)
createExceptionForUnexpectedIllegalAccessback to summary
public static RuntimeException createExceptionForUnexpectedIllegalAccess(IllegalAccessException exception)
fieldToStringback to summary
public static String fieldToString(Field field)

Creates a string representation for a field, omitting modifiers and the field type.

getAccessibleObjectDescriptionback to summary
public static String getAccessibleObjectDescription(AccessibleObject object, boolean uppercaseFirstLetter)

Returns a short string describing the AccessibleObject in a human-readable way. The result is normally shorter than AccessibleObject#toString() because it omits modifiers (e.g. final) and uses simple names for constructor and method parameter types.

Parameters
object:AccessibleObject

object to describe

uppercaseFirstLetter:boolean

whether the first letter of the description should be uppercased

getAccessorback to summary
public static Method getAccessor(Class<?> raw, Field field)

Looks up the record accessor method that corresponds to the given record field

getCanonicalRecordConstructorback to summary
public static <T> Constructor<T> getCanonicalRecordConstructor(Class<T> raw)
getInaccessibleTroubleshootingSuffixback to summary
private static String getInaccessibleTroubleshootingSuffix(Exception e)
getRecordComponentNamesback to summary
public static String[] getRecordComponentNames(Class<?> raw)
isAnonymousOrNonStaticLocalback to summary
public static boolean isAnonymousOrNonStaticLocal(Class<?> clazz)

Returns whether the class is anonymous or a non-static local class.

isRecordback to summary
public static boolean isRecord(Class<?> raw)

If records are supported on the JVM, this is equivalent to a call to Class.isRecord()

isStaticback to summary
public static boolean isStatic(Class<?> clazz)
makeAccessibleback to summary
public static void makeAccessible(AccessibleObject object) throws JsonIOException

Internal implementation of making an AccessibleObject accessible.

Parameters
object:AccessibleObject

the object that AccessibleObject#setAccessible(boolean) should be called on.

Exceptions
JsonIOException:
if making the object accessible fails
tryMakeAccessibleback to summary
public static String tryMakeAccessible(Constructor<?> constructor)

Tries making the constructor accessible, returning an exception message if this fails.

Parameters
constructor:Constructor<?>

constructor to make accessible

Returns:String

exception message; null if successful, non-null if unsuccessful

com.google.gson.internal.reflect back to summary

private abstract Class ReflectionHelper.RecordHelper

extends Object
Class Inheritance
  • java.lang.Object
  • com.google.gson.internal.reflect.ReflectionHelper.RecordHelper
Known Direct Subclasses
com.google.gson.internal.reflect.ReflectionHelper.RecordSupportedHelper, com.google.gson.internal.reflect.ReflectionHelper.RecordNotSupportedHelper

Internal abstraction over reflection when Records are supported.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv abstract Method
getAccessor(Class<?> raw, Field field)

pack-priv abstract <T> Constructor<T>
pack-priv abstract String[]
pack-priv abstract boolean
isRecord(Class<?> clazz)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

RecordHelperback to summary
private RecordHelper()

Method Detail

getAccessorback to summary
pack-priv abstract Method getAccessor(Class<?> raw, Field field)
getCanonicalRecordConstructorback to summary
pack-priv abstract <T> Constructor<T> getCanonicalRecordConstructor(Class<T> raw)
getRecordComponentNamesback to summary
pack-priv abstract String[] getRecordComponentNames(Class<?> clazz)
isRecordback to summary
pack-priv abstract boolean isRecord(Class<?> clazz)
com.google.gson.internal.reflect back to summary

private Class ReflectionHelper.RecordNotSupportedHelper

extends RecordHelper
Class Inheritance

Instance used when records are not supported

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Method
pack-priv <T> Constructor<T>
pack-priv String[]
pack-priv boolean

Constructor Detail

RecordNotSupportedHelperback to summary
private RecordNotSupportedHelper()

Method Detail

getAccessorback to summary
public Method getAccessor(Class<?> raw, Field field)

Implements abstract com.google.gson.internal.reflect.ReflectionHelper.RecordHelper.getAccessor.

Annotations
@Override
getCanonicalRecordConstructorback to summary
pack-priv <T> Constructor<T> getCanonicalRecordConstructor(Class<T> raw)

Implements abstract com.google.gson.internal.reflect.ReflectionHelper.RecordHelper.getCanonicalRecordConstructor.

Annotations
@Override
getRecordComponentNamesback to summary
pack-priv String[] getRecordComponentNames(Class<?> clazz)

Implements abstract com.google.gson.internal.reflect.ReflectionHelper.RecordHelper.getRecordComponentNames.

Annotations
@Override
isRecordback to summary
pack-priv boolean isRecord(Class<?> clazz)

Implements abstract com.google.gson.internal.reflect.ReflectionHelper.RecordHelper.isRecord.

Annotations
@Override
com.google.gson.internal.reflect back to summary

private Class ReflectionHelper.RecordSupportedHelper

extends RecordHelper
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final Method
private final Method
private final Method
private final Method

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Method
public <T> Constructor<T>
pack-priv String[]
pack-priv boolean

Field Detail

getNameback to summary
private final Method getName
getRecordComponentsback to summary
private final Method getRecordComponents
getTypeback to summary
private final Method getType
isRecordback to summary
private final Method isRecord

Constructor Detail

RecordSupportedHelperback to summary
private RecordSupportedHelper() throws NoSuchMethodException, ClassNotFoundException

Method Detail

getAccessorback to summary
public Method getAccessor(Class<?> raw, Field field)

Implements abstract com.google.gson.internal.reflect.ReflectionHelper.RecordHelper.getAccessor.

Annotations
@Override
getCanonicalRecordConstructorback to summary
public <T> Constructor<T> getCanonicalRecordConstructor(Class<T> raw)

Implements abstract com.google.gson.internal.reflect.ReflectionHelper.RecordHelper.getCanonicalRecordConstructor.

Annotations
@Override
getRecordComponentNamesback to summary
pack-priv String[] getRecordComponentNames(Class<?> raw)

Implements abstract com.google.gson.internal.reflect.ReflectionHelper.RecordHelper.getRecordComponentNames.

Annotations
@Override
isRecordback to summary
pack-priv boolean isRecord(Class<?> raw)

Implements abstract com.google.gson.internal.reflect.ReflectionHelper.RecordHelper.isRecord.

Annotations
@Override