Class ElementValue

java.lang.Object
org.apache.bcel.classfile.ElementValue
Direct Known Subclasses:
AnnotationElementValue, ArrayElementValue, ClassElementValue, EnumElementValue, SimpleElementValue

public abstract class ElementValue extends Object
The element_value structure is documented at https://docs.oracle.com/javase/specs/jvms/se11/html/jvms-4.html#jvms-4.7.16.1
 element_value {
    u1 tag;
    union {
        u2 const_value_index;

        {   u2 type_name_index;
            u2 const_name_index;
        } enum_const_value;

        u2 class_info_index;

        annotation annotation_value;

        {   u2            num_values;
            element_value values[num_values];
        } array_value;
    } value;
}
Since:
6.0
  • Field Details

    • STRING

      public static final byte STRING
      Element value type: string.
      See Also:
    • ENUM_CONSTANT

      public static final byte ENUM_CONSTANT
      Element value type: enum constant.
      See Also:
    • CLASS

      public static final byte CLASS
      Element value type: class.
      See Also:
    • ANNOTATION

      public static final byte ANNOTATION
      Element value type: annotation.
      See Also:
    • ARRAY

      public static final byte ARRAY
      Element value type: array.
      See Also:
    • PRIMITIVE_INT

      public static final byte PRIMITIVE_INT
      Element value type: primitive int.
      See Also:
    • PRIMITIVE_BYTE

      public static final byte PRIMITIVE_BYTE
      Element value type: primitive byte.
      See Also:
    • PRIMITIVE_CHAR

      public static final byte PRIMITIVE_CHAR
      Element value type: primitive char.
      See Also:
    • PRIMITIVE_DOUBLE

      public static final byte PRIMITIVE_DOUBLE
      Element value type: primitive double.
      See Also:
    • PRIMITIVE_FLOAT

      public static final byte PRIMITIVE_FLOAT
      Element value type: primitive float.
      See Also:
    • PRIMITIVE_LONG

      public static final byte PRIMITIVE_LONG
      Element value type: primitive long.
      See Also:
    • PRIMITIVE_SHORT

      public static final byte PRIMITIVE_SHORT
      Element value type: primitive short.
      See Also:
    • PRIMITIVE_BOOLEAN

      public static final byte PRIMITIVE_BOOLEAN
      Element value type: primitive boolean.
      See Also:
    • EMPTY_ARRAY

      static final ElementValue[] EMPTY_ARRAY
      Empty array constant.
    • type

      @Deprecated protected int type
      Deprecated.
      (since 6.0) will be made private and final; do not access directly, use getter.
    • cpool

      @Deprecated protected ConstantPool cpool
      Deprecated.
      (since 6.0) will be made private and final; do not access directly, use getter.
  • Constructor Details

    • ElementValue

      protected ElementValue(int type, ConstantPool cpool)
      Constructs an ElementValue.
      Parameters:
      type - The element value type.
      cpool - The constant pool.
  • Method Details

    • readElementValue

      public static ElementValue readElementValue(DataInput input, ConstantPool cpool) throws IOException
      Reads an element_value as an ElementValue.
      Parameters:
      input - Raw data input.
      cpool - Constant pool.
      Returns:
      A new ElementValue.
      Throws:
      IOException - Thrown if an I/O error occurs.
    • readElementValue

      static ElementValue readElementValue(DataInput input, ConstantPool cpool, boolean isRuntimeVisible, int arrayNesting) throws IOException
      Throws:
      IOException
    • readElementValue

      public static ElementValue readElementValue(DataInput input, ConstantPool cpool, int arrayNesting) throws IOException
      Reads an element_value as an ElementValue.
      Parameters:
      input - Raw data input.
      cpool - Constant pool.
      arrayNesting - level of current array nesting.
      Returns:
      A new ElementValue.
      Throws:
      IOException - Thrown if an I/O error occurs.
      Since:
      6.7.0
    • dump

      public abstract void dump(DataOutputStream dos) throws IOException
      Dumps this element value to a DataOutputStream.
      Parameters:
      dos - The output stream.
      Throws:
      IOException - Thrown if an I/O error occurs.
    • getConstantPool

      final ConstantPool getConstantPool()
      Gets the constant pool.
      Returns:
      The constant pool.
      Since:
      6.0
    • getElementValueType

      public int getElementValueType()
      Gets the element value type.
      Returns:
      The element value type.
    • getType

      final int getType()
      Gets the type.
      Returns:
      The type.
      Since:
      6.0
    • stringifyValue

      public abstract String stringifyValue()
      Returns a string representation of the element value.
      Returns:
      A string representation of the element value.
    • toShortString

      public String toShortString()
      Returns a short string representation of the element value.
      Returns:
      A short string representation of the element value.
    • toString

      public String toString()
      Returns a string representation of the element value.
      Overrides:
      toString in class Object
      Returns:
      A string representation of the element value.