Interface TypeInfo

All Known Subinterfaces:
ParameterizedTypeInfo, VariableTypeInfo, WildcardTypeInfo
All Known Implementing Classes:
ArrayTypeInfo, BasicClassTypeInfo, ClassTypeInfo, EnumTypeInfo, InterfaceTypeInfo, NoTypeInfo, ParameterizedTypeInfoImpl, PrimitiveClassTypeInfo, TypeInfoBase, VariableTypeInfoImpl

public interface TypeInfo
A representation of Java type, aiming at preserving more type information than what a Class can provide

Note: using null is not recommended, NONE should be used instead

See Also:
  • Field Details

    • NONE

      static final TypeInfo NONE
    • OBJECT

      static final TypeInfo OBJECT
      use isObjectExact() to determine whether a type represents a Object class, using `typeInfo == TypeInfo.OBJECT` might cause problem with VariableTypeInfo
    • OBJECT_ARRAY

      static final TypeInfo OBJECT_ARRAY
    • PRIMITIVE_VOID

      static final TypeInfo PRIMITIVE_VOID
    • PRIMITIVE_BOOLEAN

      static final TypeInfo PRIMITIVE_BOOLEAN
    • PRIMITIVE_BYTE

      static final TypeInfo PRIMITIVE_BYTE
    • PRIMITIVE_SHORT

      static final TypeInfo PRIMITIVE_SHORT
    • PRIMITIVE_INT

      static final TypeInfo PRIMITIVE_INT
    • PRIMITIVE_LONG

      static final TypeInfo PRIMITIVE_LONG
    • PRIMITIVE_FLOAT

      static final TypeInfo PRIMITIVE_FLOAT
    • PRIMITIVE_DOUBLE

      static final TypeInfo PRIMITIVE_DOUBLE
    • PRIMITIVE_CHARACTER

      static final TypeInfo PRIMITIVE_CHARACTER
    • VOID

      static final TypeInfo VOID
    • BOOLEAN

      static final TypeInfo BOOLEAN
    • BYTE

      static final TypeInfo BYTE
    • SHORT

      static final TypeInfo SHORT
    • INT

      static final TypeInfo INT
    • LONG

      static final TypeInfo LONG
    • FLOAT

      static final TypeInfo FLOAT
    • DOUBLE

      static final TypeInfo DOUBLE
    • CHARACTER

      static final TypeInfo CHARACTER
    • NUMBER

      static final TypeInfo NUMBER
    • STRING

      static final TypeInfo STRING
    • STRING_ARRAY

      static final TypeInfo STRING_ARRAY
    • RAW_CLASS

      static final TypeInfo RAW_CLASS
    • DATE

      static final TypeInfo DATE
    • RUNNABLE

      static final TypeInfo RUNNABLE
    • RAW_CONSUMER

      static final TypeInfo RAW_CONSUMER
    • RAW_SUPPLIER

      static final TypeInfo RAW_SUPPLIER
    • RAW_FUNCTION

      static final TypeInfo RAW_FUNCTION
    • RAW_PREDICATE

      static final TypeInfo RAW_PREDICATE
    • RAW_LIST

      static final TypeInfo RAW_LIST
    • RAW_SET

      static final TypeInfo RAW_SET
    • RAW_MAP

      static final TypeInfo RAW_MAP
    • RAW_OPTIONAL

      static final TypeInfo RAW_OPTIONAL
    • RAW_ENUM_SET

      static final TypeInfo RAW_ENUM_SET
    • BIG_INT

      static final TypeInfo BIG_INT
  • Method Details

    • asClass

      Class<?> asClass()
      Get the Class object represented by this TypeInfo. For a Type object, the TypeInfo object created from the Type object should return the exact same class as the one after Java erased its generic type info
    • param

      default TypeInfo param(int index)
      Example:

      1. for Map<String, Integer>, param(-1) == NONE, param(0) == STRING, param(1) == INT, param(2) == NONE

      2. for Map (raw usage of generic class) or Integer (not generic class), param(anyNumberHere) == NONE

      Returns:
      the actual type parameter at provided index, or NONE if:

      1. index not in valid range, or

      2. the TypeInfo itself is not representing a ParameterizedType

      See Also:
    • is

      default boolean is(Class<?> c)
      Returns:
      true if this TypeInfo represents the same class as the Class parameter, false otherwise
    • isNot

      default boolean isNot(Class<?> c)
      Returns:
      true if this TypeInfo does NOT represent the same class as the Class parameter, false otherwise
    • isPrimitive

      default boolean isPrimitive()
      See Also:
    • shouldReplace

      default boolean shouldReplace()
      Returns:
      true if this type contains too little information (e.g. being NONE) and should be replaced by actual object type, false otherwise
    • toString

      String toString()
      Overrides:
      toString in class Object
      See Also:
    • toString

      String toString(TypeFormatContext ctx)
    • getComponentType

      default TypeInfo getComponentType()
      See Also:
    • newArray

      default Object newArray(int length)
      get an array whose element type is the caller TypeInfo
    • isInterface

      default boolean isInterface()
      See Also:
    • isFunctionalInterface

      default boolean isFunctionalInterface()
      See Also:
    • isEnum

      default boolean isEnum()
      See Also:
    • enumConstants

      default List<Object> enumConstants()
      See Also:
    • createDefaultValue

      default Object createDefaultValue()
    • isVoid

      default boolean isVoid()
      Returns:
      true if this TypeInfo represents Void class or void class
    • isBoolean

      default boolean isBoolean()
      Returns:
      true if this TypeInfo represents Boolean class or boolean class
    • isNumber

      default boolean isNumber()
      Returns:
      true if this TypeInfo represents a type assignable to Number class
      See Also:
    • isByte

      default boolean isByte()
      Returns:
      true if this TypeInfo represents Byte class or byte class
    • isShort

      default boolean isShort()
      Returns:
      true if this TypeInfo represents Short class or short class
    • isInt

      default boolean isInt()
      Returns:
      true if this TypeInfo represents Integer class or int class
    • isLong

      default boolean isLong()
      Returns:
      true if this TypeInfo represents Long class or long class
    • isFloat

      default boolean isFloat()
      Returns:
      true if this TypeInfo represents Float class or float class
    • isDouble

      default boolean isDouble()
      Returns:
      true if this TypeInfo represents Double class or double class
    • isCharacter

      default boolean isCharacter()
      Returns:
      true if this TypeInfo represents Character class or char class
    • isString

      default boolean isString()
      Returns:
      true if this TypeInfo represents String class
    • isObjectExact

      default boolean isObjectExact()
      Returns:
      true if this TypeInfo represents Object class
    • isArray

      default boolean isArray()
      See Also:
    • isAssignableFrom

      default boolean isAssignableFrom(TypeInfo another)
      Returns:
      true if the caller TypeInfo represents the super class of the class represented by another TypeInfo
      See Also:
    • isInstance

      default boolean isInstance(Object o)
      Returns:
      true if o is an instance of this class represented by the caller TypeInfo
      See Also:
    • getTypeTag

      default int getTypeTag()
      See Also:
    • consolidate

      default TypeInfo consolidate(Map<VariableTypeInfo,TypeInfo> mapping)