Package com.google.gson.internal
Class GsonTypes
- java.lang.Object
-
- com.google.gson.internal.GsonTypes
-
public final class GsonTypes extends java.lang.ObjectStatic methods for working with types.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classGsonTypes.GenericArrayTypeImplprivate static classGsonTypes.ParameterizedTypeImplprivate static classGsonTypes.WildcardTypeImplThe WildcardType interface supports multiple upper bounds and multiple lower bounds.
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.lang.reflect.Type[]EMPTY_TYPE_ARRAY
-
Constructor Summary
Constructors Modifier Constructor Description privateGsonTypes()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.reflect.GenericArrayTypearrayOf(java.lang.reflect.Type componentType)Returns an array type whose elements are all instances ofcomponentType.static java.lang.reflect.Typecanonicalize(java.lang.reflect.Type type)Returns a type that is functionally equal but not necessarily equal according toObject.equals().(package private) static voidcheckNotPrimitive(java.lang.reflect.Type type)private static java.lang.Class<?>declaringClassOf(java.lang.reflect.TypeVariable<?> typeVariable)Returns the declaring class oftypeVariable, ornullif it was not declared by a class.private static booleanequal(java.lang.Object a, java.lang.Object b)static booleanequals(java.lang.reflect.Type a, java.lang.reflect.Type b)Returns true ifaandbare equal.static java.lang.reflect.TypegetArrayComponentType(java.lang.reflect.Type array)Returns the component type of this array type.static java.lang.reflect.TypegetCollectionElementType(java.lang.reflect.Type context, java.lang.Class<?> contextRawType)Returns the element type of this collection type.private static java.lang.reflect.TypegetGenericSupertype(java.lang.reflect.Type context, java.lang.Class<?> rawType, java.lang.Class<?> supertype)Returns the generic supertype forsupertype.static java.lang.reflect.Type[]getMapKeyAndValueTypes(java.lang.reflect.Type context, java.lang.Class<?> contextRawType)Returns a two element array containing this map's key and value types in positions 0 and 1 respectively.static java.lang.Class<?>getRawType(java.lang.reflect.Type type)private static java.lang.reflect.TypegetSupertype(java.lang.reflect.Type context, java.lang.Class<?> contextRawType, java.lang.Class<?> supertype)Returns the generic form ofsupertype.private static intindexOf(java.lang.Object[] array, java.lang.Object toFind)static java.lang.reflect.ParameterizedTypenewParameterizedTypeWithOwner(java.lang.reflect.Type ownerType, java.lang.Class<?> rawType, java.lang.reflect.Type... typeArguments)Returns a new parameterized type, applyingtypeArgumentstorawTypeand enclosed byownerType.static booleanrequiresOwnerType(java.lang.reflect.Type rawType)Whether an owner type must be specified when constructing aParameterizedTypeforrawType.static java.lang.reflect.Typeresolve(java.lang.reflect.Type context, java.lang.Class<?> contextRawType, java.lang.reflect.Type toResolve)private static java.lang.reflect.Typeresolve(java.lang.reflect.Type context, java.lang.Class<?> contextRawType, java.lang.reflect.Type toResolve, java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> visitedTypeVariables)private static java.lang.reflect.TyperesolveTypeVariable(java.lang.reflect.Type context, java.lang.Class<?> contextRawType, java.lang.reflect.TypeVariable<?> unknown)static java.lang.reflect.WildcardTypesubtypeOf(java.lang.reflect.Type bound)Returns a type that represents an unknown type that extendsbound.static java.lang.reflect.WildcardTypesupertypeOf(java.lang.reflect.Type bound)Returns a type that represents an unknown supertype ofbound.static java.lang.StringtypeToString(java.lang.reflect.Type type)
-
-
-
Method Detail
-
newParameterizedTypeWithOwner
public static java.lang.reflect.ParameterizedType newParameterizedTypeWithOwner(java.lang.reflect.Type ownerType, java.lang.Class<?> rawType, java.lang.reflect.Type... typeArguments)Returns a new parameterized type, applyingtypeArgumentstorawTypeand enclosed byownerType.- Returns:
- a
serializableparameterized type.
-
arrayOf
public static java.lang.reflect.GenericArrayType arrayOf(java.lang.reflect.Type componentType)
Returns an array type whose elements are all instances ofcomponentType.- Returns:
- a
serializablegeneric array type.
-
subtypeOf
public static java.lang.reflect.WildcardType subtypeOf(java.lang.reflect.Type bound)
Returns a type that represents an unknown type that extendsbound. For example, ifboundisCharSequence.class, this returns? extends CharSequence. IfboundisObject.class, this returns?, which is shorthand for? extends Object.
-
supertypeOf
public static java.lang.reflect.WildcardType supertypeOf(java.lang.reflect.Type bound)
Returns a type that represents an unknown supertype ofbound. For example, ifboundisString.class, this returns? super String.
-
canonicalize
public static java.lang.reflect.Type canonicalize(java.lang.reflect.Type type)
Returns a type that is functionally equal but not necessarily equal according toObject.equals(). The returned type isSerializable.
-
getRawType
public static java.lang.Class<?> getRawType(java.lang.reflect.Type type)
-
equal
private static boolean equal(java.lang.Object a, java.lang.Object b)
-
equals
public static boolean equals(java.lang.reflect.Type a, java.lang.reflect.Type b)Returns true ifaandbare equal.
-
typeToString
public static java.lang.String typeToString(java.lang.reflect.Type type)
-
getGenericSupertype
private static java.lang.reflect.Type getGenericSupertype(java.lang.reflect.Type context, java.lang.Class<?> rawType, java.lang.Class<?> supertype)Returns the generic supertype forsupertype. For example, given a classIntegerSet, the result for when supertype isSet.classisSet<Integer>and the result when the supertype isCollection.classisCollection<Integer>.
-
getSupertype
private static java.lang.reflect.Type getSupertype(java.lang.reflect.Type context, java.lang.Class<?> contextRawType, java.lang.Class<?> supertype)Returns the generic form ofsupertype. For example, if this isArrayList<String>, this returnsIterable<String>given the inputIterable.class.- Parameters:
supertype- a superclass of, or interface implemented by, this.
-
getArrayComponentType
public static java.lang.reflect.Type getArrayComponentType(java.lang.reflect.Type array)
Returns the component type of this array type.- Throws:
java.lang.ClassCastException- if this type is not an array.
-
getCollectionElementType
public static java.lang.reflect.Type getCollectionElementType(java.lang.reflect.Type context, java.lang.Class<?> contextRawType)Returns the element type of this collection type.- Throws:
java.lang.IllegalArgumentException- if this type is not a collection.
-
getMapKeyAndValueTypes
public static java.lang.reflect.Type[] getMapKeyAndValueTypes(java.lang.reflect.Type context, java.lang.Class<?> contextRawType)Returns a two element array containing this map's key and value types in positions 0 and 1 respectively.
-
resolve
public static java.lang.reflect.Type resolve(java.lang.reflect.Type context, java.lang.Class<?> contextRawType, java.lang.reflect.Type toResolve)
-
resolve
private static java.lang.reflect.Type resolve(java.lang.reflect.Type context, java.lang.Class<?> contextRawType, java.lang.reflect.Type toResolve, java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> visitedTypeVariables)
-
resolveTypeVariable
private static java.lang.reflect.Type resolveTypeVariable(java.lang.reflect.Type context, java.lang.Class<?> contextRawType, java.lang.reflect.TypeVariable<?> unknown)
-
indexOf
private static int indexOf(java.lang.Object[] array, java.lang.Object toFind)
-
declaringClassOf
private static java.lang.Class<?> declaringClassOf(java.lang.reflect.TypeVariable<?> typeVariable)
Returns the declaring class oftypeVariable, ornullif it was not declared by a class.
-
checkNotPrimitive
static void checkNotPrimitive(java.lang.reflect.Type type)
-
requiresOwnerType
public static boolean requiresOwnerType(java.lang.reflect.Type rawType)
Whether an owner type must be specified when constructing aParameterizedTypeforrawType.Note that this method might not require an owner type for all cases where Java reflection would create parameterized types with owner type.
-
-