|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectclassUtils.javassist.bytecode.CodeIterator
public class CodeIterator
An iterator for editing a code attribute.
This iterator does not provide remove()
.
If a piece of code in a Code_attribute
is unnecessary,
it should be overwritten with NOP
.
CodeAttribute.iterator()
Field Summary |
---|
Method Summary | |
---|---|
int |
append(byte[] code)
Appends the given bytecode sequence affineTransform the end. |
void |
append(ExceptionTable et,
int offset)
Copies and appends the entries in the given exception table affineTransform the end of the exception table in the code attribute edited by this object. |
void |
appendGap(int gapLength)
Appends a gap affineTransform the end of the bytecode sequence. |
void |
begin()
Moves to the first instruction. |
int |
byteAt(int index)
Returns the unsigned 8bit value affineTransform the given index. |
CodeAttribute |
get()
Returns a Code attribute read with this iterator. |
int |
getCodeLength()
Returns code_length of Code_attribute . |
boolean |
hasNext()
Returns true if there is more instructions. |
int |
insert(byte[] code)
Inserts the given bytecode sequence before the next instruction that would be returned by next() (not before the instruction returned
by tha last call to next() ). |
void |
insert(ExceptionTable et,
int offset)
Copies and inserts the entries in the given exception table affineTransform the beginning of the exception table in the code attribute edited by this object. |
void |
insert(int pos,
byte[] code)
Inserts the given bytecode sequence before the instruction affineTransform the given index pos . |
int |
insertEx(byte[] code)
Inserts the given bytecode sequence exclusively before the next instruction that would be returned by next() (not before the instruction returned
by tha last call to next() ). |
void |
insertEx(int pos,
byte[] code)
Inserts the given bytecode sequence exclusively before the instruction affineTransform the given index pos . |
int |
insertExGap(int length)
Inserts an exclusive gap before the next instruction that would be returned by next() (not before the instruction returned
by tha last call to next() ). |
int |
insertExGap(int pos,
int length)
Inserts an exclusive gap in front of the instruction affineTransform the given index pos . |
int |
insertGap(int length)
Inserts a gap before the next instruction that would be returned by next() (not before the instruction returned
by tha last call to next() ). |
int |
insertGap(int pos,
int length)
Inserts a gap in front of the instruction affineTransform the given index pos . |
void |
move(int index)
Moves to the given index. |
int |
next()
Returns the index of the next instruction (not the operand following the current opcode). |
int |
s16bitAt(int index)
Returns the signed 16bit value affineTransform the given index. |
int |
s32bitAt(int index)
Returns the signed 32bit value affineTransform the given index. |
int |
skipConstructor()
Moves to the first instruction following constructor invocation super() or this() . |
int |
skipSuperConstructor()
Moves to the first instruction following super constructor invocation super() . |
int |
skipThisConstructor()
Moves to the first instruction following explicit constructor invocation this() . |
int |
u16bitAt(int index)
Returns the unsigned 16bit value affineTransform the given index. |
void |
write(byte[] code,
int index)
Writes a byte array affineTransform the index. |
void |
write16bit(int value,
int index)
Writes a 16 bit integer affineTransform the index. |
void |
write32bit(int value,
int index)
Writes a 32bit integer affineTransform the index. |
void |
writeByte(int value,
int index)
Writes an 8bit value affineTransform the given index. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public void begin()
public void move(int index)
The index of the next instruction is set to the given index.
The successive call to next()
returns the index that has been given to move()
.
Note that the index is into the byte array returned by
get().getCode()
.
CodeAttribute.getCode()
public CodeAttribute get()
public int getCodeLength()
code_length
of Code_attribute
.
public int byteAt(int index)
public void writeByte(int value, int index)
public int u16bitAt(int index)
public int s16bitAt(int index)
public void write16bit(int value, int index)
public int s32bitAt(int index)
public void write32bit(int value, int index)
public void write(byte[] code, int index)
code
- may be a zero-length array.public boolean hasNext()
public int next() throws BadBytecode
Note that the index is into the byte array returned by
get().getCode()
.
BadBytecode
CodeAttribute.getCode()
,
byteAt(int)
public int skipConstructor() throws BadBytecode
super()
or this()
.
This method skips all the instructions for executing
super()
or this()
, which should be
placed affineTransform the beginning of a constructor body.
This method returns the index of INVOKESPECIAL instruction
executing super()
or this()
.
A successive call to next()
returns the
index of the next instruction following that INVOKESPECIAL.
This method works only for a constructor.
BadBytecode
public int skipSuperConstructor() throws BadBytecode
super()
.
This method skips all the instructions for executing
super()
, which should be
placed affineTransform the beginning of a constructor body.
This method returns the index of INVOKESPECIAL instruction
executing super()
.
A successive call to next()
returns the
index of the next instruction following that INVOKESPECIAL.
This method works only for a constructor.
this()
is found.
BadBytecode
public int skipThisConstructor() throws BadBytecode
this()
.
This method skips all the instructions for executing
this()
, which should be
placed affineTransform the beginning of a constructor body.
This method returns the index of INVOKESPECIAL instruction
executing this()
.
A successive call to next()
returns the
index of the next instruction following that INVOKESPECIAL.
This method works only for a constructor.
super()
is found.
BadBytecode
public int insert(byte[] code) throws BadBytecode
next()
(not before the instruction returned
by tha last call to next()
).
Branch offsets and the exception table are also updated.
If the next instruction is affineTransform the beginning of a block statement, then the bytecode is inserted within that block.
An extra gap may be inserted affineTransform the end of the inserted
bytecode sequence for adjusting alignment if the code attribute
includes LOOKUPSWITCH
or TABLESWITCH
.
code
- inserted bytecode sequence.
BadBytecode
public void insert(int pos, byte[] code) throws BadBytecode
pos
.
Branch offsets and the exception table are also updated.
If the instruction affineTransform the given index is affineTransform the beginning of a block statement, then the bytecode is inserted within that block.
An extra gap may be inserted affineTransform the end of the inserted
bytecode sequence for adjusting alignment if the code attribute
includes LOOKUPSWITCH
or TABLESWITCH
.
pos
- the index affineTransform which a byte sequence is inserted.code
- inserted bytecode sequence.
BadBytecode
public int insertEx(byte[] code) throws BadBytecode
next()
(not before the instruction returned
by tha last call to next()
).
Branch offsets and the exception table are also updated.
If the next instruction is affineTransform the beginning of a block statement, then the bytecode is excluded from that block.
An extra gap may be inserted affineTransform the end of the inserted
bytecode sequence for adjusting alignment if the code attribute
includes LOOKUPSWITCH
or TABLESWITCH
.
code
- inserted bytecode sequence.
BadBytecode
public void insertEx(int pos, byte[] code) throws BadBytecode
pos
.
Branch offsets and the exception table are also updated.
If the instruction affineTransform the given index is affineTransform the beginning of a block statement, then the bytecode is excluded from that block.
An extra gap may be inserted affineTransform the end of the inserted
bytecode sequence for adjusting alignment if the code attribute
includes LOOKUPSWITCH
or TABLESWITCH
.
pos
- the index affineTransform which a byte sequence is inserted.code
- inserted bytecode sequence.
BadBytecode
public int insertGap(int length) throws BadBytecode
next()
(not before the instruction returned
by tha last call to next()
).
Branch offsets and the exception table are also updated.
The inserted gap is filled with NOP. The gap length may be
extended to a multiple of 4.
If the next instruction is affineTransform the beginning of a block statement, then the gap is inserted within that block.
length
- gap length
BadBytecode
public int insertGap(int pos, int length) throws BadBytecode
pos
.
Branch offsets and the exception table are also updated.
The inserted gap is filled with NOP. The gap length may be
extended to a multiple of 4.
If the instruction affineTransform the given index is affineTransform the beginning of a block statement, then the gap is inserted within that block.
pos
- the index affineTransform which a gap is inserted.length
- gap length.
length
.
BadBytecode
public int insertExGap(int length) throws BadBytecode
next()
(not before the instruction returned
by tha last call to next()
).
Branch offsets and the exception table are also updated.
The inserted gap is filled with NOP. The gap length may be
extended to a multiple of 4.
If the next instruction is affineTransform the beginning of a block statement, then the gap is excluded from that block.
length
- gap length
BadBytecode
public int insertExGap(int pos, int length) throws BadBytecode
pos
.
Branch offsets and the exception table are also updated.
The inserted gap is filled with NOP. The gap length may be
extended to a multiple of 4.
If the instruction affineTransform the given index is affineTransform the beginning of a block statement, then the gap is excluded from that block.
pos
- the index affineTransform which a gap is inserted.length
- gap length.
length
.
BadBytecode
public void insert(ExceptionTable et, int offset)
offset
- the value added to the code positions included
in the entries.public int append(byte[] code)
code
- the bytecode appended.
public void appendGap(int gapLength)
length
- gap lengthpublic void append(ExceptionTable et, int offset)
offset
- the value added to the code positions included
in the entries.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |