Package org.apache.bcel.generic
Class BranchInstruction
- java.lang.Object
-
- org.apache.bcel.generic.Instruction
-
- org.apache.bcel.generic.BranchInstruction
-
- All Implemented Interfaces:
java.lang.Cloneable,InstructionTargeter
- Direct Known Subclasses:
GotoInstruction,IfInstruction,JsrInstruction,Select
public abstract class BranchInstruction extends Instruction implements InstructionTargeter
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:
InstructionList
-
-
Field Summary
Fields Modifier and Type Field Description protected intindexDeprecated.(since 6.0) will be made private; do not access directly, use getter/setterprotected intpositionDeprecated.(since 6.0) will be made private; do not access directly, use getter/setterprotected InstructionHandletargetDeprecated.(since 6.0) will be made private; do not access directly, use getter/setter-
Fields inherited from class org.apache.bcel.generic.Instruction
EMPTY_ARRAY, length, opcode
-
-
Constructor Summary
Constructors Modifier Constructor Description (package private)BranchInstruction()Empty constructor needed for Instruction.readInstruction.protectedBranchInstruction(short opcode, InstructionHandle target)Common super constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsTarget(InstructionHandle ih)Tests whether this targeter targets the specified instruction handle.(package private) voiddispose()Inform target that it's not targeted anymore.voiddump(java.io.DataOutputStream out)Dumps instruction as byte code to stream out.intgetIndex()Gets the target offset in byte code.protected intgetPosition()Gets the position.InstructionHandlegetTarget()Gets the target of branch instruction.protected intgetTargetOffset()Gets 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.java.lang.StringtoString(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, equals, getComparator, getLength, getName, getOpcode, hashCode, isValidByte, isValidShort, produceStack, readInstruction, setComparator, setLength, setOpcode, toString, toString
-
-
-
-
Field Detail
-
index
@Deprecated protected int index
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setter
-
target
@Deprecated protected InstructionHandle target
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setter
-
position
@Deprecated protected int position
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setter
-
-
Constructor Detail
-
BranchInstruction
BranchInstruction()
Empty constructor needed for Instruction.readInstruction. Not to be used otherwise.
-
BranchInstruction
protected BranchInstruction(short opcode, InstructionHandle target)Common super constructor- Parameters:
opcode- Instruction opcode.target- instruction to branch to.
-
-
Method Detail
-
notifyTarget
static void notifyTarget(InstructionHandle oldIh, InstructionHandle newIh, InstructionTargeter t)
Used by BranchInstruction, LocalVariableGen, CodeExceptionGen, LineNumberGen
-
containsTarget
public boolean containsTarget(InstructionHandle ih)
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
public void dump(java.io.DataOutputStream out) throws java.io.IOExceptionDumps instruction as byte code to stream out.- Overrides:
dumpin classInstruction- Parameters:
out- Output stream.- Throws:
java.io.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
public InstructionHandle 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
protected int getTargetOffset(InstructionHandle target)
Gets the offset to target relative to this instruction.- Parameters:
target- branch target.- Returns:
- the offset to 'target' relative to this instruction.
-
initFromFile
protected void initFromFile(ByteSequence bytes, boolean wide) throws java.io.IOException
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:
java.io.IOException- may be thrown if the implementation needs to read data from the file- See Also:
InstructionList
-
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
public void setTarget(InstructionHandle target)
Sets branch target.- Parameters:
target- branch target.
-
toString
public java.lang.String toString(boolean verbose)
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
public void updateTarget(InstructionHandle oldIh, InstructionHandle newIh)
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.
-
-