Class TypeKindUtils

java.lang.Object
org.checkerframework.javacutil.TypeKindUtils

public final class TypeKindUtils extends Object
A utility class that helps with TypeKinds.
  • Method Details

    • isIntegral

      public static boolean isIntegral(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
    • isIntegralNumeric

      public static boolean isIntegralNumeric(TypeKind typeKind)
      Return true if the argument is one of INT, SHORT, BYTE, LONG.
      Parameters:
      typeKind - the TypeKind to inspect
      Returns:
      true if typeKind is a primitive integral type kind, excluding CHAR which does not print as an integer
    • isFloatingPoint

      public static boolean isFloatingPoint(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(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 TypeKind primitiveOrBoxedToTypeKind(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
    • widenedNumericType

      public static TypeKind widenedNumericType(TypeMirror left, 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 TypeKind widenedNumericType(TypeKind a, 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(TypeKind from, 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(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(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