org.ow2.asmdex.structureCommon
Class Label

java.lang.Object
  extended by org.ow2.asmdex.structureCommon.Label

public class Label
extends java.lang.Object

A label represents a position in the bytecode of a method. Labels are used for jump, goto, and switch instructions, and for try catch blocks. A label designates the instruction that is just after. Two Labels are equal if their position is the same. Note however that there can be other elements between a label and the instruction it designates (such as other labels, line numbers, etc.).

Author:
Julien Névo, based on the ASM Framework.

Field Summary
 java.lang.Object info
          Field used to associate user information to a label.
 
Constructor Summary
Label()
          Constructs a new label.
 
Method Summary
 void addReferringInstruction(Instruction instruction)
          Adds an Instruction that refers to this Label.
 boolean equals(java.lang.Object obj)
           
 int getLine()
          Returns the Line number associated to this Label.
 int getOffset()
          Returns the offset corresponding to this label.
 java.util.ArrayList<Instruction> getReferringInstructions()
          Returns the list of instructions which REFER to this Label.
 int hashCode()
           
 boolean isResolved()
          Indicates if the Label is resolved or not.
 void setLine(int line)
          Sets the Line number associated to this Label.
 void setOffset(int offset)
          Sets the offset of this Label, and flags the Label as Resolved.
 java.lang.String toString()
          Returns a string representation of this label.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

info

public java.lang.Object info
Field used to associate user information to a label. Warning: this field is used by the ASM tree package. In order to use it with the ASM tree package you must override the MethodNode.getLabelNode(org.ow2.asmdex.structureCommon.Label) method.

Constructor Detail

Label

public Label()
Constructs a new label.

Method Detail

getOffset

public int getOffset()
Returns the offset corresponding to this label. This offset is computed from the start of the method's bytecode. This method is normally not needed by class generators or adapters.

Returns:
the offset corresponding to this label.
Throws:
java.lang.IllegalStateException - if this label is not resolved yet.

setOffset

public void setOffset(int offset)
Sets the offset of this Label, and flags the Label as Resolved.

Parameters:
offset - the offset of this Label in bytes, from the beginning of the bytecode of its method.

isResolved

public boolean isResolved()
Indicates if the Label is resolved or not.

Returns:
true if the Label is resolved.

getLine

public int getLine()
Returns the Line number associated to this Label.

Returns:
the Line number associated to this Label.

setLine

public void setLine(int line)
Sets the Line number associated to this Label.

Parameters:
line - the Line number to associate to this Label.

getReferringInstructions

public java.util.ArrayList<Instruction> getReferringInstructions()
Returns the list of instructions which REFER to this Label. Only jumps/tests making reference to this label are added here.

Returns:
the list of instructions which refer to this Label

addReferringInstruction

public void addReferringInstruction(Instruction instruction)
Adds an Instruction that refers to this Label. The Instruction must be a jump/test.

Parameters:
instruction - the Instruction that refers to this Label.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Returns a string representation of this label. The Offset is written only if known.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this label. The Offset is written only if known.