Top Description Fields Constructors Methods
org.apache.bcel.generic

public abstract Class BranchInstruction

extends Instruction
implements InstructionTargeter
Class Inheritance
All Implemented Interfaces
org.apache.bcel.generic.InstructionTargeter
Known Direct Subclasses
org.apache.bcel.generic.GotoInstruction, org.apache.bcel.generic.IfInstruction, org.apache.bcel.generic.JsrInstruction, org.apache.bcel.generic.Select
Imports
java.io.DataOutputStream, .IOException, org.apache.bcel.util.ByteSequence

Abstract super class for branching instructions like GOTO, IFEQ, etc.. Branch instructions may have a variable length, namely GOTO, JSR, LOOKUPSWITCH and TABLESWITCH.
See Also
InstructionList

Field Summary

Modifier and TypeField and Description
protected int
index

Deprecated (since 6.0) will be made private; do not access directly, use getter/setter
protected int
position

Deprecated (since 6.0) will be made private; do not access directly, use getter/setter
protected InstructionHandle
target

Deprecated (since 6.0) will be made private; do not access directly, use getter/setter
Inherited from org.apache.bcel.generic.Instruction:
EMPTY_ARRAYlengthopcode

Constructor Summary

AccessConstructor and Description
pack-priv
BranchInstruction()

Empty constructor needed for Instruction.readInstruction.

protected
BranchInstruction(final short
Instruction opcode
opcode
,
final InstructionHandle
instruction to branch to
target
)

Common super constructor

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true, if ih is target of this instruction
containsTarget
(final InstructionHandle ih)

Implements org.apache.bcel.generic.InstructionTargeter.containsTarget.

Checks whether this targeter targets the specified instruction handle.
pack-priv void
dispose()

Overrides org.apache.bcel.generic.Instruction.dispose.

Inform target that it's not targeted anymore.
public void
dump(final DataOutputStream
Output stream
out
)

Overrides org.apache.bcel.generic.Instruction.dump.

Dump instruction as byte code to stream out.
public final int

Returns:

target offset in byte code
getIndex
()

protected int

Returns:

the position
getPosition
()

public InstructionHandle

Returns:

target of branch instruction
getTarget
()

protected int

Returns:

the offset to this instruction's target
getTargetOffset
()

protected int

Returns:

the offset to 'target' relative to this instruction
getTargetOffset
(final InstructionHandle
branch target
target
)

protected void
initFromFile(final ByteSequence
input stream
bytes
,
final boolean
wide prefix?
wide
)

Overrides org.apache.bcel.generic.Instruction.initFromFile.

Read needed data (e.g. index) from file.
pack-priv static void
notifyTarget(final InstructionHandle oldIh, final InstructionHandle newIh, final InstructionTargeter t)

Used by BranchInstruction, LocalVariableGen, CodeExceptionGen, LineNumberGen

protected void
setIndex(final int
the index to set
index
)

protected void
setPosition(final int
the position to set
position
)

public void
setTarget(final InstructionHandle
branch target
target
)

Sets branch target

public String

Returns:

mnemonic for instruction
toString
(final boolean
long/short format switch
verbose
)

Overrides org.apache.bcel.generic.Instruction.toString.

Long output format: <position in byte code> <name of opcode> "["<opcode number>"]" "("<length of instruction>")" "<"<target instruction>">" "@"<branch target offset>
protected int

Returns:

additional offset caused by possible change of this instruction's length
updatePosition
(final int
additional offset caused by preceding (variable length) instructions
offset
,
final int
the maximum offset that may be caused by these instructions
maxOffset
)

Called by InstructionList.setPositions when setting the position for every instruction.

public void
updateTarget(final InstructionHandle
old target
oldIh
,
final InstructionHandle
new target
newIh
)

Implements org.apache.bcel.generic.InstructionTargeter.updateTarget.

Replaces the target of this targeter from this old handle to the new handle.
Inherited from org.apache.bcel.generic.Instruction:
acceptconsumeStackcopyequalsgetComparatorgetLengthgetNamegetOpcodehashCodeisValidByteisValidShortproduceStackreadInstructionsetComparatorsetLengthsetOpcodetoStringtoString

Field Detail

indexback to summary
protected int index

Deprecated

(since 6.0) will be made private; do not access directly, use getter/setter

Annotations
@Deprecated
positionback to summary
protected int position

Deprecated

(since 6.0) will be made private; do not access directly, use getter/setter

Annotations
@Deprecated
targetback to summary
protected InstructionHandle target

Deprecated

(since 6.0) will be made private; do not access directly, use getter/setter

Annotations
@Deprecated

Constructor Detail

BranchInstructionback to summary
pack-priv BranchInstruction()

Empty constructor needed for Instruction.readInstruction. Not to be used otherwise.

BranchInstructionback to summary
protected BranchInstruction(final short opcode, final InstructionHandle target)

Common super constructor

Parameters
opcode:short

Instruction opcode

target:InstructionHandle

instruction to branch to

Method Detail

containsTargetback to summary
public boolean containsTarget(final InstructionHandle ih)

Implements org.apache.bcel.generic.InstructionTargeter.containsTarget.

Doc from org.apache.bcel.generic.InstructionTargeter.containsTarget.

Checks whether this targeter targets the specified instruction handle.

Returns:boolean

true, if ih is target of this instruction

Annotations
@Override
disposeback to summary
pack-priv void dispose()

Overrides org.apache.bcel.generic.Instruction.dispose.

Inform target that it's not targeted anymore.

Annotations
@Override
dumpback to summary
public void dump(final DataOutputStream out) throws IOException

Overrides org.apache.bcel.generic.Instruction.dump.

Dump instruction as byte code to stream out.

Parameters
out:DataOutputStream

Output stream

Annotations
@Override
Exceptions
IOException:

Doc from org.apache.bcel.generic.Instruction.dump.

Thrown when an I/O exception of some sort has occurred.

getIndexback to summary
public final int getIndex()
Returns:int

target offset in byte code

getPositionback to summary
protected int getPosition()
Returns:int

the position

Since
6.0
getTargetback to summary
public InstructionHandle getTarget()
Returns:InstructionHandle

target of branch instruction

getTargetOffsetback to summary
protected int getTargetOffset()
Returns:int

the offset to this instruction's target

getTargetOffsetback to summary
protected int getTargetOffset(final InstructionHandle target)
Parameters
target:InstructionHandle

branch target

Returns:int

the offset to 'target' relative to this instruction

initFromFileback to summary
protected void initFromFile(final ByteSequence bytes, final boolean wide) throws IOException

Overrides org.apache.bcel.generic.Instruction.initFromFile.

Read needed data (e.g. index) from file. Conversion to a InstructionHandle is done in InstructionList(byte[]).

Parameters
bytes:ByteSequence

input stream

wide:boolean

wide prefix?

Annotations
@Override
Exceptions
IOException:

Doc from org.apache.bcel.generic.Instruction.initFromFile.

may be thrown if the implementation needs to read data from the file

See Also
InstructionList
notifyTargetback to summary
pack-priv static void notifyTarget(final InstructionHandle oldIh, final InstructionHandle newIh, final InstructionTargeter t)

Used by BranchInstruction, LocalVariableGen, CodeExceptionGen, LineNumberGen

setIndexback to summary
protected void setIndex(final int index)
Parameters
index:int

the index to set

Since
6.0
setPositionback to summary
protected void setPosition(final int position)
Parameters
position:int

the position to set

Since
6.0
setTargetback to summary
public void setTarget(final InstructionHandle target)

Sets branch target

Parameters
target:InstructionHandle

branch target

toStringback to summary
public String toString(final boolean verbose)

Overrides org.apache.bcel.generic.Instruction.toString.

Long output format: <position in byte code> <name of opcode> "["<opcode number>"]" "("<length of instruction>")" "<"<target instruction>">" "@"<branch target offset>

Parameters
verbose:boolean

long/short format switch

Returns:String

mnemonic for instruction

Annotations
@Override
updatePositionback to summary
protected int updatePosition(final int offset, final 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:int

additional offset caused by preceding (variable length) instructions

maxOffset:int

the maximum offset that may be caused by these instructions

Returns:int

additional offset caused by possible change of this instruction's length

updateTargetback to summary
public void updateTarget(final InstructionHandle oldIh, final InstructionHandle newIh)

Implements org.apache.bcel.generic.InstructionTargeter.updateTarget.

Doc from org.apache.bcel.generic.InstructionTargeter.updateTarget.

Replaces the target of this targeter from this old handle to the new handle.

Parameters
oldIh:InstructionHandle

old target

newIh:InstructionHandle

new target

Annotations
@Override