Class CodeWriter


  • public final class CodeWriter
    extends ClassWriter.Element
    This class helps emit Code elements.

    After constructing a CodeWriter, at least the max stack, max locals and bytecode bytes must be set before it can be used.

    • Constructor Summary

      Constructors 
      Constructor Description
      CodeWriter​(ClassWriter w)
      Build an empty serializable Code attribute.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int copyInto​(byte[] buf, int offset)
      Copy the bytes into 'buf' at offset 'offset'.
      int getCodeLength()  
      int getSize()  
      void setAttributes​(ClassWriter.Element[] attributes)
      Set the attributes of this Code.
      void setCode​(byte[] code)
      Set the bytecodes for this Code attribute.
      void setMaxLocals​(int maxLocals)
      Set the maximum number of local variable space used, in words, by this Code.
      void setMaxStack​(int maxStack)
      Set the maximum stack size, in words, in this Code.
      void setRawHandlers​(int[] exnHandlers)
      Set the raw handler data for this Code attribute.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CodeWriter

        public CodeWriter​(ClassWriter w)
        Build an empty serializable Code attribute.
        Throws:
        java.lang.IllegalArgumentException - if w is null
    • Method Detail

      • getCodeLength

        public int getCodeLength()
                          throws java.lang.IllegalStateException
        Throws:
        java.lang.IllegalStateException
      • getSize

        public int getSize()
                    throws java.lang.IllegalArgumentException
        Specified by:
        getSize in class ClassWriter.Element
        Returns:
        the number of bytes that will be generated.
        Throws:
        java.lang.IllegalArgumentException
      • 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
      • setCode

        public void setCode​(byte[] code)
                     throws java.lang.IllegalArgumentException
        Set the bytecodes for this Code attribute.
        Throws:
        java.lang.IllegalArgumentException - if code is null
      • setRawHandlers

        public void setRawHandlers​(int[] exnHandlers)
        Set the raw handler data for this Code attribute.
        Parameters:
        exnHandlers - a flattened sequence of (startPC, endPC, catchClassIndex, catchPC) tuples
        Throws:
        java.lang.IllegalArgumentException - if exnHandlers is null
      • setMaxLocals

        public void setMaxLocals​(int maxLocals)
        Set the maximum number of local variable space used, in words, by this Code.
      • setMaxStack

        public void setMaxStack​(int maxStack)
        Set the maximum stack size, in words, in this Code.
      • setAttributes

        public void setAttributes​(ClassWriter.Element[] attributes)
        Set the attributes of this Code.