Class TypeKindUtils


  • public final class TypeKindUtils
    extends java.lang.Object
    A utility class that helps with TypeKinds.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  TypeKindUtils.PrimitiveConversionKind
      The type of primitive conversion: narrowing, widening, or same.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static @Nullable javax.lang.model.type.TypeKind boxedToTypeKind​(javax.lang.model.type.TypeMirror type)
      Given a boxed primitive type, return the corresponding primitive type kind.
      static TypeKindUtils.PrimitiveConversionKind getPrimitiveConversionKind​(javax.lang.model.type.TypeKind from, javax.lang.model.type.TypeKind to)
      Return the type of primitive conversion between from and to.
      static boolean isFloatingPoint​(javax.lang.model.type.TypeKind typeKind)
      Return true if the argument is one of FLOAT, DOUBLE.
      static boolean isIntegral​(javax.lang.model.type.TypeKind typeKind)
      Return true if the argument is one of INT, SHORT, BYTE, CHAR, LONG.
      static boolean isNumeric​(javax.lang.model.type.TypeKind typeKind)
      Returns true iff the argument is a primitive numeric type kind.
      static long maxValue​(javax.lang.model.type.TypeKind tk)
      Returns the maximum value representable by the given integral primitive type.
      static long minValue​(javax.lang.model.type.TypeKind tk)
      Returns the minimum value representable by the given integral primitive type.
      static @Nullable javax.lang.model.type.TypeKind primitiveOrBoxedToTypeKind​(javax.lang.model.type.TypeMirror type)
      Given a primitive type, return its kind.
      static javax.lang.model.type.TypeKind widenedNumericType​(javax.lang.model.type.TypeKind a, javax.lang.model.type.TypeKind b)
      Given two type kinds, return the type kind they are widened to, when an arithmetic operation is performed on them.
      static javax.lang.model.type.TypeKind widenedNumericType​(javax.lang.model.type.TypeMirror left, javax.lang.model.type.TypeMirror right)
      Returns the widened numeric type for an arithmetic operation performed on a value of the left type and the right type.
      • Methods inherited from class java.lang.Object

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

      • isIntegral

        public static boolean isIntegral​(javax.lang.model.type.TypeKind typeKind)
        Return true if the argument is one of INT, SHORT, BYTE, CHAR, LONG.
        Parameters:
        typeKind - the TypeKind to inspect
        Returns:
        true if typeKind is a primitive integral type kind
      • isFloatingPoint

        public static boolean isFloatingPoint​(javax.lang.model.type.TypeKind typeKind)
        Return true if the argument is one of FLOAT, DOUBLE.
        Parameters:
        typeKind - the TypeKind to inspect
        Returns:
        true if typeKind is a primitive floating point type kind
      • isNumeric

        public static boolean isNumeric​(javax.lang.model.type.TypeKind typeKind)
        Returns true iff the argument is a primitive numeric type kind.
        Parameters:
        typeKind - a type kind
        Returns:
        true if the argument is a primitive numeric type kind
      • primitiveOrBoxedToTypeKind

        public static @Nullable javax.lang.model.type.TypeKind primitiveOrBoxedToTypeKind​(javax.lang.model.type.TypeMirror type)
        Given a primitive type, return its kind. Given a boxed primitive type, return the corresponding primitive type kind. Otherwise, return null.
        Parameters:
        type - a primitive or boxed primitive type
        Returns:
        a primitive type kind, or null
      • boxedToTypeKind

        public static @Nullable javax.lang.model.type.TypeKind boxedToTypeKind​(javax.lang.model.type.TypeMirror type)
        Given a boxed primitive type, return the corresponding primitive type kind. Otherwise, return null.
        Parameters:
        type - a boxed primitive type
        Returns:
        a primitive type kind, or null
      • widenedNumericType

        public static javax.lang.model.type.TypeKind widenedNumericType​(javax.lang.model.type.TypeMirror left,
                                                                        javax.lang.model.type.TypeMirror right)
        Returns the widened numeric type for an arithmetic operation performed on a value of the left type and the right type. Defined in JLS 5.6.2. We return a TypeKind because creating a TypeMirror requires a Types object from the ProcessingEnvironment.
        Parameters:
        left - a type mirror
        right - a type mirror
        Returns:
        the result of widening numeric conversion, or NONE when the conversion cannot be performed
      • widenedNumericType

        public static javax.lang.model.type.TypeKind widenedNumericType​(javax.lang.model.type.TypeKind a,
                                                                        javax.lang.model.type.TypeKind b)
        Given two type kinds, return the type kind they are widened to, when an arithmetic operation is performed on them. Defined in JLS 5.6.2.
        Parameters:
        a - a type kind
        b - a type kind
        Returns:
        the type kind to which they are widened, when an operation is performed on them
      • getPrimitiveConversionKind

        public static TypeKindUtils.PrimitiveConversionKind getPrimitiveConversionKind​(javax.lang.model.type.TypeKind from,
                                                                                       javax.lang.model.type.TypeKind to)
        Return the type of primitive conversion between from and to.

        The narrowing conversions include both short to char and char to short.

        Parameters:
        from - a primitive type
        to - a primitive type
        Returns:
        the type of primitive conversion between from and to
      • minValue

        public static long minValue​(javax.lang.model.type.TypeKind tk)
        Returns the minimum value representable by the given integral primitive type.
        Parameters:
        tk - a primitive type kind
        Returns:
        the minimum value representable by the given integral primitive type
      • maxValue

        public static long maxValue​(javax.lang.model.type.TypeKind tk)
        Returns the maximum value representable by the given integral primitive type.
        Parameters:
        tk - a primitive type kind
        Returns:
        the maximum value representable by the given integral primitive type