Class ConstantValueWriter


  • public final class ConstantValueWriter
    extends ClassWriter.Element
    This class builds serializable ConstantValue attributes. These attributes are associated with final fields.

    After constructing a ConstantValueWriter, you must call setValueCPIndex.

    • Constructor Detail

      • ConstantValueWriter

        public ConstantValueWriter​(ClassWriter w)
        Build an empty writer.
        Throws:
        java.lang.IllegalArgumentException - if w is null
      • ConstantValueWriter

        public ConstantValueWriter​(ClassWriter w,
                                   long v)
        Build an writer for a 'long' constant value.
      • ConstantValueWriter

        public ConstantValueWriter​(ClassWriter w,
                                   int v)
        Build an writer for an 'int' constant value.
      • ConstantValueWriter

        public ConstantValueWriter​(ClassWriter w,
                                   float v)
        Build an writer for a 'float' constant value.
      • ConstantValueWriter

        public ConstantValueWriter​(ClassWriter w,
                                   double v)
        Build an writer for a 'double' constant value.
      • ConstantValueWriter

        public ConstantValueWriter​(ClassWriter w,
                                   java.lang.String v)
        Build an writer for a 'String' constant value.
    • Method Detail

      • getSize

        public int getSize()
        Specified by:
        getSize in class ClassWriter.Element
        Returns:
        the number of bytes that will be generated.
      • copyInto

        public int copyInto​(byte[] buf,
                            int offset)
                     throws java.lang.IllegalArgumentException
        Description copied from class: ClassWriter.Element
        Copy the bytes into 'buf' at offset 'offset'.
        Specified by:
        copyInto in class ClassWriter.Element
        Returns:
        the number of bytes copies, which must be equal to getSize()
        Throws:
        java.lang.IllegalArgumentException
      • setLong

        public void setLong​(long value)
        Set the constant value to a long.
      • setDouble

        public void setDouble​(double value)
        Set the constant value to a double.
      • setInt

        public void setInt​(int value)
        Set the constant value to an int.
      • setFloat

        public void setFloat​(float value)
        Set the constant value to a float.
      • setString

        public void setString​(java.lang.String value)
        Set the constant value to a String.
      • setValueCPIndex

        public void setValueCPIndex​(int index)
                             throws java.lang.IllegalArgumentException
        Set the index of the constant pool item holding the constant value.
        Throws:
        java.lang.IllegalArgumentException