Class TypeArguments


  • public final class TypeArguments
    extends java.lang.Object
    Utility methods for dealing with generic type arguments.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static interface  TypeArguments.Implicit
      Qualifier of bindings that should be treated as implicit.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static com.google.inject.TypeLiteral<?>[] NO_TYPE_LITERALS  
      private static com.google.inject.TypeLiteral<java.lang.Object> OBJECT_TYPE_LITERAL  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private TypeArguments()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static com.google.inject.TypeLiteral<?> expand​(java.lang.reflect.Type type)
      Expands wild-card types where possible, for example Bar from ? extends Bar.
      static com.google.inject.TypeLiteral<?>[] get​(com.google.inject.TypeLiteral<?> typeLiteral)
      Get all type arguments from a generic type, for example [Foo,Bar] from Map<Foo,Bar>.
      static com.google.inject.TypeLiteral<?> get​(com.google.inject.TypeLiteral<?> typeLiteral, int index)
      Get an indexed type argument from a generic type, for example Bar from Map<Foo,Bar>.
      static <T> com.google.inject.Key<T> implicitKey​(java.lang.Class<T> clazz)
      Creates a special binding key for the given implicit type.
      static boolean isAssignableFrom​(com.google.inject.TypeLiteral<?> superLiteral, com.google.inject.TypeLiteral<?> subLiteral)
      Determines if the sub-type can be converted to the generic super-type via an identity or widening conversion.
      private static boolean isAssignableFrom​(java.lang.reflect.Type[] superArgs, java.lang.reflect.Type[] subArgs)
      Determines whether the resolved sub-type arguments can be assigned to their generic super-type arguments.
      static boolean isConcrete​(com.google.inject.TypeLiteral<?> literal)
      Determines if the given generic type represents a concrete type.
      static boolean isConcrete​(java.lang.Class<?> clazz)
      Determines if the given raw type represents a concrete type.
      static boolean isImplicit​(com.google.inject.TypeLiteral<?> literal)
      Determines if the given generic type represents an implicit binding.
      static boolean isImplicit​(java.lang.Class<?> clazz)
      Determines if the given raw type represents an implicit binding.
      • Methods inherited from class java.lang.Object

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

      • OBJECT_TYPE_LITERAL

        private static final com.google.inject.TypeLiteral<java.lang.Object> OBJECT_TYPE_LITERAL
      • NO_TYPE_LITERALS

        private static final com.google.inject.TypeLiteral<?>[] NO_TYPE_LITERALS
    • Constructor Detail

      • TypeArguments

        private TypeArguments()
    • Method Detail

      • get

        public static com.google.inject.TypeLiteral<?>[] get​(com.google.inject.TypeLiteral<?> typeLiteral)
        Get all type arguments from a generic type, for example [Foo,Bar] from Map<Foo,Bar>.
        Parameters:
        typeLiteral - The generic type
        Returns:
        Array of type arguments
      • get

        public static com.google.inject.TypeLiteral<?> get​(com.google.inject.TypeLiteral<?> typeLiteral,
                                                           int index)
        Get an indexed type argument from a generic type, for example Bar from Map<Foo,Bar>.
        Parameters:
        typeLiteral - The generic type
        index - The argument index
        Returns:
        Indexed type argument; TypeLiteral<Object> if the given type is a raw class
      • isAssignableFrom

        public static boolean isAssignableFrom​(com.google.inject.TypeLiteral<?> superLiteral,
                                               com.google.inject.TypeLiteral<?> subLiteral)
        Determines if the sub-type can be converted to the generic super-type via an identity or widening conversion.
        Parameters:
        superLiteral - The generic super-type
        subLiteral - The generic sub-type
        Returns:
        true if the sub-type can be converted to the generic super-type; otherwise false
        See Also:
        Class.isAssignableFrom(Class)
      • isConcrete

        public static boolean isConcrete​(com.google.inject.TypeLiteral<?> literal)
        Determines if the given generic type represents a concrete type.
        Parameters:
        literal - The generic type
        Returns:
        true if the generic type is concrete; otherwise false
      • isConcrete

        public static boolean isConcrete​(java.lang.Class<?> clazz)
        Determines if the given raw type represents a concrete type.
        Parameters:
        clazz - The raw type
        Returns:
        true if the raw type is concrete; otherwise false
      • isImplicit

        public static boolean isImplicit​(com.google.inject.TypeLiteral<?> literal)
        Determines if the given generic type represents an implicit binding.
        Parameters:
        literal - The generic type
        Returns:
        true if the generic type is implicit; otherwise false
      • isImplicit

        public static boolean isImplicit​(java.lang.Class<?> clazz)
        Determines if the given raw type represents an implicit binding.
        Parameters:
        clazz - The raw type
        Returns:
        true if the raw type is implicit; otherwise false
      • implicitKey

        public static <T> com.google.inject.Key<T> implicitKey​(java.lang.Class<T> clazz)
        Creates a special binding key for the given implicit type.
        Parameters:
        clazz - The implicit type
        Returns:
        Implicit binding key
      • expand

        private static com.google.inject.TypeLiteral<?> expand​(java.lang.reflect.Type type)
        Expands wild-card types where possible, for example Bar from ? extends Bar.
        Parameters:
        type - The generic type
        Returns:
        Widened type that is still assignment-compatible with the original.
      • isAssignableFrom

        private static boolean isAssignableFrom​(java.lang.reflect.Type[] superArgs,
                                                java.lang.reflect.Type[] subArgs)
        Determines whether the resolved sub-type arguments can be assigned to their generic super-type arguments.
        Parameters:
        superArgs - The generic super-arguments
        subArgs - The resolved sub-arguments
        Returns:
        true if all the super-arguments have assignable resolved arguments; otherwise false