Class Code
java.lang.Object
org.aspectj.apache.bcel.classfile.Attribute
org.aspectj.apache.bcel.classfile.Code
- All Implemented Interfaces:
Serializable
,Cloneable
,Node
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.
- Version:
- $Id: Code.java,v 1.9 2009/10/05 17:35:36 aclement Exp $
- Author:
- M. Dahm
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionCode
(int name_index, int length, int max_stack, int max_locals, byte[] code, CodeException[] exception_table, Attribute[] attributes, ConstantPool constant_pool) Initialize from another object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class.final void
dump
(DataOutputStream file) Dump code attribute to file stream in binary format.final Attribute[]
final byte[]
getCode()
Returns the same as toString(true) except that the attribute information isn't included (line numbers).final CodeException[]
final int
final int
final void
setAttributes
(Attribute[] attributes) final void
setCode
(byte[] code) final void
setExceptionTable
(CodeException[] exception_table) final void
setMaxLocals
(int max_locals) final void
setMaxStack
(int max_stack) final String
toString()
final String
toString
(boolean verbose) Methods inherited from class org.aspectj.apache.bcel.classfile.Attribute
getConstantPool, getLength, getName, getNameIndex, getTag, readAttribute
-
Constructor Details
-
Code
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 max_stack, int max_locals, byte[] code, CodeException[] exception_table, Attribute[] attributes, ConstantPool constant_pool) - Parameters:
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
-
-
Method Details
-
accept
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
Dump code attribute to file stream in binary format.- Overrides:
dump
in classAttribute
- Parameters:
file
- Output file stream- Throws:
IOException
-
getAttributes
- Returns:
- Collection of code attributes.
- See Also:
-
getLineNumberTable
- Returns:
- LineNumberTable of Code, if it has one
-
getLocalVariableTable
- Returns:
- LocalVariableTable of Code, if it has one
-
getCode
public final byte[] getCode()- Returns:
- Actual byte code of the method.
-
getExceptionTable
- Returns:
- Table of handled exceptions.
- See Also:
-
getMaxLocals
public final int getMaxLocals()- Returns:
- Number of local variables.
-
getMaxStack
public final int getMaxStack()- Returns:
- Maximum size of stack used by this method.
-
setAttributes
- Parameters:
attributes
- .
-
setCode
public final void setCode(byte[] code) - Parameters:
code
- byte code
-
setExceptionTable
- Parameters:
exception_table
- exception table
-
setMaxLocals
public final void setMaxLocals(int max_locals) - Parameters:
max_locals
- maximum number of local variables
-
setMaxStack
public final void setMaxStack(int max_stack) - Parameters:
max_stack
- maximum stack size
-
toString
- Returns:
- String representation of code chunk.
-
toString
-
getCodeString
Returns the same as toString(true) except that the attribute information isn't included (line numbers). Can be used to check whether two pieces of code are equivalent.
-