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:
    • isDoubleSlotWildcard

      boolean isDoubleSlotWildcard()
      Wildcard type for any type whose concrete representation requires two slots.
      Returns:
    • isSmallIntegerWildcard

      boolean isSmallIntegerWildcard()
      Wildcard type for any small integer type (byte, char, short, int).
      Returns:
    • isGenericObjectWildcard

      boolean isGenericObjectWildcard()
      Wildcard type for any object.
      Returns:
    • 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:
    • getArrayElementType

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

      IJavaType getArrayTypeDimensionBelow()
      Get the type of an imaginary array with one dimension less than the current array.
      Example: [[[I -> [[I
      Returns:
    • 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 (internal form).
      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:
    • 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:
    • 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:
    • 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 -
      Returns:
    • 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 -
      Returns:
      success indicator
    • compareAndGetMostPrecise

      IJavaType compareAndGetMostPrecise(IJavaType other)
      Parameters:
      other -
      Returns:
    • isValidForRendering

      boolean isValidForRendering()
      Returns:
    • 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)
      Parameters:
      fctx - sink and formatting context
      dim0 -