Top Description Inners Fields Constructors Methods
com.google.inject.internal

public Class MoreTypes

extends Object
Class Inheritance
Static Imports
com.google.common.base.Preconditions.checkArgument, .Preconditions.checkNotNull

Static methods for working with types that we aren't publishing in the public Types API.
Author
[email protected] (Jesse Wilson)

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static interface
MoreTypes.CompositeType

A type formed from other types, such as arrays, parameterized types or wildcard types

public static class
public static class
public static class
MoreTypes.WildcardTypeImpl

The WildcardType interface supports multiple upper bounds and multiple lower bounds.

Field Summary

Modifier and TypeField and Description
public static final Type[]
private static final ImmutableMap<TypeLiteral<?>, TypeLiteral<?>>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Type
canonicalize(Type type)

Returns a type that is functionally equal but not necessarily equal according to Object.equals().

public static <T> TypeLiteral<T>
canonicalizeForKey(TypeLiteral<T> typeLiteral)

Returns an type that's appropriate for use in a key.

public static <T> Key<T>
canonicalizeKey(Key<T> key)

Returns a key that doesn't hold any references to parent classes.

private static void
private static Class<?>
declaringClassOf(TypeVariable<?> typeVariable)

Returns the declaring class of typeVariable, or null if it was not declared by a class.

public static boolean
equals(Type a, Type b)

Returns true if a and b are equal.

public static Type
getGenericSupertype(Type type, Class<?> rawType, Class<?> toResolve)

Returns the generic supertype for type.

public static Class<?>
private static Type[]
getSharedTypeArguments(ParameterizedType p)

This method is used as a performance optimization to prevent unnecessary clones of typeArguments from being made by ParameterizedTypeImpl.

private static int
private static int
indexOf(Object[] array, Object toFind)

private static boolean
isFullySpecified(Type type)

Returns true if type is free from type variables.

public static Type
resolveTypeVariable(Type type, Class<?> rawType, TypeVariable<?> unknown)

public static String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EMPTY_TYPE_ARRAYback to summary
public static final Type[] EMPTY_TYPE_ARRAY
PRIMITIVE_TO_WRAPPERback to summary
private static final ImmutableMap<TypeLiteral<?>, TypeLiteral<?>> PRIMITIVE_TO_WRAPPER

Constructor Detail

MoreTypesback to summary
private MoreTypes()

Method Detail

canonicalizeback to summary
public static Type canonicalize(Type type)

Returns a type that is functionally equal but not necessarily equal according to Object.equals(). The returned type is Serializable.

canonicalizeForKeyback to summary
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 a jakarta.inject.Provider or jakarta.inject.Provider, this returns a com.google.inject.Provider with the same type parameters.

If the type is a primitive, the corresponding wrapper type will be returned.

Exceptions
ConfigurationException:
if type contains a type variable
canonicalizeKeyback to summary
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.

checkNotPrimitiveback to summary
private static void checkNotPrimitive(Type type, String use)
declaringClassOfback to summary
private static Class<?> declaringClassOf(TypeVariable<?> typeVariable)

Returns the declaring class of typeVariable, or null if it was not declared by a class.

equalsback to summary
public static boolean equals(Type a, Type b)

Returns true if a and b are equal.

getGenericSupertypeback to summary
public static Type getGenericSupertype(Type type, Class<?> rawType, Class<?> toResolve)

Returns the generic supertype for type. For example, given a class IntegerSet, the result for when supertype is Set.class is Set<Integer> and the result when the supertype is Collection.class is Collection<Integer>.

getRawTypeback to summary
public static Class<?> getRawType(Type type)
getSharedTypeArgumentsback to summary
private static Type[] getSharedTypeArguments(ParameterizedType p)

This method is used as a performance optimization to prevent unnecessary clones of typeArguments from being made by ParameterizedTypeImpl.

hashCodeOrZeroback to summary
private static int hashCodeOrZero(Object o)
indexOfback to summary
private static int indexOf(Object[] array, Object toFind)
isFullySpecifiedback to summary
private static boolean isFullySpecified(Type type)

Returns true if type is free from type variables.

resolveTypeVariableback to summary
public static Type resolveTypeVariable(Type type, Class<?> rawType, TypeVariable<?> unknown)
typeToStringback to summary
public static String typeToString(Type type)
com.google.inject.internal back to summary

private Interface MoreTypes.CompositeType

Known Direct Implementers
com.google.inject.internal.MoreTypes.ParameterizedTypeImpl, com.google.inject.internal.MoreTypes.GenericArrayTypeImpl, com.google.inject.internal.MoreTypes.WildcardTypeImpl

A type formed from other types, such as arrays, parameterized types or wildcard types

Method Summary

Modifier and TypeMethod and Description
public boolean
isFullySpecified()

Returns true if there are no type variables in this type.

Method Detail

isFullySpecifiedback to summary
public boolean isFullySpecified()

Returns true if there are no type variables in this type.

com.google.inject.internal back to summary

public Class MoreTypes.GenericArrayTypeImpl

extends Object
implements GenericArrayType, Serializable, CompositeType
Class Inheritance
All Implemented Interfaces
com.google.inject.internal.MoreTypes.CompositeType, java.io.Serializable, java.lang.reflect.GenericArrayType, java.lang.reflect.Type

Field Summary

Modifier and TypeField and Description
private final Type
private static final long

Constructor Summary

AccessConstructor and Description
public
GenericArrayTypeImpl(Type componentType)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public Type
getGenericComponentType()

Implements java.lang.reflect.GenericArrayType.getGenericComponentType.

Returns a Type object representing the component type of this array.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
public boolean
isFullySpecified()

Implements com.google.inject.internal.MoreTypes.CompositeType.isFullySpecified.

Returns true if there are no type variables in this type.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

componentTypeback to summary
private final Type componentType
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

GenericArrayTypeImplback to summary
public GenericArrayTypeImpl(Type componentType)

Method Detail

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getGenericComponentTypeback to summary
public Type getGenericComponentType()

Implements java.lang.reflect.GenericArrayType.getGenericComponentType.

Doc from java.lang.reflect.GenericArrayType.getGenericComponentType.

Returns a Type object representing the component type of this array. This method creates the component type of the array. See the declaration of ParameterizedType for the semantics of the creation process for parameterized types and see TypeVariable for the creation process for type variables.

Returns:Type

a Type object representing the component type of this array

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
isFullySpecifiedback to summary
public boolean isFullySpecified()

Implements com.google.inject.internal.MoreTypes.CompositeType.isFullySpecified.

Doc from com.google.inject.internal.MoreTypes.CompositeType.isFullySpecified.

Returns true if there are no type variables in this type.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
com.google.inject.internal back to summary

public Class MoreTypes.ParameterizedTypeImpl

extends Object
implements ParameterizedType, Serializable, CompositeType
Class Inheritance
All Implemented Interfaces
com.google.inject.internal.MoreTypes.CompositeType, java.io.Serializable, java.lang.reflect.ParameterizedType, java.lang.reflect.Type

Field Summary

Modifier and TypeField and Description
private final Type
private final Type
private static final long
pack-priv final Type[]

Constructor Summary

AccessConstructor and Description
public
ParameterizedTypeImpl(Type ownerType, Type rawType, Type... typeArguments)

Method Summary

Modifier and TypeMethod and Description
private static void
ensureOwnerType(Type ownerType, Type rawType)

public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public Type[]
getActualTypeArguments()

Implements java.lang.reflect.ParameterizedType.getActualTypeArguments.

Returns an array of Type objects representing the actual type arguments to this type.
public Type
getOwnerType()

Implements java.lang.reflect.ParameterizedType.getOwnerType.

Returns a Type object representing the type that this type is a member of.
public Type
getRawType()

Implements java.lang.reflect.ParameterizedType.getRawType.

Returns the Type object representing the class or interface that declared this type.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
public boolean
isFullySpecified()

Implements com.google.inject.internal.MoreTypes.CompositeType.isFullySpecified.

Returns true if there are no type variables in this type.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

ownerTypeback to summary
private final Type ownerType
rawTypeback to summary
private final Type rawType
serialVersionUIDback to summary
private static final long serialVersionUID
typeArgumentsback to summary
pack-priv final Type[] typeArguments

Constructor Detail

ParameterizedTypeImplback to summary
public ParameterizedTypeImpl(Type ownerType, Type rawType, Type... typeArguments)

Method Detail

ensureOwnerTypeback to summary
private static void ensureOwnerType(Type ownerType, Type rawType)
equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getActualTypeArgumentsback to summary
public Type[] getActualTypeArguments()

Implements java.lang.reflect.ParameterizedType.getActualTypeArguments.

Doc from java.lang.reflect.ParameterizedType.getActualTypeArguments.

Returns an array of Type objects representing the actual type arguments to this type.

Note that in some cases, the returned array be empty. This can occur if this type represents a non-parameterized type nested within a parameterized type.

Returns:Type[]

an array of Type objects representing the actual type arguments to this type

Annotations
@Override
getOwnerTypeback to summary
public Type getOwnerType()

Implements java.lang.reflect.ParameterizedType.getOwnerType.

Doc from java.lang.reflect.ParameterizedType.getOwnerType.

Returns a Type object representing the type that this type is a member of. For example, if this type is O<T>.I<S>, return a representation of O<T>.

If this type is a top-level type, null is returned.

Returns:Type

a Type object representing the type that this type is a member of. If this type is a top-level type, null is returned

Annotations
@Override
getRawTypeback to summary
public Type getRawType()

Implements java.lang.reflect.ParameterizedType.getRawType.

Doc from java.lang.reflect.ParameterizedType.getRawType.

Returns the Type object representing the class or interface that declared this type.

Returns:Type

the Type object representing the class or interface that declared this type

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
isFullySpecifiedback to summary
public boolean isFullySpecified()

Implements com.google.inject.internal.MoreTypes.CompositeType.isFullySpecified.

Doc from com.google.inject.internal.MoreTypes.CompositeType.isFullySpecified.

Returns true if there are no type variables in this type.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
com.google.inject.internal back to summary

public Class MoreTypes.WildcardTypeImpl

extends Object
implements WildcardType, Serializable, CompositeType
Class Inheritance
All Implemented Interfaces
com.google.inject.internal.MoreTypes.CompositeType, java.io.Serializable, java.lang.reflect.WildcardType, java.lang.reflect.Type

The WildcardType interface supports multiple upper bounds and multiple lower bounds. We only support what the Java 8 language needs - at most one bound. If a lower bound is set, the upper bound must be Object.class.

Field Summary

Modifier and TypeField and Description
private final Type
private static final long
private final Type

Constructor Summary

AccessConstructor and Description
public
WildcardTypeImpl(Type[] upperBounds, Type[] lowerBounds)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public Type[]
getLowerBounds()

Implements java.lang.reflect.WildcardType.getLowerBounds.

Returns an array of Type objects representing the lower bound(s) of this type variable.
public Type[]
getUpperBounds()

Implements java.lang.reflect.WildcardType.getUpperBounds.

Returns an array of Type objects representing the upper bound(s) of this type variable.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
public boolean
isFullySpecified()

Implements com.google.inject.internal.MoreTypes.CompositeType.isFullySpecified.

Returns true if there are no type variables in this type.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

lowerBoundback to summary
private final Type lowerBound
serialVersionUIDback to summary
private static final long serialVersionUID
upperBoundback to summary
private final Type upperBound

Constructor Detail

WildcardTypeImplback to summary
public WildcardTypeImpl(Type[] upperBounds, Type[] lowerBounds)

Method Detail

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getLowerBoundsback to summary
public Type[] getLowerBounds()

Implements java.lang.reflect.WildcardType.getLowerBounds.

Doc from java.lang.reflect.WildcardType.getLowerBounds.

Returns an array of Type objects representing the lower bound(s) of this type variable. If no lower bound is explicitly declared, the lower bound is the type of null. In this case, a zero length array is returned.

For each lower bound B :

  • if B is a parameterized type or a type variable, it is created, (see ParameterizedType for the details of the creation process for parameterized types).
  • Otherwise, B is resolved.
Returns:Type[]

an array of Types representing the lower bound(s) of this type variable

Annotations
@Override
getUpperBoundsback to summary
public Type[] getUpperBounds()

Implements java.lang.reflect.WildcardType.getUpperBounds.

Doc from java.lang.reflect.WildcardType.getUpperBounds.

Returns an array of Type objects representing the upper bound(s) of this type variable. If no upper bound is explicitly declared, the upper bound is Object.

For each upper bound B :

  • if B is a parameterized type or a type variable, it is created, (see ParameterizedType for the details of the creation process for parameterized types).
  • Otherwise, B is resolved.
Returns:Type[]

an array of Types representing the upper bound(s) of this type variable

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
isFullySpecifiedback to summary
public boolean isFullySpecified()

Implements com.google.inject.internal.MoreTypes.CompositeType.isFullySpecified.

Doc from com.google.inject.internal.MoreTypes.CompositeType.isFullySpecified.

Returns true if there are no type variables in this type.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override