org.apache.bcel.generic
Class BranchHandle

java.lang.Object
  extended by org.apache.bcel.generic.InstructionHandle
      extended by org.apache.bcel.generic.BranchHandle
All Implemented Interfaces:
java.io.Serializable

public final class BranchHandle
extends InstructionHandle

BranchHandle is returned by specialized InstructionList.append() whenever a BranchInstruction is appended. This is useful when the target of this instruction is not known at time of creation and must be set later via setTarget().

Version:
$Id: BranchHandle.java 386056 2006-03-15 11:31:56Z tcurdt $
Author:
M. Dahm
See Also:
InstructionHandle, Instruction, InstructionList, Serialized Form

Field Summary
private static BranchHandle bh_list
          Factory methods.
private  BranchInstruction bi
           
 
Fields inherited from class org.apache.bcel.generic.InstructionHandle
i_position, instruction, next, prev
 
Constructor Summary
private BranchHandle(BranchInstruction i)
           
 
Method Summary
protected  void addHandle()
          Handle adds itself to the list of resuable handles.
(package private) static BranchHandle getBranchHandle(BranchInstruction i)
           
 int getPosition()
           
 InstructionHandle getTarget()
           
 void setInstruction(Instruction i)
          Set new contents.
(package private)  void setPosition(int pos)
          Set the position, i.e., the byte code offset of the contained instruction.
 void setTarget(InstructionHandle ih)
          Pass new target to instruction.
protected  int updatePosition(int offset, int max_offset)
          Called by InstructionList.setPositions when setting the position for every instruction.
 void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih)
          Update target of instruction.
 
Methods inherited from class org.apache.bcel.generic.InstructionHandle
accept, addAttribute, addTargeter, dispose, getAttribute, getAttributes, getInstruction, getInstructionHandle, getNext, getPrev, getTargeters, hasTargeters, removeAllTargeters, removeAttribute, removeTargeter, swapInstruction, toString, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

bi

private BranchInstruction bi

bh_list

private static BranchHandle bh_list
Factory methods.

Constructor Detail

BranchHandle

private BranchHandle(BranchInstruction i)
Method Detail

getBranchHandle

static final BranchHandle getBranchHandle(BranchInstruction i)

addHandle

protected void addHandle()
Handle adds itself to the list of resuable handles.

Overrides:
addHandle in class InstructionHandle

getPosition

public int getPosition()
Overrides:
getPosition in class InstructionHandle
Returns:
the position, i.e., the byte code offset of the contained instruction. This is accurate only after InstructionList.setPositions() has been called.

setPosition

void setPosition(int pos)
Description copied from class: InstructionHandle
Set the position, i.e., the byte code offset of the contained instruction.

Overrides:
setPosition in class InstructionHandle

updatePosition

protected int updatePosition(int offset,
                             int max_offset)
Description copied from class: InstructionHandle
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.

Overrides:
updatePosition in class InstructionHandle
Parameters:
offset - additional offset caused by preceding (variable length) instructions
max_offset - the maximum offset that may be caused by these instructions
Returns:
additional offset caused by possible change of this instruction's length

setTarget

public void setTarget(InstructionHandle ih)
Pass new target to instruction.


updateTarget

public void updateTarget(InstructionHandle old_ih,
                         InstructionHandle new_ih)
Update target of instruction.


getTarget

public InstructionHandle getTarget()
Returns:
target of instruction.

setInstruction

public void setInstruction(Instruction i)
Set new contents. Old instruction is disposed and may not be used anymore.

Overrides:
setInstruction in class InstructionHandle