Class CodeAttribute


  • public class CodeAttribute
    extends Attribute
    The Code attribute: a method's bytecode, stack/local sizes, exception table, and nested attributes.
    • Constructor Detail

      • CodeAttribute

        public CodeAttribute​(String name,
                             MemberEntry parent,
                             int nameIndex,
                             int length)
        Creates the attribute shell for parsing, attached to a member.
        Parameters:
        name - the attribute name
        parent - the member the attribute belongs to
        nameIndex - constant-pool index of the name Utf8
        length - the attribute length in bytes
      • CodeAttribute

        public CodeAttribute​(String name,
                             ClassFile parent,
                             int nameIndex,
                             int length)
        Creates the attribute shell for parsing, attached to a class.
        Parameters:
        name - the attribute name
        parent - the class the attribute belongs to
        nameIndex - constant-pool index of the name Utf8
        length - the attribute length in bytes
    • Method Detail

      • getMaxStack

        public int getMaxStack()
        Returns:
        the max stack
      • getMaxLocals

        public int getMaxLocals()
        Returns:
        the max locals
      • getCode

        public byte[] getCode()
        Returns:
        the code
      • getAttributes

        public List<Attribute> getAttributes()
        Returns:
        the attributes
      • setMaxStack

        public void setMaxStack​(int maxStack)
        Parameters:
        maxStack - the operand stack size limit
      • setMaxLocals

        public void setMaxLocals​(int maxLocals)
        Parameters:
        maxLocals - the local variable slot count
      • setCode

        public void setCode​(byte[] code)
        Parameters:
        code - the raw bytecode
      • setAttributes

        public void setAttributes​(List<Attribute> attributes)
        Parameters:
        attributes - the nested code attributes
      • read

        public void read​(ClassFile classFile,
                         int length)
        Description copied from class: Attribute
        Reads the attribute data from the class file.
        Specified by:
        read in class Attribute
        Parameters:
        classFile - The ClassFile utility to read data.
        length - The length of the attribute.
      • setParent

        public void setParent​(MethodEntry methodEntry)
        Sets the parent method entry for this code attribute.
        Parameters:
        methodEntry - The parent method entry
      • getClassFile

        public ClassFile getClassFile()
        Returns the class file that owns this code attribute.
        Returns:
        the owning class file
      • getMethod

        public MethodEntry getMethod()
        Returns the method that owns this code attribute, or null if its parent is not a method.
        Returns:
        the owning method entry, or null
      • updateLength

        public void updateLength()
        Description copied from class: Attribute
        Recomputes the attribute length field from the current in-memory content.
        Specified by:
        updateLength in class Attribute
      • accept

        public void accept​(AbstractMethodVisitor abstractMethodVisitor)
        Accepts a visitor for bytecode analysis.
        Parameters:
        abstractMethodVisitor - The visitor to accept