Class ElementValue

  • Direct Known Subclasses:
    AnnotationElementValue, ArrayElementValue, ClassElementValue, EnumElementValue, SimpleElementValue

    public abstract class ElementValue
    extends java.lang.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 Summary

      Fields 
      Modifier and Type Field Description
      static byte ANNOTATION
      Element value type: annotation.
      static byte ARRAY
      Element value type: array.
      static byte CLASS
      Element value type: class.
      protected ConstantPool cpool
      Deprecated.
      (since 6.0) will be made private and final; do not access directly, use getter.
      static byte ENUM_CONSTANT
      Element value type: enum constant.
      static byte PRIMITIVE_BOOLEAN
      Element value type: primitive boolean.
      static byte PRIMITIVE_BYTE
      Element value type: primitive byte.
      static byte PRIMITIVE_CHAR
      Element value type: primitive char.
      static byte PRIMITIVE_DOUBLE
      Element value type: primitive double.
      static byte PRIMITIVE_FLOAT
      Element value type: primitive float.
      static byte PRIMITIVE_INT
      Element value type: primitive int.
      static byte PRIMITIVE_LONG
      Element value type: primitive long.
      static byte PRIMITIVE_SHORT
      Element value type: primitive short.
      static byte STRING
      Element value type: string.
      protected int type
      Deprecated.
      (since 6.0) will be made private and final; do not access directly, use getter.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected ElementValue​(int type, ConstantPool cpool)
      Constructs an ElementValue.
    • Constructor Detail

      • ElementValue

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

      • readElementValue

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

        public static ElementValue readElementValue​(java.io.DataInput input,
                                                    ConstantPool cpool,
                                                    int arrayNesting)
                                             throws java.io.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:
        java.io.IOException - Thrown if an I/O error occurs.
        Since:
        6.7.0
      • dump

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

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

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

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

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