Top Description Inners Fields Constructors Methods
javassist.bytecode

public Class CodeAttribute

extends AttributeInfo
implements Opcode
Class Inheritance
All Implemented Interfaces
javassist.bytecode.Opcode
Imports
java.io.DataInputStream, .DataOutputStream, .IOException, java.util.ArrayList, .List, .Map

Code_attribute.

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

See Also
CodeIterator, iterator()

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
public static class
CodeAttribute.RuntimeCopyException

An exception that may be thrown by copy() in CodeAttribute.

Field Summary

Modifier and TypeField and Description
private List<AttributeInfo>
private ExceptionTable
private int
private int
public static final String
tag

The name of this attribute "Code".

Inherited from javassist.bytecode.AttributeInfo:
constPoolinfoname

Constructor Summary

AccessConstructor and Description
public
CodeAttribute(ConstPool
constant pool table
cp
,
int
max_stack
stack
,
int
max_locals
locals
,
byte[]
code[]
code
,
ExceptionTable
exception_table[]
etable
)

Constructs a Code_attribute.

private
CodeAttribute(ConstPool
constant pool table.
cp
,
CodeAttribute
source Code attribute.
src
,
Map<String, String>
pairs of replaced and substituted class names.
classnames
)

Constructs a copy of Code_attribute.

pack-priv

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the newly computed value of max_stack
computeMaxStack
()

Computes the maximum stack size and sets max_stack to the computed size.

public AttributeInfo

Returns:

CodeAttribute object.
copy
(ConstPool
the constant pool table used by the new copy.
newCp
,
Map<String, String>
pairs of replaced and substituted class names.
classnames
)

Overrides javassist.bytecode.AttributeInfo.copy.

Makes a copy.

private byte[]
copyCode(ConstPool destCp, Map<String, String> classnames, ExceptionTable etable, CodeAttribute destCa)

Copies code.

private static CodeAttribute.LdcEntry
copyCode(byte[] code, int beginPos, int endPos, ConstPool srcCp, byte[] newcode, ConstPool destCp, Map<String, String> classnameMap)

private static void
copyConstPoolInfo(int i, byte[] code, ConstPool srcCp, byte[] newcode, ConstPool destCp, Map<String, String> classnameMap)

public byte[]
get()

Overrides javassist.bytecode.AttributeInfo.get.

This method is not available.

public AttributeInfo

Returns:

an AttributeInfo object or null.
getAttribute
(String
attribute name
name
)

Returns the attribute with the specified name.

public List<AttributeInfo>
getAttributes()

Returns attributes[].

public byte[]
getCode()

Returns code[].

public int
getCodeLength()

Returns code_length.

public String
getDeclaringClass()

Returns the name of the class declaring the method including this code attribute.

public ExceptionTable
getExceptionTable()

Returns exception_table[].

public int
getMaxLocals()

Returns max_locals.

public int
getMaxStack()

Returns max_stack.

pack-priv void
public void
insertLocalVar(int
the index of the new parameter.
where
,
int
the type size of the new parameter (1 or 2).
size
)

Changes the index numbers of the local variables to append a new parameter.

public CodeIterator
iterator()

Makes a new iterator for reading this code attribute.

public int
length()

Overrides javassist.bytecode.AttributeInfo.length.

Returns the length of this attribute_info structure.

pack-priv void
pack-priv void
public void
set(byte[] newinfo)

Overrides javassist.bytecode.AttributeInfo.set.

This method is not available.

public void
setAttribute(StackMapTable
the stack map table added to this code attribute. If it is null, a new stack map is not added. Only the old stack map is removed.
smt
)

Adds a stack map table.

public void
setAttribute(StackMap
the stack map table added to this code attribute. If it is null, a new stack map is not added. Only the old stack map is removed.
sm
)

Adds a stack map table for J2ME (CLDC).

pack-priv void
setCode(byte[] newinfo)

Sets code[].

public void
setMaxLocals(int value)

Sets max_locals.

public void
setMaxStack(int value)

Sets max_stack.

private static void
shiftIndex(CodeIterator ci, int
If the index of the local variable is less than this value, it does not change. Otherwise, the index is increased.
lessThan
,
int
the indexes of the local variables are increased by this value.
delta
)

private static void
shiftIndex0(CodeIterator ci, int index, int opcode, int lessThan, int delta, int opcode_i_0, int opcode_i)

private static void
shiftIndex8(CodeIterator ci, int index, int opcode, int lessThan, int delta)

pack-priv void
Inherited from javassist.bytecode.AttributeInfo:
copyAllgetConstPoolgetLengthgetNamegetRefClasseslookupreadremoverenameClassrenameClasswriteAll

Field Detail

attributesback to summary
private List<AttributeInfo> attributes
exceptionsback to summary
private ExceptionTable exceptions
maxLocalsback to summary
private int maxLocals
maxStackback to summary
private int maxStack
tagback to summary
public static final String tag

The name of this attribute "Code".

Constructor Detail

CodeAttributeback to summary
public CodeAttribute(ConstPool cp, int stack, int locals, byte[] code, ExceptionTable etable)

Constructs a Code_attribute.

Parameters
cp:ConstPool

constant pool table

stack:int

max_stack

locals:int

max_locals

code:byte[]

code[]

etable:ExceptionTable

exception_table[]

CodeAttributeback to summary
private CodeAttribute(ConstPool cp, CodeAttribute src, Map<String, String> classnames) throws BadBytecode

Constructs a copy of Code_attribute. Specified class names are replaced during the copy.

Parameters
cp:ConstPool

constant pool table.

src:CodeAttribute

source Code attribute.

classnames:Map<String, String>

pairs of replaced and substituted class names.

CodeAttributeback to summary
pack-priv CodeAttribute(ConstPool cp, int name_id, DataInputStream in) throws IOException

Method Detail

computeMaxStackback to summary
public int computeMaxStack() throws BadBytecode

Computes the maximum stack size and sets max_stack to the computed size.

Returns:int

the newly computed value of max_stack

Exceptions
BadBytecode:
if this method fails in computing.
copyback to summary
public AttributeInfo copy(ConstPool newCp, Map<String, String> classnames) throws RuntimeCopyException

Overrides javassist.bytecode.AttributeInfo.copy.

Makes a copy. Class names are replaced according to the given Map object.

Parameters
newCp:ConstPool

the constant pool table used by the new copy.

classnames:Map<String, String>

pairs of replaced and substituted class names.

Returns:AttributeInfo

CodeAttribute object.

Annotations
@Override
Exceptions
RuntimeCopyException:
if a BadBytecode exception is thrown, it is converted into RuntimeCopyException.
copyCodeback to summary
private byte[] copyCode(ConstPool destCp, Map<String, String> classnames, ExceptionTable etable, CodeAttribute destCa) throws BadBytecode

Copies code.

copyCodeback to summary
private static CodeAttribute.LdcEntry copyCode(byte[] code, int beginPos, int endPos, ConstPool srcCp, byte[] newcode, ConstPool destCp, Map<String, String> classnameMap) throws BadBytecode
copyConstPoolInfoback to summary
private static void copyConstPoolInfo(int i, byte[] code, ConstPool srcCp, byte[] newcode, ConstPool destCp, Map<String, String> classnameMap)
getback to summary
public byte[] get()

Overrides javassist.bytecode.AttributeInfo.get.

This method is not available.

Annotations
@Override
Exceptions
UnsupportedOperationException:
always thrown.
getAttributeback to summary
public AttributeInfo getAttribute(String name)

Returns the attribute with the specified name. If it is not found, this method returns null.

Parameters
name:String

attribute name

Returns:AttributeInfo

an AttributeInfo object or null.

getAttributesback to summary
public List<AttributeInfo> 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
getCodeback to summary
public byte[] getCode()

Returns code[].

getCodeLengthback to summary
public int getCodeLength()

Returns code_length.

getDeclaringClassback to summary
public String getDeclaringClass()

Returns the name of the class declaring the method including this code attribute.

getExceptionTableback to summary
public ExceptionTable getExceptionTable()

Returns exception_table[].

getMaxLocalsback to summary
public int getMaxLocals()

Returns max_locals.

getMaxStackback to summary
public int getMaxStack()

Returns max_stack.

getRefClassesback to summary
pack-priv void getRefClasses(Map<String, String> classnames)

Overrides javassist.bytecode.AttributeInfo.getRefClasses.

Annotations
@Override
insertLocalVarback to summary
public void insertLocalVar(int where, int size) throws BadBytecode

Changes the index numbers of the local variables to append a new parameter. This method does not update LocalVariableAttribute, LocalVariableTypeAttribute, StackMapTable, or StackMap. These attributes must be explicitly updated.

Parameters
where:int

the index of the new parameter.

size:int

the type size of the new parameter (1 or 2).

See Also
LocalVariableAttribute#shiftIndex(int, int), LocalVariableTypeAttribute#shiftIndex(int, int), StackMapTable#insertLocal(int, int, int), StackMap#insertLocal(int, int, int)
iteratorback to summary
public CodeIterator iterator()

Makes a new iterator for reading this code attribute.

lengthback to summary
public int length()

Overrides javassist.bytecode.AttributeInfo.length.

Returns the length of this attribute_info structure. The returned value is attribute_length + 6.

Annotations
@Override
renameClassback to summary
pack-priv void renameClass(String oldname, String newname)

Overrides javassist.bytecode.AttributeInfo.renameClass.

Annotations
@Override
renameClassback to summary
pack-priv void renameClass(Map<String, String> classnames)

Overrides javassist.bytecode.AttributeInfo.renameClass.

Annotations
@Override
setback to summary
public void set(byte[] newinfo)

Overrides javassist.bytecode.AttributeInfo.set.

This method is not available.

Annotations
@Override
Exceptions
UnsupportedOperationException:
always thrown.
setAttributeback to summary
public void setAttribute(StackMapTable smt)

Adds a stack map table. If another copy of stack map table is already contained, the old one is removed.

Parameters
smt:StackMapTable

the stack map table added to this code attribute. If it is null, a new stack map is not added. Only the old stack map is removed.

setAttributeback to summary
public void setAttribute(StackMap sm)

Adds a stack map table for J2ME (CLDC). If another copy of stack map table is already contained, the old one is removed.

Parameters
sm:StackMap

the stack map table added to this code attribute. If it is null, a new stack map is not added. Only the old stack map is removed.

Since
3.12
setCodeback to summary
pack-priv void setCode(byte[] newinfo)

Sets code[].

setMaxLocalsback to summary
public void setMaxLocals(int value)

Sets max_locals.

setMaxStackback to summary
public void setMaxStack(int value)

Sets max_stack.

shiftIndexback to summary
private static void shiftIndex(CodeIterator ci, int lessThan, int delta) throws BadBytecode
Parameters
lessThan:int

If the index of the local variable is less than this value, it does not change. Otherwise, the index is increased.

delta:int

the indexes of the local variables are increased by this value.

shiftIndex0back to summary
private static void shiftIndex0(CodeIterator ci, int index, int opcode, int lessThan, int delta, int opcode_i_0, int opcode_i) throws BadBytecode
shiftIndex8back to summary
private static void shiftIndex8(CodeIterator ci, int index, int opcode, int lessThan, int delta) throws BadBytecode
writeback to summary
pack-priv void write(DataOutputStream out) throws IOException

Overrides javassist.bytecode.AttributeInfo.write.

Annotations
@Override
javassist.bytecode back to summary

pack-priv Class CodeAttribute.LdcEntry

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv CodeAttribute.LdcEntry
pack-priv int

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv static byte[]
doit(byte[] code, CodeAttribute.LdcEntry ldc, ExceptionTable etable, CodeAttribute ca)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

indexback to summary
pack-priv int index
nextback to summary
pack-priv CodeAttribute.LdcEntry next
whereback to summary
pack-priv int where

Constructor Detail

LdcEntryback to summary
pack-priv LdcEntry()

Method Detail

doitback to summary
pack-priv static byte[] doit(byte[] code, CodeAttribute.LdcEntry ldc, ExceptionTable etable, CodeAttribute ca) throws BadBytecode
javassist.bytecode back to summary

public Class CodeAttribute.RuntimeCopyException

extends RuntimeException
Class Inheritance

An exception that may be thrown by copy() in CodeAttribute.

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
public
RuntimeCopyException(String s)

Constructs an exception.

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.lang.RuntimeException.serialVersionUID.

default serialVersionUID

Constructor Detail

RuntimeCopyExceptionback to summary
public RuntimeCopyException(String s)

Constructs an exception.