net.sf.rej.java.instruction
Class Label

java.lang.Object
  extended by net.sf.rej.java.instruction.Instruction
      extended by net.sf.rej.java.instruction.Label

public class Label
extends Instruction

The concept "label" does not exist in the java bytecode. Instead it's created in the ReJ API to help the user of the API to avoid having to manipulate relative pc position values, whenever an instruction is added or removed between for example between a goto instruction and it's target. The positition would have to be recalculated every time and with non-fixed size instructions the task would not be trivial. Logically a Label is not an instruction, but since it shares a lot of functionality with instructions, making the class extend Instruction was a practical (lazy) choice.

Author:
Sami Koivu

Constructor Summary
Label(int pos)
           
Label(int pos, java.lang.String id)
           
 
Method Summary
 void execute(ExecutionContext ec)
          Reserved for possible future use.
 byte[] getData(DecompilationContext dc)
          Get the bytecode data for this instruction.
 java.lang.String getId()
           
 java.lang.String getMnemonic()
          Return the mnemonic of this instruction.
 int getOpcode()
          Return the Opcode of this instruction.
 Parameters getParameters()
          Return a Parameters object describing the types of parameters(if any) and the values set to this particular instance for those parameters.
 Parameters getParameterTypes()
          Return a Parameters object describing the types of parameters(if any) that are applicable to this type of an instruction.
 int getPosition()
           
 int getSize()
          Return the size of this instruction.
 void setData(byte[] data, DecompilationContext dc)
          Set the data for this instruction.
 void setParameters(Parameters params)
          Update the parameter values of this instruction with the values in the Parameters object defined by params.
 void setPosition(int pos)
           
 java.lang.String toString()
          Returns a textual description of this instruction instance.
 
Methods inherited from class net.sf.rej.java.instruction.Instruction
createNewInstance, getLabels, getPoppedElements, getPushedElements, getSize
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Label

public Label(int pos)

Label

public Label(int pos,
             java.lang.String id)
Method Detail

setPosition

public void setPosition(int pos)

getSize

public int getSize()
Description copied from class: Instruction
Return the size of this instruction.

Specified by:
getSize in class Instruction
Returns:
Size of the instruction in bytes.

getOpcode

public int getOpcode()
Description copied from class: Instruction
Return the Opcode of this instruction.

Specified by:
getOpcode in class Instruction
Returns:
The Opcode value of this instruction.

getMnemonic

public java.lang.String getMnemonic()
Description copied from class: Instruction
Return the mnemonic of this instruction. Such as aload, invokespecial, nop, etc..

Specified by:
getMnemonic in class Instruction
Returns:
mnemonic.

execute

public void execute(ExecutionContext ec)
Description copied from class: Instruction
Reserved for possible future use.

Specified by:
execute in class Instruction
Parameters:
ec - Context for execution.

getPosition

public int getPosition()

getId

public java.lang.String getId()

toString

public java.lang.String toString()
Description copied from class: Instruction
Returns a textual description of this instruction instance. The default implementation just returns the Mnemonic returned by getMnemonic().

Overrides:
toString in class Instruction
Returns:
Description

setData

public void setData(byte[] data,
                    DecompilationContext dc)
Description copied from class: Instruction
Set the data for this instruction. Called by the decompiler to initialize the parameters of the instruction from bytecode data.

Specified by:
setData in class Instruction
Parameters:
data - A byte arrray with the instruction data, starting with the opcode byte(s) and followed by any parameters if applicable.
dc - A callback mechanism to offer the instruction information about the context where it's located.

getData

public byte[] getData(DecompilationContext dc)
Description copied from class: Instruction
Get the bytecode data for this instruction. In other words, tell the instruction to serialize itself. Some instructions use padding to put the subsequent parameters in a pc position that is divisible by 4 and thus require the pc position which they can obtain from the DecompilationContext

Specified by:
getData in class Instruction
Parameters:
dc - A callback mechanism to offer the instruction information about the context where it's located.
Returns:
A byte array with the instruction data.

getParameterTypes

public Parameters getParameterTypes()
Description copied from class: Instruction
Return a Parameters object describing the types of parameters(if any) that are applicable to this type of an instruction. This method is identical to the getParameters() method, only the Parameters object return by a call to this method, does not contain the values of the parameters, just the type information.

Specified by:
getParameterTypes in class Instruction
Returns:
A Parameters object with the types of parameters applicable for this type of an instruction.

getParameters

public Parameters getParameters()
Description copied from class: Instruction
Return a Parameters object describing the types of parameters(if any) and the values set to this particular instance for those parameters. For different parameter types see the Parameters class. Modifications in the values of the parameters class are not reflected by this instruction unless setParameters(Parameters) is called subsequently.

Specified by:
getParameters in class Instruction
Returns:
A Parameters object with the types and current values of the parameters.

setParameters

public void setParameters(Parameters params)
Description copied from class: Instruction
Update the parameter values of this instruction with the values in the Parameters object defined by params. Observe that the types and count of the parameters in the Parameters object MUST match those that this instruction expects. This can be ensured by obtaining the Parameters object with a call to getParameters() of this instruction.

Specified by:
setParameters in class Instruction
Parameters:
params - A Parameters object with new values for this instruction.