Package org.checkerframework.javacutil
Class TypeKindUtils
java.lang.Object
org.checkerframework.javacutil.TypeKindUtils
A utility class that helps with
TypeKinds.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe type of primitive conversion: narrowing, widening, or same. -
Method Summary
Modifier and TypeMethodDescriptiongetPrimitiveConversionKind(TypeKind from, TypeKind to) Returns the type of primitive conversion betweenfromandto.static booleanisFloatingPoint(TypeKind typeKind) Returns true if the argument is one of FLOAT, DOUBLE.static booleanisIntegral(TypeKind typeKind) Returns true if the argument is one of INT, SHORT, BYTE, CHAR, LONG.static booleanisIntegralNumeric(TypeKind typeKind) Returns true if the argument is one of INT, SHORT, BYTE, LONG.static booleanReturns true iff the argument is a primitive numeric type kind.static longReturns the maximum value representable by the given integral primitive type.static longReturns the minimum value representable by the given integral primitive type.Given a primitive type, return its kind.static TypeKindGiven two type kinds, return the type kind they are widened to, when an arithmetic operation is performed on them.static TypeKindwidenedNumericType(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
Returns 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
Returns 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
Returns 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
-
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 aTypeKindbecause creating aTypeMirrorrequires aTypesobject 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) Returns the type of primitive conversion betweenfromandto.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
fromandto
-
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
-