org.apache.bcel.classfile
Class Code
- Cloneable, Node, Serializable
This class represents a chunk of Java byte code contained in a
method. It is instantiated by the
Attribute.readAttribute() method. A Code
attribute contains informations about operand stack, local
variables, byte code and the exceptions handled within this
method.
This attribute has attributes itself, namely LineNumberTable which
is used for debugging purposes and LocalVariableTable which
contains information about the local variables.
$Id: Code.java 386056 2006-03-15 11:31:56Z tcurdt $
Code(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
|
Code(int name_index, int length, int max_stack, int max_locals, byte[] code, CodeException[] exception_table, Attribute[] attributes, ConstantPool constant_pool)
|
Code(Code c) - Initialize from another object.
|
accept , addAttributeReader , clone , copy , dump , getConstantPool , getLength , getNameIndex , getTag , readAttribute , removeAttributeReader , setConstantPool , setLength , setNameIndex , toString |
attributes_count
private int attributes_count
code_length
private int code_length
exception_table_length
private int exception_table_length
max_locals
private int max_locals
max_stack
private int max_stack
Code
(package private) Code(int name_index,
int length,
DataInputStream file,
ConstantPool constant_pool)
throws IOException
name_index
- Index pointing to the name Codelength
- Content length in bytesfile
- Input streamconstant_pool
- Array of constants
Code
public Code(int name_index,
int length,
int max_stack,
int max_locals,
byte[] code,
CodeException[] exception_table,
Attribute[] attributes,
ConstantPool constant_pool)
name_index
- Index pointing to the name Codelength
- Content length in bytesmax_stack
- Maximum size of stackmax_locals
- Number of local variablescode
- Actual byte codeexception_table
- Table of handled exceptionsattributes
- Attributes of code: LineNumber or LocalVariableconstant_pool
- Array of constants
Code
public Code(Code c)
Initialize from another object. Note that both objects use the same
references (shallow copy). Use copy() for a physical copy.
accept
public void accept(Visitor v)
Called by objects that are traversing the nodes of the tree implicitely
defined by the contents of a Java class. I.e., the hierarchy of methods,
fields, attributes, etc. spawns a tree of objects.
- accept in interface Node
- accept in interface Attribute
calculateLength
private final int calculateLength()
- the full size of this code attribute, minus its first 6 bytes,
including the size of all its contained attributes
dump
public final void dump(DataOutputStream file)
throws IOException
Dump code attribute to file stream in binary format.
- dump in interface Attribute
file
- Output file stream
getAttributes
public final Attribute[] getAttributes()
- Collection of code attributes.
getCode
public final byte[] getCode()
- Actual byte code of the method.
getExceptionTable
public final CodeException[] getExceptionTable()
- Table of handled exceptions.
getInternalLength
private final int getInternalLength()
- the internal length of this code attribute (minus the first 6 bytes)
and excluding all its attributes
getLineNumberTable
public LineNumberTable getLineNumberTable()
- LineNumberTable of Code, if it has one
getLocalVariableTable
public LocalVariableTable getLocalVariableTable()
- LocalVariableTable of Code, if it has one
getMaxLocals
public final int getMaxLocals()
- Number of local variables.
getMaxStack
public final int getMaxStack()
- Maximum size of stack used by this method.
setAttributes
public final void setAttributes(Attribute[] attributes)
attributes
- the attributes to set for this Code
setCode
public final void setCode(byte[] code)
setExceptionTable
public final void setExceptionTable(CodeException[] exception_table)
exception_table
- exception table
setMaxLocals
public final void setMaxLocals(int max_locals)
max_locals
- maximum number of local variables
setMaxStack
public final void setMaxStack(int max_stack)
max_stack
- maximum stack size
toString
public final String toString()
- toString in interface Attribute
- String representation of code chunk.
toString
public final String toString(boolean verbose)
- String representation of code chunk.