Interface IJavaConstant

All Superinterfaces:
IJavaElement, IJavaExpression

@Ser public interface IJavaConstant extends IJavaExpression
Java AST interface to represent a literal or constant value.

Constant types are: the eight primitive types (boolean, byte, char, short, int, long, float, double) and the string type.

Rendering of a literal may be customized (overridden).

  • Method Details

    • setName

      void setName(String name)
      Set a custom name to override rendering. This is only applicable to non-String immediates.
      Parameters:
      name - a name override, or null
    • getName

      String getName()
      Retrieve the optional custom name to override rendering. This is only applicable to non-String immediates.
      Returns:
      a name override, or null
    • getType

      IJavaType getType()
      Retrieve the constant type.
      Returns:
      the type signature, null if the constant is 'null'
    • isNull

      boolean isNull()
      Determine if the constant is the 'null' literal.
      Returns:
      true if the constant is 'null'
    • isString

      boolean isString()
      Determine if the constant is of type java.lang.String. Convenience routine.
      Returns:
      true if the constant is a Java string
    • getBoolean

      boolean getBoolean()
      Retrieve the boolean value.
      Returns:
      the value
      Throws:
      IllegalStateException - if the constant is not a boolean
    • getByte

      byte getByte()
      Retrieve the byte value.
      Returns:
      the byte value
      Throws:
      IllegalStateException - if the constant is not a byte
    • getChar

      char getChar()
      Retrieve the character value.
      Returns:
      the character value
      Throws:
      IllegalStateException - if the constant is not a char
    • getShort

      short getShort()
      Retrieve the short value.
      Returns:
      the short value
      Throws:
      IllegalStateException - if the constant is not a short
    • getInt

      int getInt()
      Retrieve the integer value.
      Returns:
      the integer value
      Throws:
      IllegalStateException - if the constant is not an int
    • getLong

      long getLong()
      Retrieve the long value.
      Returns:
      the long value
      Throws:
      IllegalStateException - if the constant is not a long
    • getFloat

      float getFloat()
      Retrieve the float value.
      Returns:
      the float value
      Throws:
      IllegalStateException - if the constant is not a float
    • getDouble

      double getDouble()
      Retrieve the double value.
      Returns:
      the double value
      Throws:
      IllegalStateException - if the constant is not a double
    • getString

      String getString()
      Retrieve the string value.
      Returns:
      the string value
      Throws:
      IllegalStateException - if the constant is not a string
    • isTrue

      boolean isTrue()
      Determine if a constant is the true literal. This method does not raise.
      Returns:
      true if the constant is a boolean true, false otherwise
    • isFalse

      boolean isFalse()
      Determine if a constant is the false literal. This method does not raise.
      Returns:
      true if the constant is a boolean false, false otherwise
    • isZero

      boolean isZero()
      Determine if a constant is a numeric literal whose value is 0. This method does not raise.
      Returns:
      true if the constant is a numeric literal whose value is 0, false otherwise
    • isOne

      boolean isOne()
      Determine if a constant is a numeric literal whose value is 1. This method does not raise.
      Returns:
      true if the constant is a numeric literal whose value is 1, false otherwise
    • isMinusOne

      boolean isMinusOne()
      Determine if a constant is a numeric literal whose value is -1. This method does not raise.
      Returns:
      true if the constant is a numeric literal whose value is -1, false otherwise
    • isPositive

      boolean isPositive()
      Determine if a constant is a numeric literal whose value is strictly positive. This method does not raise.
      Returns:
      true if the constant is a numeric literal whose value is strictly positive, false otherwise
    • isNegative

      boolean isNegative()
      Determine if a constant is a numeric literal whose value is strictly negative. This method does not raise.
      Returns:
      true if the constant is a numeric literal whose value is strictly negative, false otherwise
    • duplicate

      IJavaConstant duplicate()
      Description copied from interface: IJavaElement
      Duplicate this element.
      Specified by:
      duplicate in interface IJavaElement
      Specified by:
      duplicate in interface IJavaExpression
      Returns:
      a (possibly) duplicated object of the same type