Top Description Fields Constructors Methods
org.aspectj.apache.bcel.classfile

public final Class Code

extends Attribute
Class Inheritance
Imports
java.io.DataInputStream, .DataOutputStream, .IOException, org.aspectj.apache.bcel.Constants

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.
Author
M. Dahm
Version
$Id: Code.java,v 1.9 2009/10/05 17:35:36 aclement Exp $
See Also
Attribute, CodeException, LineNumberTable, LocalVariableTable

Field Summary

Modifier and TypeField and Description
private Attribute[]
private byte[]
private CodeException[]
private int
private int
private static final CodeException[]
Inherited from org.aspectj.apache.bcel.classfile.Attribute:
cpoollengthnameIndexNoAttributestag

Constructor Summary

AccessConstructor and Description
public
Code(Code c)

Initialize from another object.

pack-priv
Code(int name_index, int length, DataInputStream file, ConstantPool constant_pool)

public
Code(int
Index pointing to the name Code
name_index
,
int
Content length in bytes
length
,
int
Maximum size of stack
max_stack
,
int
Number of local variables
max_locals
,
byte[]
Actual byte code
code
,
CodeException[]
Table of handled exceptions
exception_table
,
Attribute[]
Attributes of code: LineNumber or LocalVariable
attributes
,
ConstantPool
Array of constants
constant_pool
)

Method Summary

Modifier and TypeMethod and Description
public void
accept(ClassVisitor
Visitor object
v
)

Implements abstract org.aspectj.apache.bcel.classfile.Attribute.accept.

Implements org.aspectj.apache.bcel.classfile.Node.accept.

Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class.
private final int

Returns:

the full size of this code attribute, minus its first 6 bytes, including the size of all its contained attributes
calculateLength
()

public final void
dump(DataOutputStream
Output file stream
file
)

Overrides org.aspectj.apache.bcel.classfile.Attribute.dump.

Dump code attribute to file stream in binary format.
public final Attribute[]

Returns:

Collection of code attributes.
getAttributes
()

public final byte[]

Returns:

Actual byte code of the method.
getCode
()

public String
getCodeString()

Returns the same as toString(true) except that the attribute information isn't included (line numbers).

public final CodeException[]

Returns:

Table of handled exceptions.
getExceptionTable
()

private final int

Returns:

the internal length of this code attribute (minus the first 6 bytes) and excluding all its attributes
getInternalLength
()

public LineNumberTable

Returns:

LineNumberTable of Code, if it has one
getLineNumberTable
()

public LocalVariableTable

Returns:

LocalVariableTable of Code, if it has one
getLocalVariableTable
()

public final int

Returns:

Number of local variables.
getMaxLocals
()

public final int

Returns:

Maximum size of stack used by this method.
getMaxStack
()

public final void
setAttributes(Attribute[] attributes)

public final void
setCode(byte[]
byte code
code
)

public final void
setExceptionTable(CodeException[]
exception table
exception_table
)

public final void
setMaxLocals(int
maximum number of local variables
max_locals
)

public final void
setMaxStack(int
maximum stack size
max_stack
)

public final String

Returns:

String representation of code chunk.
toString
(boolean verbose)

public final String

Returns:

String representation of code chunk.
toString
()

Overrides org.aspectj.apache.bcel.classfile.Attribute.toString.

Returns a string representation of the object.
Inherited from org.aspectj.apache.bcel.classfile.Attribute:
getConstantPoolgetLengthgetNamegetNameIndexgetTagreadAttribute

Field Detail

attributesback to summary
private Attribute[] attributes
codeback to summary
private byte[] code
exceptionTableback to summary
private CodeException[] exceptionTable
maxLocalsback to summary
private int maxLocals
maxStackback to summary
private int maxStack
NO_EXCEPTIONSback to summary
private static final CodeException[] NO_EXCEPTIONS

Constructor Detail

Codeback to summary
public Code(Code c)

Initialize from another object. Note that both objects use the same references (shallow copy). Use copy() for a physical copy.

Codeback to summary
pack-priv Code(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException
Codeback to summary
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:int

Index pointing to the name Code

length:int

Content length in bytes

max_stack:int

Maximum size of stack

max_locals:int

Number of local variables

code:byte[]

Actual byte code

exception_table:CodeException[]

Table of handled exceptions

attributes:Attribute[]

Attributes of code: LineNumber or LocalVariable

constant_pool:ConstantPool

Array of constants

Method Detail

acceptback to summary
public void accept(ClassVisitor v)

Implements abstract org.aspectj.apache.bcel.classfile.Attribute.accept.

Implements org.aspectj.apache.bcel.classfile.Node.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.

Parameters
v:ClassVisitor

Visitor object

Annotations
@Override
calculateLengthback to summary
private final int calculateLength()
Returns:int

the full size of this code attribute, minus its first 6 bytes, including the size of all its contained attributes

dumpback to summary
public final void dump(DataOutputStream file) throws IOException

Overrides org.aspectj.apache.bcel.classfile.Attribute.dump.

Dump code attribute to file stream in binary format.

Parameters
file:DataOutputStream

Output file stream

Annotations
@Override
getAttributesback to summary
public final Attribute[] getAttributes()
Returns:Attribute[]

Collection of code attributes.

See Also
Attribute
getCodeback to summary
public final byte[] getCode()
Returns:byte[]

Actual byte code of the method.

getCodeStringback to summary
public String 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.

getExceptionTableback to summary
public final CodeException[] getExceptionTable()
Returns:CodeException[]

Table of handled exceptions.

See Also
CodeException
getInternalLengthback to summary
private final int getInternalLength()
Returns:int

the internal length of this code attribute (minus the first 6 bytes) and excluding all its attributes

getLineNumberTableback to summary
public LineNumberTable getLineNumberTable()
Returns:LineNumberTable

LineNumberTable of Code, if it has one

getLocalVariableTableback to summary
public LocalVariableTable getLocalVariableTable()
Returns:LocalVariableTable

LocalVariableTable of Code, if it has one

getMaxLocalsback to summary
public final int getMaxLocals()
Returns:int

Number of local variables.

getMaxStackback to summary
public final int getMaxStack()
Returns:int

Maximum size of stack used by this method.

setAttributesback to summary
public final void setAttributes(Attribute[] attributes)
setCodeback to summary
public final void setCode(byte[] code)
Parameters
code:byte[]

byte code

setExceptionTableback to summary
public final void setExceptionTable(CodeException[] exception_table)
Parameters
exception_table:CodeException[]

exception table

setMaxLocalsback to summary
public final void setMaxLocals(int max_locals)
Parameters
max_locals:int

maximum number of local variables

setMaxStackback to summary
public final void setMaxStack(int max_stack)
Parameters
max_stack:int

maximum stack size

toStringback to summary
public final String toString(boolean verbose)
Returns:String

String representation of code chunk.

toStringback to summary
public final String toString()

Overrides org.aspectj.apache.bcel.classfile.Attribute.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

String representation of code chunk.

Annotations
@Override