Overview | Package | Class | Tree | Deprecated | Index | Help
| ej-technologies
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.gjt.jclasslib.bytecode
Class CodeInsertion

    java.lang.Object
      org.gjt.jclasslib.bytecode.CodeInsertion

public class CodeInsertion
extends Object

Contains all information necessary to insert code into a method. Allows for pre and post insertions. The core method to perform code insertions is the static `apply` method.

Version:
  $Revision: 1.8 $ $Date: 2003/08/18 07:58:35 $
Author:
  Ingo Kegel

Constructor Summary
`CodeInsertion(int position, AbstractInstruction[] preInstructions, AbstractInstruction[] postInstructions, boolean shiftTarget)` Create a code insertion.

Method Summary
`static List` | `apply(List instructions, List codeInsertions, CodeAttribute codeAttribute)` Apply a list of `CodeInsertion`s to a list of instructions such as the one supplied by a `ByteCodeReader`.
`int` | `getPosition()` Get the insertion position, i.e the instruction number to which this `CodeInsertion` is to be applied.
`AbstractInstruction[]` | `getPostInstructions()` Get the instructions to be inserted after the insertion point.
`AbstractInstruction[]` | `getPreInstructions()` Get the instructions to be inserted before the insertion point.
`boolean` | `isShiftTarget()` Get whether offsets of branch instructions pointing to the position of the resulting code insertion should be shifted to the first pre-instruction or continue to point at the original instruction.
`static CodeInsertion` | `merge(int position, boolean shiftTarget, CodeInsertion inner, CodeInsertion outer)` Merge two code insertions into one.
`static AbstractInstruction[]` | `mergeInstructions(AbstractInstruction[] firstInstructions, AbstractInstruction[] lastInstructions)` Merge two arrays of instructions into one.
`void` | `setPosition(int position)` Set the insertion position, i.e the instruction number to which this `CodeInsertion` is to be applied.
`void` | `setPostInstructions(AbstractInstruction[] postInstructions)` Set the instructions to be inserted after the insertion point.
`void` | `setPreInstructions(AbstractInstruction[] preInstructions)` Set the instructions to be inserted before the insertion point.
`void` | `setShiftTarget(boolean shiftTarget)` Set whether offsets of branch instructions pointing to the position of the resulting code insertion should be shifted to the first pre-instruction or continue to point at the original instruction.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### CodeInsertion

    public CodeInsertion(int position,
                         AbstractInstruction[] preInstructions,
                         AbstractInstruction[] postInstructions,
                         boolean shiftTarget)

  Create a code insertion.

Parameters:
  `position` - the instruction number to which this `CodeInsertion` is to be applied. Corresponds to the index in the list of instructions such as the one returned by a `ByteCodeReader`.
  `preInstructions` - the instructions to be inserted before the insertion point.
  `postInstructions` - the instructions to be inserted after the insertion point.
  `shiftTarget` - should offsets of branch instructions pointing to the position of this code insertion be shifted or point to the beginning of the code inserted via the `preInstructions` parameters.

Method Detail

### merge

    public static CodeInsertion merge(int position,
                                      boolean shiftTarget,
                                      CodeInsertion inner,
                                      CodeInsertion outer)

  Merge two code insertions into one.

  Parameters:
    `position` - the position of the resulting `CodeInsertion`
    `shiftTarget` - should offsets of branch instructions pointing to the position of the resulting code insertion be shifted or point to the beginning of the inserted code.
    `inner` - the inner `CodeInsertion`
    `outer` - the outer `CodeInsertion`
  Returns:
    the resulting `CodeInsertion`

### mergeInstructions

    public static AbstractInstruction[] mergeInstructions(AbstractInstruction[] firstInstructions,
                                                          AbstractInstruction[] lastInstructions)

  Merge two arrays of instructions into one.

  Parameters:
    `firstInstructions` - the head array of type `AbstractInstruction`
    `lastInstructions` - the tail array of type `AbstractInstruction`
  Returns:
    the merged array of type `AbstractInstruction[]`

### apply

    public static List apply(List instructions,
                             List codeInsertions,
                             CodeAttribute codeAttribute)
                      throws InvalidByteCodeException

  Apply a list of `CodeInsertion`s to a list of instructions such as the one supplied by a `ByteCodeReader`. Offsets of branch instructions will be adapted to point to the original instructions. Exception and line number tables in the associated `CodeAttribute`will also be updated.

  Parameters:
    `instructions` - the list of instructions which is to be treated with the `CodeInsertion`s. This list and the resulting instructions will not be usable after the method is finished. If you need to reuse the original instructions, you have to pass a deep-cloned list into this method.
    `codeInsertions` - the list of codeInsertions which is to be applied to the list of instructions.
    `codeAttribute` - the `CodeAttribute` pertaining to the supplied list of instructions.
  Returns:
    the resulting list of instructions
  Throws:
    `InvalidByteCodeException`

### getPosition

    public int getPosition()

  Get the insertion position, i.e the instruction number to which this `CodeInsertion` is to be applied. Corresponds to the index in the list of instructions such as the one returned by a `ByteCodeReader`.

  Returns:
    the insertion position

### setPosition

    public void setPosition(int position)

  Set the insertion position, i.e the instruction number to which this `CodeInsertion` is to be applied. Corresponds to the index in the list of instructions such as the one returned by a `ByteCodeReader`.

  Parameters:
    `position` - the insertion position

### getPreInstructions

    public AbstractInstruction[] getPreInstructions()

  Get the instructions to be inserted before the insertion point.

  Returns:
    array of instructions

### setPreInstructions

    public void setPreInstructions(AbstractInstruction[] preInstructions)

  Set the instructions to be inserted before the insertion point.

  Parameters:
    `preInstructions` - array of instructions

### getPostInstructions

    public AbstractInstruction[] getPostInstructions()

  Get the instructions to be inserted after the insertion point.

  Returns:
    array of instructions

### setPostInstructions

    public void setPostInstructions(AbstractInstruction[] postInstructions)

  Set the instructions to be inserted after the insertion point.

  Parameters:
    `postInstructions` - array of instructions

### isShiftTarget

    public boolean isShiftTarget()

  Get whether offsets of branch instructions pointing to the position of the resulting code insertion should be shifted to the first pre-instruction or continue to point at the original instruction.

  Returns:
    the boolean value

### setShiftTarget

    public void setShiftTarget(boolean shiftTarget)

  Set whether offsets of branch instructions pointing to the position of the resulting code insertion should be shifted to the first pre-instruction or continue to point at the original instruction.

  Parameters:
    `shiftTarget` - the boolean value.

Overview | Package | Class | Tree | Deprecated | Index | Help
| ej-technologies
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD