public class CodeInsertion extends Object
Constructor and Description |
---|
CodeInsertion(int position,
AbstractInstruction[] preInstructions,
AbstractInstruction[] postInstructions,
boolean shiftTarget)
Create a code insertion.
|
Modifier and Type | Method and Description |
---|---|
static List |
apply(List instructions,
List codeInsertions,
CodeAttribute codeAttribute)
Apply a list of CodeInsertions to a list of instructions
such as the one supplied by a ByteCodeReader.
|
int |
getPosition()
Get the insertion position, i.e the instruction number to which
this CodeInsertion is to be applied.
|
AbstractInstruction[] |
getPostInstructions()
Get the instructions to be inserted after the insertion point.
|
AbstractInstruction[] |
getPreInstructions()
Get the instructions to be inserted before the insertion point.
|
boolean |
isShiftTarget()
Get whether offsets of branch instructions pointing to the position of
the resulting code insertion should be shifted to the first pre-instruction
or continue to point at the original instruction.
|
static CodeInsertion |
merge(int position,
boolean shiftTarget,
CodeInsertion inner,
CodeInsertion outer)
Merge two code insertions into one.
|
static AbstractInstruction[] |
mergeInstructions(AbstractInstruction[] firstInstructions,
AbstractInstruction[] lastInstructions)
Merge two arrays of instructions into one.
|
void |
setPosition(int position)
Set the insertion position, i.e the instruction number to which
this CodeInsertion is to be applied.
|
void |
setPostInstructions(AbstractInstruction[] postInstructions)
Set the instructions to be inserted after the insertion point.
|
void |
setPreInstructions(AbstractInstruction[] preInstructions)
Set the instructions to be inserted before the insertion point.
|
void |
setShiftTarget(boolean shiftTarget)
Set whether offsets of branch instructions pointing to the position of
the resulting code insertion should be shifted to the first pre-instruction
or continue to point at the original instruction.
|
public CodeInsertion(int position, AbstractInstruction[] preInstructions, AbstractInstruction[] postInstructions, boolean shiftTarget)
position
- the instruction number to which this CodeInsertion
is to be applied. Corresponds to the index in the list
of instructions such as the one returned by a
ByteCodeReader.preInstructions
- the instructions to be inserted before
the insertion point.postInstructions
- the instructions to be inserted after
the insertion point.shiftTarget
- should offsets of branch instructions pointing to
the position of this code insertion
be shifted or point to the beginning of the
code inserted via the preInstructions
parameters.public static CodeInsertion merge(int position, boolean shiftTarget, CodeInsertion inner, CodeInsertion outer)
position
- the position of the resulting CodeInsertionshiftTarget
- should offsets of branch instructions pointing to
the position of the resulting code insertion
be shifted or point to the beginning of the
inserted code.inner
- the inner CodeInsertionouter
- the outer CodeInsertionpublic static AbstractInstruction[] mergeInstructions(AbstractInstruction[] firstInstructions, AbstractInstruction[] lastInstructions)
firstInstructions
- the head array of type AbstractInstructionlastInstructions
- the tail array of type AbstractInstructionpublic static List apply(List instructions, List codeInsertions, CodeAttribute codeAttribute) throws InvalidByteCodeException
instructions
- the list of instructions which is to be treated
with the CodeInsertions. This list
and the resulting instructions will not be usable
after the method is finished. If you need to
reuse the original instructions, you have to pass
a deep-cloned list into this method.codeInsertions
- the list of codeInsertions which is to be applied to
the list of instructions.codeAttribute
- the CodeAttribute pertaining to the supplied
list of instructions.InvalidByteCodeException
public int getPosition()
public void setPosition(int position)
position
- the insertion positionpublic AbstractInstruction[] getPreInstructions()
public void setPreInstructions(AbstractInstruction[] preInstructions)
preInstructions
- array of instructionspublic AbstractInstruction[] getPostInstructions()
public void setPostInstructions(AbstractInstruction[] postInstructions)
postInstructions
- array of instructionspublic boolean isShiftTarget()
public void setShiftTarget(boolean shiftTarget)
shiftTarget
- the boolean value.