APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.org.apache.bcel.internal.generic

public abstract Class BranchInstruction

extends Instruction
implements InstructionTargeter
Class Inheritance
All Implemented Interfaces
com.sun.org.apache.bcel.internal.generic.InstructionTargeter
Known Direct Subclasses
com.sun.org.apache.bcel.internal.generic.GotoInstruction, com.sun.org.apache.bcel.internal.generic.IfInstruction, com.sun.org.apache.bcel.internal.generic.JsrInstruction, com.sun.org.apache.bcel.internal.generic.Select
Imports
java.io.DataOutputStream, .IOException, com.sun.org.apache.bcel.internal.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 com.sun.org.apache.bcel.internal.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 com.sun.org.apache.bcel.internal.generic.InstructionTargeter.containsTarget.

Tests whether this targeter targets the specified instruction handle.

pack-priv void
dispose()

Overrides com.sun.org.apache.bcel.internal.generic.Instruction.dispose.

Inform target that it's not targeted anymore.

public void
dump(final DataOutputStream
Output stream
out
)

Overrides com.sun.org.apache.bcel.internal.generic.Instruction.dump.

Dump instruction as byte code to stream out.

public final int
getIndex()

Returns: target offset in byte code

protected int
getPosition()

Returns: the position

public InstructionHandle
getTarget()

Returns: target of branch instruction

protected int
getTargetOffset()

Returns: the offset to this instruction's target

protected int
getTargetOffset(final InstructionHandle
branch target
target
)

Returns: the offset to 'target' relative to this instruction

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

Overrides com.sun.org.apache.bcel.internal.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
)

pack-priv void
setOpcode(final short
the opcode
opcode
)

Overrides com.sun.org.apache.bcel.internal.generic.Instruction.setOpcode.

Updates the opcode.

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

public void
setTarget(final InstructionHandle
branch target
target
)

Set branch target

public String

Returns:

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

Overrides com.sun.org.apache.bcel.internal.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 com.sun.org.apache.bcel.internal.generic.InstructionTargeter.updateTarget.

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

Inherited from com.sun.org.apache.bcel.internal.generic.Instruction:
acceptconsumeStackcopyequalsgetComparatorgetLengthgetNamegetOpcodehashCodeisValidByteisValidShortproduceStackreadInstructionsetComparatorsetLengthtoStringtoString

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 com.sun.org.apache.bcel.internal.generic.InstructionTargeter.containsTarget.

Doc from com.sun.org.apache.bcel.internal.generic.InstructionTargeter.containsTarget.

Tests 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 com.sun.org.apache.bcel.internal.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 com.sun.org.apache.bcel.internal.generic.Instruction.dump.

Dump instruction as byte code to stream out.

Parameters
out:DataOutputStream

Output stream

Annotations
@Override
Exceptions
IOException:

Doc from com.sun.org.apache.bcel.internal.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 com.sun.org.apache.bcel.internal.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 com.sun.org.apache.bcel.internal.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
setOpcodeback to summary
pack-priv void setOpcode(final short opcode)

Overrides com.sun.org.apache.bcel.internal.generic.Instruction.setOpcode.

Updates the opcode. Before changing the opcode, reset the target so that the old instruction is removed from the HashSet and the new one then added.

Parameters
opcode:short

the opcode

Annotations
@Override
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)

Set branch target

Parameters
target:InstructionHandle

branch target

toStringback to summary
public String toString(final boolean verbose)

Overrides com.sun.org.apache.bcel.internal.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 com.sun.org.apache.bcel.internal.generic.InstructionTargeter.updateTarget.

Doc from com.sun.org.apache.bcel.internal.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