Package org.checkerframework.javacutil
Class TypeKindUtils
java.lang.Object
org.checkerframework.javacutil.TypeKindUtils
A utility class that helps with
TypeKind
s.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
The type of primitive conversion: narrowing, widening, or same. -
Method Summary
Modifier and TypeMethodDescriptionboxedToTypeKind
(TypeMirror type) Given a boxed primitive type, return the corresponding primitive type kind.getPrimitiveConversionKind
(TypeKind from, TypeKind to) Return the type of primitive conversion betweenfrom
andto
.static boolean
isFloatingPoint
(TypeKind typeKind) Return true if the argument is one of FLOAT, DOUBLE.static boolean
isIntegral
(TypeKind typeKind) Return true if the argument is one of INT, SHORT, BYTE, CHAR, LONG.static boolean
Returns true iff the argument is a primitive numeric type kind.static long
Returns the maximum value representable by the given integral primitive type.static long
Returns the minimum value representable by the given integral primitive type.Given a primitive type, return its kind.static TypeKind
Given two type kinds, return the type kind they are widened to, when an arithmetic operation is performed on them.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.
-
Method Details
-
isIntegral
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
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
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
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
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
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
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(TypeKind from, 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
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
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
-