Package org.apache.bcel.generic
Class BranchInstruction
java.lang.Object
org.apache.bcel.generic.Instruction
org.apache.bcel.generic.BranchInstruction
- All Implemented Interfaces:
Cloneable,InstructionTargeter
- Direct Known Subclasses:
GotoInstruction,IfInstruction,JsrInstruction,Select
Abstract super class for branching instructions like GOTO, IFEQ, and so on. Branch instructions may have a variable length, namely GOTO, JSR, LOOKUPSWITCH
and TABLESWITCH.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intDeprecated.(since 6.0) will be made private; do not access directly, use getter/setterprotected intDeprecated.(since 6.0) will be made private; do not access directly, use getter/setterprotected InstructionHandleDeprecated.(since 6.0) will be made private; do not access directly, use getter/setterFields inherited from class org.apache.bcel.generic.Instruction
EMPTY_ARRAY, length, opcode -
Constructor Summary
ConstructorsModifierConstructorDescription(package private)Empty constructor needed for Instruction.readInstruction.protectedBranchInstruction(short opcode, InstructionHandle target) Common super constructor -
Method Summary
Modifier and TypeMethodDescriptionbooleanTests whether this targeter targets the specified instruction handle.(package private) voiddispose()Inform target that it's not targeted anymore.voiddump(DataOutputStream out) Dumps instruction as byte code to stream out.final intgetIndex()Gets the target offset in byte code.protected intGets the position.Gets the target of branch instruction.protected intGets the offset to this instruction's target.protected intgetTargetOffset(InstructionHandle target) Gets the offset to target relative to this instruction.protected voidinitFromFile(ByteSequence bytes, boolean wide) Reads needed data (for example index) from file.(package private) static voidnotifyTarget(InstructionHandle oldIh, InstructionHandle newIh, InstructionTargeter t) Used by BranchInstruction, LocalVariableGen, CodeExceptionGen, LineNumberGenprotected voidsetIndex(int index) Sets the index.protected voidsetPosition(int position) Sets the position.voidsetTarget(InstructionHandle target) Sets branch target.toString(boolean verbose) Long output format: <position in byte code> <name of opcode> "["<opcode number>"]" "("<length of instruction>")" "<"<target instruction>">" "@"<branch target offset>protected intupdatePosition(int offset, int maxOffset) Called by InstructionList.setPositions when setting the position for every instruction.voidupdateTarget(InstructionHandle oldIh, InstructionHandle newIh) Replaces the target of this targeter from this old handle to the new handle.Methods inherited from class org.apache.bcel.generic.Instruction
accept, consumeStack, copy, dumpToByteArray, equals, getComparator, getLength, getName, getOpcode, hashCode, isNonNegativeUShort, isValidByte, isValidShort, produceStack, readInstruction, readInstruction, setComparator, setLength, setOpcode, toString, toString
-
Field Details
-
index
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setter -
target
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setter -
position
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setter
-
-
Constructor Details
-
BranchInstruction
BranchInstruction()Empty constructor needed for Instruction.readInstruction. Not to be used otherwise. -
BranchInstruction
Common super constructor- Parameters:
opcode- Instruction opcode.target- instruction to branch to.
-
-
Method Details
-
notifyTarget
Used by BranchInstruction, LocalVariableGen, CodeExceptionGen, LineNumberGen -
containsTarget
Description copied from interface:InstructionTargeterTests whether this targeter targets the specified instruction handle.- Specified by:
containsTargetin interfaceInstructionTargeter- Parameters:
ih- The instruction handle to test.- Returns:
- true, if ih is target of this instruction.
-
dispose
void dispose()Inform target that it's not targeted anymore.- Overrides:
disposein classInstruction
-
dump
Dumps instruction as byte code to stream out.- Overrides:
dumpin classInstruction- Parameters:
out- Output stream.- Throws:
IOException- Thrown when an I/O exception of some sort has occurred.
-
getIndex
public final int getIndex()Gets the target offset in byte code.- Returns:
- target offset in byte code.
-
getPosition
protected int getPosition()Gets the position.- Returns:
- The position.
- Since:
- 6.0
-
getTarget
Gets the target of branch instruction.- Returns:
- target of branch instruction.
-
getTargetOffset
protected int getTargetOffset()Gets the offset to this instruction's target.- Returns:
- The offset to this instruction's target.
-
getTargetOffset
Gets the offset to target relative to this instruction.- Parameters:
target- branch target.- Returns:
- The offset to 'target' relative to this instruction.
-
initFromFile
Reads needed data (for example index) from file. Conversion to a InstructionHandle is done in InstructionList(byte[]).- Overrides:
initFromFilein classInstruction- Parameters:
bytes- input stream.wide- wide prefix?- Throws:
IOException- Thrown if the implementation needs to read data from the file- See Also:
-
setIndex
protected void setIndex(int index) Sets the index.- Parameters:
index- The index to set.- Since:
- 6.0
-
setPosition
protected void setPosition(int position) Sets the position.- Parameters:
position- The position to set.- Since:
- 6.0
-
setTarget
Sets branch target.- Parameters:
target- branch target.
-
toString
Long output format: <position in byte code> <name of opcode> "["<opcode number>"]" "("<length of instruction>")" "<"<target instruction>">" "@"<branch target offset>- Overrides:
toStringin classInstruction- Parameters:
verbose- long/short format switch.- Returns:
- mnemonic for instruction.
-
updatePosition
protected int updatePosition(int offset, int maxOffset) Called by InstructionList.setPositions when setting the position for every instruction. In the presence of variable length instructions 'setPositions' performs multiple passes over the instruction list to calculate the correct (byte) positions and offsets by calling this function.- Parameters:
offset- additional offset caused by preceding (variable length) instructions.maxOffset- The maximum offset that may be caused by these instructions.- Returns:
- additional offset caused by possible change of this instruction's length.
-
updateTarget
Description copied from interface:InstructionTargeterReplaces the target of this targeter from this old handle to the new handle.- Specified by:
updateTargetin interfaceInstructionTargeter- Parameters:
oldIh- old target.newIh- new target.
-