Class MoreTypes


  • public class MoreTypes
    extends java.lang.Object
    Static methods for working with types that we aren't publishing in the public Types API.
    Author:
    jessewilson@google.com (Jesse Wilson)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.reflect.Type[] EMPTY_TYPE_ARRAY  
    • 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 to Object.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.
      static boolean equals​(java.lang.reflect.Type a, java.lang.reflect.Type b)
      Returns true if a and b 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 for type.
      static java.lang.Class<?> getRawType​(java.lang.reflect.Type type)  
      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)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • EMPTY_TYPE_ARRAY

        public static final java.lang.reflect.Type[] EMPTY_TYPE_ARRAY
    • 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 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
      • 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 to Object.equals(). The returned type is Serializable.
      • 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 if a and b are equal.
      • 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 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 java.lang.reflect.Type resolveTypeVariable​(java.lang.reflect.Type type,
                                                                 java.lang.Class<?> rawType,
                                                                 java.lang.reflect.TypeVariable<?> unknown)