javassist.bytecode

Class CodeAttribute

public class CodeAttribute extends AttributeInfo implements Opcode

Code_attribute.

To browse the code field of a Code_attribute structure, use CodeIterator.

See Also: CodeIterator

Nested Class Summary
static classCodeAttribute.RuntimeCopyException
An exception that may be thrown by copy() in CodeAttribute.
Field Summary
static Stringtag
The name of this attribute "Code".
Constructor Summary
CodeAttribute(ConstPool cp, int stack, int locals, byte[] code, ExceptionTable etable)
Constructs a Code_attribute.
Method Summary
intcomputeMaxStack()
Computes the maximum stack size and sets max_stack to the computed size.
AttributeInfocopy(ConstPool newCp, Map classnames)
Makes a copy.
byte[]get()
This method is not available.
AttributeInfogetAttribute(String name)
Returns the attribute with the specified name.
ListgetAttributes()
Returns attributes[].
byte[]getCode()
Returns code[].
intgetCodeLength()
Returns code_length.
StringgetDeclaringClass()
Returns the name of the class declaring the method including this code attribute.
ExceptionTablegetExceptionTable()
Returns exception_table[].
intgetMaxLocals()
Returns max_locals.
intgetMaxStack()
Returns max_stack.
CodeIteratoriterator()
Makes a new iterator for reading this code attribute.
intlength()
Returns the length of this attribute_info structure.
voidset(byte[] newinfo)
This method is not available.
voidsetMaxLocals(int value)
Sets max_locals.
voidsetMaxStack(int value)
Sets max_stack.

Field Detail

tag

public static final String tag
The name of this attribute "Code".

Constructor Detail

CodeAttribute

public CodeAttribute(ConstPool cp, int stack, int locals, byte[] code, ExceptionTable etable)
Constructs a Code_attribute.

Parameters: cp constant pool table stack max_stack locals max_locals code code[] etable exception_table[]

Method Detail

computeMaxStack

public int computeMaxStack()
Computes the maximum stack size and sets max_stack to the computed size.

Returns: the newly computed value of max_stack

Throws: BadBytecode if this method fails in computing.

copy

public AttributeInfo copy(ConstPool newCp, Map classnames)
Makes a copy. Class names are replaced according to the given Map object.

Parameters: newCp the constant pool table used by the new copy. classnames pairs of replaced and substituted class names.

Returns: CodeAttribute object.

Throws: RuntimeCopyException if a BadBytecode exception is thrown, it is converted into RuntimeCopyException.

get

public byte[] get()
This method is not available.

Throws: java.lang.UnsupportedOperationException always thrown.

getAttribute

public AttributeInfo getAttribute(String name)
Returns the attribute with the specified name. If it is not found, this method returns null.

Parameters: name attribute name

Returns: an AttributeInfo object or null.

getAttributes

public List getAttributes()
Returns attributes[]. It returns a list of AttributeInfo. A new element can be added to the returned list and an existing element can be removed from the list.

See Also: AttributeInfo

getCode

public byte[] getCode()
Returns code[].

getCodeLength

public int getCodeLength()
Returns code_length.

getDeclaringClass

public String getDeclaringClass()
Returns the name of the class declaring the method including this code attribute.

getExceptionTable

public ExceptionTable getExceptionTable()
Returns exception_table[].

getMaxLocals

public int getMaxLocals()
Returns max_locals.

getMaxStack

public int getMaxStack()
Returns max_stack.

iterator

public CodeIterator iterator()
Makes a new iterator for reading this code attribute.

length

public int length()
Returns the length of this attribute_info structure. The returned value is attribute_length + 6.

set

public void set(byte[] newinfo)
This method is not available.

Throws: java.lang.UnsupportedOperationException always thrown.

setMaxLocals

public void setMaxLocals(int value)
Sets max_locals.

setMaxStack

public void setMaxStack(int value)
Sets max_stack.
Javassist, a Java-bytecode translator toolkit.
Copyright (C) 1999-2006 Shigeru Chiba. All Rights Reserved.