Package org.apache.bcel.classfile
Class Code
- java.lang.Object
-
- org.apache.bcel.classfile.Attribute
-
- org.apache.bcel.classfile.Code
-
public final class Code extends Attribute
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.- See Also:
Attribute
,CodeException
,LineNumberTable
,LocalVariableTable
-
-
Field Summary
-
Fields inherited from class org.apache.bcel.classfile.Attribute
constant_pool, length, name_index, tag
-
-
Constructor Summary
Constructors Constructor Description Code(int name_index, int length, int maxStack, int maxLocals, byte[] code, CodeException[] exceptionTable, Attribute[] attributes, ConstantPool constant_pool)
Code(Code c)
Initialize from another object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(Visitor v)
Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class.Attribute
copy(ConstantPool _constant_pool)
void
dump(DataOutputStream file)
Dump code attribute to file stream in binary format.Attribute[]
getAttributes()
byte[]
getCode()
CodeException[]
getExceptionTable()
LineNumberTable
getLineNumberTable()
LocalVariableTable
getLocalVariableTable()
int
getMaxLocals()
int
getMaxStack()
void
setAttributes(Attribute[] attributes)
void
setCode(byte[] code)
void
setExceptionTable(CodeException[] exceptionTable)
void
setMaxLocals(int maxLocals)
void
setMaxStack(int maxStack)
String
toString()
String
toString(boolean verbose)
-
Methods inherited from class org.apache.bcel.classfile.Attribute
addAttributeReader, addAttributeReader, clone, getConstantPool, getLength, getName, getNameIndex, getTag, println, readAttribute, readAttribute, removeAttributeReader, setConstantPool, setLength, setNameIndex
-
-
-
-
Constructor Detail
-
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.
-
Code
public Code(int name_index, int length, int maxStack, int maxLocals, byte[] code, CodeException[] exceptionTable, Attribute[] attributes, ConstantPool constant_pool)
- Parameters:
name_index
- Index pointing to the name Codelength
- Content length in bytesmaxStack
- Maximum size of stackmaxLocals
- Number of local variablescode
- Actual byte codeexceptionTable
- of handled exceptionsattributes
- Attributes of code: LineNumber or LocalVariableconstant_pool
- Array of constants
-
-
Method Detail
-
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.
-
dump
public void dump(DataOutputStream file) throws IOException
Dump code attribute to file stream in binary format.- Overrides:
dump
in classAttribute
- Parameters:
file
- Output file stream- Throws:
IOException
-
getAttributes
public Attribute[] getAttributes()
- Returns:
- Collection of code attributes.
- See Also:
Attribute
-
getLineNumberTable
public LineNumberTable getLineNumberTable()
- Returns:
- LineNumberTable of Code, if it has one
-
getLocalVariableTable
public LocalVariableTable getLocalVariableTable()
- Returns:
- LocalVariableTable of Code, if it has one
-
getCode
public byte[] getCode()
- Returns:
- Actual byte code of the method.
-
getExceptionTable
public CodeException[] getExceptionTable()
- Returns:
- Table of handled exceptions.
- See Also:
CodeException
-
getMaxLocals
public int getMaxLocals()
- Returns:
- Number of local variables.
-
getMaxStack
public int getMaxStack()
- Returns:
- Maximum size of stack used by this method.
-
setAttributes
public void setAttributes(Attribute[] attributes)
- Parameters:
attributes
- the attributes to set for this Code
-
setCode
public void setCode(byte[] code)
- Parameters:
code
- byte code
-
setExceptionTable
public void setExceptionTable(CodeException[] exceptionTable)
- Parameters:
exceptionTable
- exception table
-
setMaxLocals
public void setMaxLocals(int maxLocals)
- Parameters:
maxLocals
- maximum number of local variables
-
setMaxStack
public void setMaxStack(int maxStack)
- Parameters:
maxStack
- maximum stack size
-
toString
public String toString(boolean verbose)
- Returns:
- String representation of code chunk.
-
toString
public String toString()
-
copy
public Attribute copy(ConstantPool _constant_pool)
-
-