Package com.tonic.parser.attribute
Class CodeAttribute
- java.lang.Object
-
- com.tonic.parser.attribute.Attribute
-
- com.tonic.parser.attribute.CodeAttribute
-
public class CodeAttribute extends Attribute
The Code attribute: a method's bytecode, stack/local sizes, exception table, and nested attributes.
-
-
Constructor Summary
Constructors Constructor Description CodeAttribute(String name, ClassFile parent, int nameIndex, int length)Creates the attribute shell for parsing, attached to a class.CodeAttribute(String name, MemberEntry parent, int nameIndex, int length)Creates the attribute shell for parsing, attached to a member.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(AbstractMethodVisitor abstractMethodVisitor)Accepts a visitor for bytecode analysis.List<Attribute>getAttributes()ClassFilegetClassFile()Returns the class file that owns this code attribute.byte[]getCode()List<ExceptionTableEntry>getExceptionTable()intgetMaxLocals()intgetMaxStack()MethodEntrygetMethod()Returns the method that owns this code attribute, ornullif its parent is not a method.voidread(ClassFile classFile, int length)Reads the attribute data from the class file.voidsetAttributes(List<Attribute> attributes)voidsetCode(byte[] code)voidsetMaxLocals(int maxLocals)voidsetMaxStack(int maxStack)voidsetParent(MethodEntry methodEntry)Sets the parent method entry for this code attribute.StringtoString()voidupdateLength()Recomputes the attribute length field from the current in-memory content.
-
-
-
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 nameparent- the member the attribute belongs tonameIndex- constant-pool index of the name Utf8length- 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 nameparent- the class the attribute belongs tonameIndex- constant-pool index of the name Utf8length- 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
-
getExceptionTable
public List<ExceptionTableEntry> getExceptionTable()
- Returns:
- the exception table
-
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:AttributeReads the attribute data from the class file.
-
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, ornullif its parent is not a method.- Returns:
- the owning method entry, or
null
-
updateLength
public void updateLength()
Description copied from class:AttributeRecomputes the attribute length field from the current in-memory content.- Specified by:
updateLengthin classAttribute
-
accept
public void accept(AbstractMethodVisitor abstractMethodVisitor)
Accepts a visitor for bytecode analysis.- Parameters:
abstractMethodVisitor- The visitor to accept
-
-