Class TypeChecker


  • public class TypeChecker
    extends java.lang.Object
    This class contains various utilities for ensuring java type safety
    • Constructor Summary

      Constructors 
      Constructor Description
      TypeChecker()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.reflect.Type getArrayType​(java.lang.reflect.Type type)
      An array type can be a class that is an array or a GenericArrayType
      private static java.lang.Class<?> getBound​(java.lang.reflect.Type[] bounds)  
      private static java.lang.reflect.TypeVariable<?> getTypeVariable​(java.lang.reflect.Type type)  
      private static java.lang.reflect.WildcardType getWildcard​(java.lang.reflect.Type type)  
      private static boolean isActualType​(java.lang.reflect.Type type)
      An actual type is either a Class or a ParameterizedType
      private static boolean isActualTypeVariableSafe​(java.lang.Class<?> actual, java.lang.reflect.TypeVariable<?> tv)  
      private static boolean isArrayType​(java.lang.reflect.Type type)
      An array type can be a class that is an array or a GenericArrayType
      static boolean isRawTypeSafe​(java.lang.reflect.Type requiredType, java.lang.reflect.Type beanType)
      Returns true if the given requiredType is safely assignable from the given beanType.
      private static boolean isTypeVariable​(java.lang.reflect.Type type)  
      private static boolean isTypeVariableTypeVariableSafe​(java.lang.reflect.TypeVariable<?> rtv, java.lang.reflect.TypeVariable<?> btv)  
      private static boolean isWildcard​(java.lang.reflect.Type type)  
      private static boolean isWildcardActualSafe​(java.lang.reflect.WildcardType wildcard, java.lang.Class<?> actual)  
      private static boolean isWildcardTypeVariableSafe​(java.lang.reflect.WildcardType wildcard, java.lang.reflect.TypeVariable<?> tv)  
      • Methods inherited from class java.lang.Object

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

      • TypeChecker

        public TypeChecker()
    • Method Detail

      • isRawTypeSafe

        public static boolean isRawTypeSafe​(java.lang.reflect.Type requiredType,
                                            java.lang.reflect.Type beanType)
        Returns true if the given requiredType is safely assignable from the given beanType. In otherwords, if requiredType = beanType without any cast. It should be noted that this checker is using the CDI rules (as stated in CDI version 1.1 in section
        Parameters:
        requiredType - The type being assigned into
        beanType - the type being assigned
        Returns:
        true if things are type safe
      • isTypeVariableTypeVariableSafe

        private static boolean isTypeVariableTypeVariableSafe​(java.lang.reflect.TypeVariable<?> rtv,
                                                              java.lang.reflect.TypeVariable<?> btv)
      • isActualTypeVariableSafe

        private static boolean isActualTypeVariableSafe​(java.lang.Class<?> actual,
                                                        java.lang.reflect.TypeVariable<?> tv)
      • isWildcardTypeVariableSafe

        private static boolean isWildcardTypeVariableSafe​(java.lang.reflect.WildcardType wildcard,
                                                          java.lang.reflect.TypeVariable<?> tv)
      • getBound

        private static java.lang.Class<?> getBound​(java.lang.reflect.Type[] bounds)
      • isWildcardActualSafe

        private static boolean isWildcardActualSafe​(java.lang.reflect.WildcardType wildcard,
                                                    java.lang.Class<?> actual)
      • getWildcard

        private static java.lang.reflect.WildcardType getWildcard​(java.lang.reflect.Type type)
      • getTypeVariable

        private static java.lang.reflect.TypeVariable<?> getTypeVariable​(java.lang.reflect.Type type)
      • isWildcard

        private static boolean isWildcard​(java.lang.reflect.Type type)
      • isTypeVariable

        private static boolean isTypeVariable​(java.lang.reflect.Type type)
      • isActualType

        private static boolean isActualType​(java.lang.reflect.Type type)
        An actual type is either a Class or a ParameterizedType
        Parameters:
        type - The type to test
        Returns:
        true if this is an actual type
      • isArrayType

        private static boolean isArrayType​(java.lang.reflect.Type type)
        An array type can be a class that is an array or a GenericArrayType
        Parameters:
        type - The type to test
        Returns:
        true if this is an actual type
      • getArrayType

        private static java.lang.reflect.Type getArrayType​(java.lang.reflect.Type type)
        An array type can be a class that is an array or a GenericArrayType
        Parameters:
        type - The type to test
        Returns:
        true if this is an actual type