Package com.google.gson.internal
Class ConstructorConstructor
- java.lang.Object
-
- com.google.gson.internal.ConstructorConstructor
-
public final class ConstructorConstructor extends java.lang.ObjectReturns a function that can construct an instance of a requested type.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.reflect.Type,InstanceCreator<?>>instanceCreatorsprivate java.util.List<ReflectionAccessFilter>reflectionFiltersprivate booleanuseJdkUnsafe
-
Constructor Summary
Constructors Constructor Description ConstructorConstructor(java.util.Map<java.lang.reflect.Type,InstanceCreator<?>> instanceCreators, boolean useJdkUnsafe, java.util.List<ReflectionAccessFilter> reflectionFilters)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static java.lang.StringcheckInstantiable(java.lang.Class<?> c)Check if the class can be instantiated by Unsafe allocator.<T> ObjectConstructor<T>get(TypeToken<T> typeToken)Callsget(TypeToken, boolean), and allows usage of JDK Unsafe.<T> ObjectConstructor<T>get(TypeToken<T> typeToken, boolean allowUnsafe)Retrieves an object constructor for the given type.private static booleanhasStringKeyType(java.lang.reflect.Type mapType)private static ObjectConstructor<? extends java.util.Collection<? extends java.lang.Object>>newCollectionConstructor(java.lang.Class<?> rawType)private static <T> ObjectConstructor<T>newDefaultConstructor(java.lang.Class<? super T> rawType, ReflectionAccessFilter.FilterResult filterResult)private static <T> ObjectConstructor<T>newDefaultImplementationConstructor(java.lang.reflect.Type type, java.lang.Class<? super T> rawType)Constructors for common interface types like Map and List and their subtypes.private static ObjectConstructor<? extends java.util.Map<? extends java.lang.Object,java.lang.Object>>newMapConstructor(java.lang.reflect.Type type, java.lang.Class<?> rawType)private static <T> ObjectConstructor<T>newSpecialCollectionConstructor(java.lang.reflect.Type type, java.lang.Class<? super T> rawType)Creates constructors for special JDK collection types which do not have a public no-args constructor.private <T> ObjectConstructor<T>newUnsafeAllocator(java.lang.Class<? super T> rawType)java.lang.StringtoString()
-
-
-
Field Detail
-
instanceCreators
private final java.util.Map<java.lang.reflect.Type,InstanceCreator<?>> instanceCreators
-
useJdkUnsafe
private final boolean useJdkUnsafe
-
reflectionFilters
private final java.util.List<ReflectionAccessFilter> reflectionFilters
-
-
Constructor Detail
-
ConstructorConstructor
public ConstructorConstructor(java.util.Map<java.lang.reflect.Type,InstanceCreator<?>> instanceCreators, boolean useJdkUnsafe, java.util.List<ReflectionAccessFilter> reflectionFilters)
-
-
Method Detail
-
checkInstantiable
static java.lang.String checkInstantiable(java.lang.Class<?> c)
Check if the class can be instantiated by Unsafe allocator. If the instance has interface or abstract modifiers return an exception message.- Parameters:
c- instance of the class to be checked- Returns:
- if instantiable
null, else a non-nullexception message
-
get
public <T> ObjectConstructor<T> get(TypeToken<T> typeToken)
Callsget(TypeToken, boolean), and allows usage of JDK Unsafe.
-
get
public <T> ObjectConstructor<T> get(TypeToken<T> typeToken, boolean allowUnsafe)
Retrieves an object constructor for the given type.- Parameters:
typeToken- type for which a constructor should be retrievedallowUnsafe- whether to allow usage of JDK Unsafe; has no effect ifuseJdkUnsafeis false
-
newSpecialCollectionConstructor
private static <T> ObjectConstructor<T> newSpecialCollectionConstructor(java.lang.reflect.Type type, java.lang.Class<? super T> rawType)
Creates constructors for special JDK collection types which do not have a public no-args constructor.
-
newDefaultConstructor
private static <T> ObjectConstructor<T> newDefaultConstructor(java.lang.Class<? super T> rawType, ReflectionAccessFilter.FilterResult filterResult)
-
newDefaultImplementationConstructor
private static <T> ObjectConstructor<T> newDefaultImplementationConstructor(java.lang.reflect.Type type, java.lang.Class<? super T> rawType)
Constructors for common interface types like Map and List and their subtypes.
-
newCollectionConstructor
private static ObjectConstructor<? extends java.util.Collection<? extends java.lang.Object>> newCollectionConstructor(java.lang.Class<?> rawType)
-
hasStringKeyType
private static boolean hasStringKeyType(java.lang.reflect.Type mapType)
-
newMapConstructor
private static ObjectConstructor<? extends java.util.Map<? extends java.lang.Object,java.lang.Object>> newMapConstructor(java.lang.reflect.Type type, java.lang.Class<?> rawType)
-
newUnsafeAllocator
private <T> ObjectConstructor<T> newUnsafeAllocator(java.lang.Class<? super T> rawType)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-