Interface IJavaType


@Ser public interface IJavaType
This interface is used to define a Java type.

Those objects can represent exact types or wildcard (imprecise) types. They are used at both the IR and at the AST level.

  • Field Details

  • Method Details

    • getFactory

      IJavaTypeFactory getFactory()
      Returns:
      the type factory that created this type object
    • isVoid

      boolean isVoid()
      Returns:
      true if this "type" is void (i.e. not a type, or the illegal type)
    • isPrimitive

      boolean isPrimitive()
      Returns:
      true if this type is a primitive
    • isBoolean

      boolean isBoolean()
      Returns:
      true if this type is the boolean primitive
    • isByte

      boolean isByte()
      Returns:
      true if this type is the byte primitive
    • isChar

      boolean isChar()
      Returns:
      true if this type is the char primitive
    • isShort

      boolean isShort()
      Returns:
      true if this type is the short primitive
    • isInt

      boolean isInt()
      Returns:
      true if this type is the int primitive
    • isLong

      boolean isLong()
      Returns:
      true if this type is the long primitive
    • isFloat

      boolean isFloat()
      Returns:
      true if this type is the float primitive
    • isDouble

      boolean isDouble()
      Returns:
      true if this type is the double primitive
    • isSingleSlotWildcard

      boolean isSingleSlotWildcard()
      Wildcard type for any type whose concrete representation requires one slot.
      Returns:
      true if this type is the single-slot wildcard
    • isDoubleSlotWildcard

      boolean isDoubleSlotWildcard()
      Wildcard type for any type whose concrete representation requires two slots.
      Returns:
      true if this type is the double-slot wildcard
    • isSmallIntegerWildcard

      boolean isSmallIntegerWildcard()
      Wildcard type for any small integer type (byte, char, short, int).
      Returns:
      true if this type is the small-integer wildcard
    • isGenericObjectWildcard

      boolean isGenericObjectWildcard()
      Wildcard type for any object.
      Returns:
      true if this type is the generic object wildcard
    • isObjectWildcard

      boolean isObjectWildcard()
      Returns:
      true if this type is a specialization or generalization wildcard
    • isObjectWildcardExtends

      boolean isObjectWildcardExtends()
      Returns:
      true if this type is a specialization wildcard: ? extends SomeType
    • isObjectWildcardSuper

      boolean isObjectWildcardSuper()
      Returns:
      true if this type is a generalization wildcard: ? super SomeType
    • isObject

      boolean isObject()
      Returns:
      true if this type is an object type: could be the generic-object wildcard, a specific class or interface type, an array type
    • isClassOrInterface

      boolean isClassOrInterface()
      Returns:
      true if this type is a class or interface type (not an array type, not a primitive)
    • isArray

      boolean isArray()
      Returns:
      true if this type is an array type
    • getDimensions

      int getDimensions()
      Get the dimension count of an array type. This method will throw if this type is not an array.
      Returns:
      the number of array dimensions
    • getArrayElementType

      IJavaType getArrayElementType()
      Get the simplest type of an array type, that is, the type of a 0-dimension array.
      Example: [[[I -> I
      Returns:
      the base element type
    • getArrayTypeDimensionBelow

      IJavaType getArrayTypeDimensionBelow()
      Get the type of an imaginary array with one dimension less than the current array.
      Example: [[[I -> [[I
      Returns:
      the array type one dimension below this type
    • getName

      String getName()
      Get the internal representation. Never fail. If the type is a wildcard reference, the type reference without wildcard is returned (example: on type ? extends T, this method will return "T").
      Returns:
      internal representation of the type name
    • getSignature

      String getSignature()
      Get the Java type name (original internal form).
      Returns:
      internal type name, using the L.../...; form
    • getSignature

      String getSignature(boolean doNotRenderWildcard)
      Get the Java type name (original internal form).
      Parameters:
      doNotRenderWildcard - true to omit wildcard markers from the returned signature
      Returns:
      internal type name, using the L.../...; form
    • isJavaLangObject

      boolean isJavaLangObject()
      Convenience method.
      Returns:
      true if this type is java.lang.Object.
    • isJavaLangClass

      boolean isJavaLangClass()
      Convenience method.
      Returns:
      true if this type is java.lang.Class.
    • isJavaLangString

      boolean isJavaLangString()
      Convenience method.
      Returns:
      true if this type is java.lang.String.
    • isFloatingPointType

      boolean isFloatingPointType()
      Returns:
      true if float or double
    • getEncodingBitsize

      int getEncodingBitsize()
      Returns:
      the memory bitsize required to store such a type (or type-reference, for an object type), such as 1 for a boolean, 8 for a char, 16 for a short/char32 for an int/float/ref, 64 for a long/double, etc.
    • isSingleSlot

      boolean isSingleSlot()
      Returns:
      true if the concrete representation of this type is stored in a single slot
    • isDoubleSlot

      boolean isDoubleSlot()
      Returns:
      true if the concrete representation of this type is stored in a two slots
    • isLegal

      boolean isLegal()
      Returns:
      true if non-void
    • isUndefined

      boolean isUndefined()
      Returns:
      true if void, the single-slot, or the double-slot wildcard
    • isDefined

      boolean isDefined()
      Returns:
      true if anything but void or the single-slot or double-slot wildcard
    • isDetermined

      boolean isDetermined()
      Returns:
      true if anything but void or a wildcard type
    • isWildcard

      boolean isWildcard()
      Returns:
      true if small-int wildcard, single-slot wildcard, double-slot wildcard, generic-object wildcard
    • asWildcardSup

      IJavaType asWildcardSup()
      Retrieve a "super" wildcard version of this type.

      Watch out! For super-wildcards, this method returns the same type. For extends-wildcards, this method does NOT return the generic object type. It returns the super-wildcard of the non-wildcard type.

      Returns:
      the super-wildcard version of this type
    • asWildcardExt

      IJavaType asWildcardExt()
      Retrieve an "extends" wildcard version of this type.

      Watch out! For extends-wildcards, this method returns the same type. For super-wildcards, this method does NOT return the generic object type. It returns the extends-wildcard of the non-wildcard type.

      Returns:
      the extends-wildcard version of this type
    • getSlotCount

      int getSlotCount()
      This method will throw if called on the void type!
      Returns:
      1 or 2
    • isSmallInt

      boolean isSmallInt()
      Returns:
      true for BYTE, CHAR, SHORT, INT or SMALLINT (wildcard type for any of the previous small-integer types)
    • isSpecificInteger

      boolean isSpecificInteger()
      Returns:
      true for byte, char, short, int or long (note: the small-int wildcard is NOT a specific integer)
    • isGenericInteger

      boolean isGenericInteger()
      isSpecificInteger() + BOOLEAN and the generic type SMALLINT.
      Returns:
      true if this type is a generic integer type
    • compareSimple

      boolean compareSimple(IJavaType t)
      Simple comparison: are both types objects (incl. arrays) or ints, etc.

      Note 1: comparing a String to an ArrayList or an array of int would return true.
      Note 2: comparing an int to a smallint would return false.

      Parameters:
      t - type to compare with this one
      Returns:
      true if both types have the same simple category
    • canSetType

      boolean canSetType(IJavaType otherType, boolean useExternalTypeInfo)
      Determine whether this type could be replaced by (as in, specialized) the provided other type. Unless the other type is the same as this type, this method will fail if this type is not a wildcard.

      For objects, do not confuse this method with type hierarchy checkers. Example: if this type is List, this method will return false if the other type is e.g. ArrayList, because List is already a specific type. However, if this type were to be ?_extends_List, the method would return true for any type extending List, including List itself or ArrayList.

      Parameters:
      otherType - another type
      useExternalTypeInfo - true to use external hierarchy/type information when available
      Returns:
      success indicator
    • compareAndGetMostPrecise

      IJavaType compareAndGetMostPrecise(IJavaType other)
      Compare this type with another one and return the most precise type if it can be determined.
      Parameters:
      other - type to compare with this one
      Returns:
      the most precise type, or null if no precise type can be selected
    • isValidForRendering

      boolean isValidForRendering()
      Determine whether this type can be rendered as Java source.
      Returns:
      true if this type is valid for rendering
    • format

      void format(DFormattingContext fctx)
      Get a programmer's representation for that type. Examples:
      - top-level class Lcom/foo/B$la; becomes com.foo.B$la
      - inner class Lcom/foo/Farm$Cow; becomes com.foo.Farm.Cow
      Parameters:
      fctx - sink and formatting context
    • formatArray

      void formatArray(DFormattingContext fctx, IDExpression dim0)
      Format this type as an array type, optionally with the first-dimension expression.
      Parameters:
      fctx - sink and formatting context
      dim0 - first-dimension expression, or null