Class TypeUtils
- java.lang.Object
-
- com.tonic.analysis.source.ast.type.TypeUtils
-
public final class TypeUtils extends Object
Utility methods for type operations including boxing, unboxing, type checking, and common supertype computation.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static SourceTypebox(SourceType type)Maps a primitive to its wrapper class.static SourceTypecommonSupertype(SourceType a, SourceType b)Joins two types: primitives by numeric promotion, anything else to Object.static SourceTypegetElementType(SourceType type)static SourceTypegetRawType(SourceType type)static StringgetSimpleName(SourceType type)Renders a type without package qualification, keeping array brackets and dropping generic arguments.static booleanisArray(SourceType type)static booleanisAssignableTo(SourceType from, SourceType to)Decides assignability by identity, primitive widening, or a reference going to Object.static booleanisBoolean(SourceType type)static booleanisBoxedType(SourceType type)static booleanisFloatingPoint(SourceType type)static booleanisGeneric(SourceType type)static booleanisIntegral(SourceType type)static booleanisIntersection(SourceType type)static booleanisNumeric(SourceType type)static booleanisPrimitive(SourceType type)static booleanisReference(SourceType type)static booleanisUnion(SourceType type)static booleanisVoid(SourceType type)static booleanisWildcard(SourceType type)static SourceTypeunbox(SourceType type)Maps a wrapper class to its primitive.
-
-
-
Method Detail
-
isNumeric
public static boolean isNumeric(SourceType type)
- Parameters:
type- the type to test- Returns:
- true for any primitive except boolean
-
isIntegral
public static boolean isIntegral(SourceType type)
- Parameters:
type- the type to test- Returns:
- true for byte, short, char, int or long
-
isFloatingPoint
public static boolean isFloatingPoint(SourceType type)
- Parameters:
type- the type to test- Returns:
- true for float or double
-
isPrimitive
public static boolean isPrimitive(SourceType type)
- Parameters:
type- the type to test- Returns:
- true for a primitive type
-
isReference
public static boolean isReference(SourceType type)
- Parameters:
type- the type to test- Returns:
- true for a class, array or generic type
-
isArray
public static boolean isArray(SourceType type)
- Parameters:
type- the type to test- Returns:
- true for an array type
-
isVoid
public static boolean isVoid(SourceType type)
- Parameters:
type- the type to test- Returns:
- true for void
-
isBoolean
public static boolean isBoolean(SourceType type)
- Parameters:
type- the type to test- Returns:
- true for boolean
-
isBoxedType
public static boolean isBoxedType(SourceType type)
- Parameters:
type- the type to test- Returns:
- true for one of the eight wrapper classes
-
box
public static SourceType box(SourceType type)
Maps a primitive to its wrapper class.- Parameters:
type- the type to box- Returns:
- the wrapper type, or the input unchanged if it is not a primitive
-
unbox
public static SourceType unbox(SourceType type)
Maps a wrapper class to its primitive.- Parameters:
type- the type to unbox- Returns:
- the primitive type, or the input unchanged if it is not a wrapper
-
getElementType
public static SourceType getElementType(SourceType type)
- Parameters:
type- the array type to peel one dimension off- Returns:
- the element type, or null if the input is not an array
-
getRawType
public static SourceType getRawType(SourceType type)
- Parameters:
type- the type to erase generic arguments from- Returns:
- the raw type, or the input unchanged if it is not generic
-
commonSupertype
public static SourceType commonSupertype(SourceType a, SourceType b)
Joins two types: primitives by numeric promotion, anything else to Object.- Parameters:
a- the first type, or nullb- the second type, or null- Returns:
- the join, or whichever input is non-null when the other is null
-
isAssignableTo
public static boolean isAssignableTo(SourceType from, SourceType to)
Decides assignability by identity, primitive widening, or a reference going to Object.- Parameters:
from- the source typeto- the target type- Returns:
- true if the assignment is known to be allowed
-
isGeneric
public static boolean isGeneric(SourceType type)
- Parameters:
type- the type to test- Returns:
- true for a parameterized type
-
isWildcard
public static boolean isWildcard(SourceType type)
- Parameters:
type- the type to test- Returns:
- true for a wildcard type argument
-
isIntersection
public static boolean isIntersection(SourceType type)
- Parameters:
type- the type to test- Returns:
- true for an intersection type
-
isUnion
public static boolean isUnion(SourceType type)
- Parameters:
type- the type to test- Returns:
- true for a union type, as written in a multi-catch
-
getSimpleName
public static String getSimpleName(SourceType type)
Renders a type without package qualification, keeping array brackets and dropping generic arguments.- Parameters:
type- the type to name- Returns:
- the unqualified name
-
-