Package org.checkerframework.javacutil
Class TypeKindUtils
- java.lang.Object
-
- org.checkerframework.javacutil.TypeKindUtils
-
public final class TypeKindUtils extends java.lang.Object
A utility class that helps withTypeKind
s.
-
-
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 betweenfrom
andto
.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.
-
-
-
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 aTypeKind
because creating aTypeMirror
requires aTypes
object from theProcessingEnvironment
.- Parameters:
left
- a type mirrorright
- 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 kindb
- 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 betweenfrom
andto
.The narrowing conversions include both short to char and char to short.
- Parameters:
from
- a primitive typeto
- a primitive type- Returns:
- the type of primitive conversion between
from
andto
-
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
-
-