Package com.google.inject.internal
Class MoreTypes
- java.lang.Object
-
- com.google.inject.internal.MoreTypes
-
public class MoreTypes extends java.lang.Object
Static methods for working with types that we aren't publishing in the publicTypes
API.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static interface
MoreTypes.CompositeType
A type formed from other types, such as arrays, parameterized types or wildcard typesstatic class
MoreTypes.GenericArrayTypeImpl
static class
MoreTypes.ParameterizedTypeImpl
static class
MoreTypes.WildcardTypeImpl
The WildcardType interface supports multiple upper bounds and multiple lower bounds.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.reflect.Type[]
EMPTY_TYPE_ARRAY
private static com.google.common.collect.ImmutableMap<TypeLiteral<?>,TypeLiteral<?>>
PRIMITIVE_TO_WRAPPER
-
Constructor Summary
Constructors Modifier Constructor Description private
MoreTypes()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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()
.static <T> TypeLiteral<T>
canonicalizeForKey(TypeLiteral<T> typeLiteral)
Returns an type that's appropriate for use in a key.static <T> Key<T>
canonicalizeKey(Key<T> key)
Returns a key that doesn't hold any references to parent classes.private static void
checkNotPrimitive(java.lang.reflect.Type type, java.lang.String use)
private static java.lang.Class<?>
declaringClassOf(java.lang.reflect.TypeVariable<?> typeVariable)
Returns the declaring class oftypeVariable
, ornull
if it was not declared by a class.static boolean
equals(java.lang.reflect.Type a, java.lang.reflect.Type b)
Returns true ifa
andb
are equal.static java.lang.reflect.Type
getGenericSupertype(java.lang.reflect.Type type, java.lang.Class<?> rawType, java.lang.Class<?> toResolve)
Returns the generic supertype fortype
.static java.lang.Class<?>
getRawType(java.lang.reflect.Type type)
private static java.lang.reflect.Type[]
getSharedTypeArguments(java.lang.reflect.ParameterizedType p)
This method is used as a performance optimization to prevent unnecessary clones of typeArguments from being made by ParameterizedTypeImpl.private static int
hashCodeOrZero(java.lang.Object o)
private static int
indexOf(java.lang.Object[] array, java.lang.Object toFind)
private static boolean
isFullySpecified(java.lang.reflect.Type type)
Returns true iftype
is free from type variables.static java.lang.reflect.Type
resolveTypeVariable(java.lang.reflect.Type type, java.lang.Class<?> rawType, java.lang.reflect.TypeVariable<?> unknown)
static java.lang.String
typeToString(java.lang.reflect.Type type)
-
-
-
Field Detail
-
EMPTY_TYPE_ARRAY
public static final java.lang.reflect.Type[] EMPTY_TYPE_ARRAY
-
PRIMITIVE_TO_WRAPPER
private static final com.google.common.collect.ImmutableMap<TypeLiteral<?>,TypeLiteral<?>> PRIMITIVE_TO_WRAPPER
-
-
Method Detail
-
canonicalizeKey
public static <T> Key<T> canonicalizeKey(Key<T> key)
Returns a key that doesn't hold any references to parent classes. This is necessary for anonymous keys, so ensure we don't hold a ref to the containing module (or class) forever.
-
canonicalizeForKey
public static <T> TypeLiteral<T> canonicalizeForKey(TypeLiteral<T> typeLiteral)
Returns an type that's appropriate for use in a key.If the raw type of
typeLiteral
is ajavax.inject.Provider
, this returns acom.google.inject.Provider
with the same type parameters.If the type is a primitive, the corresponding wrapper type will be returned.
- Throws:
ConfigurationException
- iftype
contains a type variable
-
isFullySpecified
private static boolean isFullySpecified(java.lang.reflect.Type type)
Returns true iftype
is free from type variables.
-
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)
-
equals
public static boolean equals(java.lang.reflect.Type a, java.lang.reflect.Type b)
Returns true ifa
andb
are equal.
-
hashCodeOrZero
private static int hashCodeOrZero(java.lang.Object o)
-
typeToString
public static java.lang.String typeToString(java.lang.reflect.Type type)
-
getGenericSupertype
public static java.lang.reflect.Type getGenericSupertype(java.lang.reflect.Type type, java.lang.Class<?> rawType, java.lang.Class<?> toResolve)
Returns the generic supertype fortype
. For example, given a classIntegerSet
, the result for when supertype isSet.class
isSet<Integer>
and the result when the supertype isCollection.class
isCollection<Integer>
.
-
resolveTypeVariable
public static java.lang.reflect.Type resolveTypeVariable(java.lang.reflect.Type type, java.lang.Class<?> rawType, java.lang.reflect.TypeVariable<?> unknown)
-
indexOf
private static int indexOf(java.lang.Object[] array, java.lang.Object toFind)
-
getSharedTypeArguments
private static java.lang.reflect.Type[] getSharedTypeArguments(java.lang.reflect.ParameterizedType p)
This method is used as a performance optimization to prevent unnecessary clones of typeArguments from being made by ParameterizedTypeImpl.
-
declaringClassOf
private static java.lang.Class<?> declaringClassOf(java.lang.reflect.TypeVariable<?> typeVariable)
Returns the declaring class oftypeVariable
, ornull
if it was not declared by a class.
-
checkNotPrimitive
private static void checkNotPrimitive(java.lang.reflect.Type type, java.lang.String use)
-
-