Class MoreTypes

java.lang.Object
com.google.inject.internal.MoreTypes

public class MoreTypes extends Object
Static methods for working with types that we aren't publishing in the public Types API.
  • Field Details

    • EMPTY_TYPE_ARRAY

      public static final Type[] EMPTY_TYPE_ARRAY
    • PRIMITIVE_TO_WRAPPER

      private static final com.google.common.collect.ImmutableMap<TypeLiteral<?>,TypeLiteral<?>> PRIMITIVE_TO_WRAPPER
  • Constructor Details

    • MoreTypes

      private MoreTypes()
  • Method Details

    • 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 a javax.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.

      Throws:
      ConfigurationException - if type contains a type variable
    • isFullySpecified

      private static boolean isFullySpecified(Type type)
      Returns true if type is free from type variables.
    • canonicalize

      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.
    • getRawType

      public static Class<?> getRawType(Type type)
    • equals

      public static boolean equals(Type a, Type b)
      Returns true if a and b are equal.
    • hashCodeOrZero

      private static int hashCodeOrZero(Object o)
    • typeToString

      public static String typeToString(Type type)
    • getGenericSupertype

      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>.
    • resolveTypeVariable

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

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

      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.
    • declaringClassOf

      private static Class<?> declaringClassOf(TypeVariable<?> typeVariable)
      Returns the declaring class of typeVariable, or null if it was not declared by a class.
    • checkNotPrimitive

      private static void checkNotPrimitive(Type type, String use)