InsnList (ASM 5.0.4 Documentation)
Date: 2015-09-18

org.objectweb.asm.tree

## Class InsnList

- java.lang.Object
- - org.objectweb.asm.tree.InsnList

-     public class InsnList
      extends Object

  A doubly linked list of `AbstractInsnNode` objects. This implementation is not thread safe.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `InsnList()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `accept(MethodVisitor mv)` Makes the given visitor visit all of the instructions in this list.
    `void` | `add(AbstractInsnNode insn)` Adds the given instruction to the end of this list.
    `void` | `add(InsnList insns)` Adds the given instructions to the end of this list.
    `void` | `clear()` Removes all of the instructions of this list.
    `boolean` | `contains(AbstractInsnNode insn)` Returns `true` if the given instruction belongs to this list.
    `AbstractInsnNode` | `get(int index)` Returns the instruction whose index is given.
    `AbstractInsnNode` | `getFirst()` Returns the first instruction in this list.
    `AbstractInsnNode` | `getLast()` Returns the last instruction in this list.
    `int` | `indexOf(AbstractInsnNode insn)` Returns the index of the given instruction in this list.
    `void` | `insert(AbstractInsnNode insn)` Inserts the given instruction at the begining of this list.
    `void` | `insert(AbstractInsnNode location, AbstractInsnNode insn)` Inserts the given instruction after the specified instruction.
    `void` | `insert(AbstractInsnNode location, InsnList insns)` Inserts the given instructions after the specified instruction.
    `void` | `insert(InsnList insns)` Inserts the given instructions at the begining of this list.
    `void` | `insertBefore(AbstractInsnNode location, AbstractInsnNode insn)` Inserts the given instruction before the specified instruction.
    `void` | `insertBefore(AbstractInsnNode location, InsnList insns)` Inserts the given instructions before the specified instruction.
    `ListIterator<AbstractInsnNode>` | `iterator()` Returns an iterator over the instructions in this list.
    `ListIterator<AbstractInsnNode>` | `iterator(int index)` Returns an iterator over the instructions in this list.
    `void` | `remove(AbstractInsnNode insn)` Removes the given instruction from this list.
    `void` | `resetLabels()` Reset all labels in the instruction list.
    `void` | `set(AbstractInsnNode location, AbstractInsnNode insn)` Replaces an instruction of this list with another instruction.
    `int` | `size()` Returns the number of instructions in this list.
    `AbstractInsnNode[]` | `toArray()` Returns an array containing all of the instructions in this list.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### InsnList

          public InsnList()

  - ### Method Detail

    - #### size

          public int size()

      Returns the number of instructions in this list.
      Returns:
        the number of instructions in this list.

    - #### getFirst

          public AbstractInsnNode getFirst()

      Returns the first instruction in this list.
      Returns:
        the first instruction in this list, or `null` if the list is empty.

    - #### getLast

          public AbstractInsnNode getLast()

      Returns the last instruction in this list.
      Returns:
        the last instruction in this list, or `null` if the list is empty.

    - #### get

          public AbstractInsnNode get(int index)

      Returns the instruction whose index is given. This method builds a cache of the instructions in this list to avoid scanning the whole list each time it is called. Once the cache is built, this method run in constant time. This cache is invalidated by all the methods that modify the list.
      Parameters:
        `index` - the index of the instruction that must be returned.
      Returns:
        the instruction whose index is given.
      Throws:
        `IndexOutOfBoundsException` - if (index < 0 || index >= size()).

    - #### contains

          public boolean contains(AbstractInsnNode insn)

      Returns `true` if the given instruction belongs to this list. This method always scans the instructions of this list until it finds the given instruction or reaches the end of the list.
      Parameters:
        `insn` - an instruction.
      Returns:
        `true` if the given instruction belongs to this list.

    - #### indexOf

          public int indexOf(AbstractInsnNode insn)

      Returns the index of the given instruction in this list. This method builds a cache of the instruction indexes to avoid scanning the whole list each time it is called. Once the cache is built, this method run in constant time. The cache is invalidated by all the methods that modify the list.
      Parameters:
        `insn` - an instruction of this list.
      Returns:
        the index of the given instruction in this list. The result of this method is undefined if the given instruction does not belong to this list. Use `contains` to test if an instruction belongs to an instruction list or not.

    - #### accept

          public void accept(MethodVisitor mv)

      Makes the given visitor visit all of the instructions in this list.
      Parameters:
        `mv` - the method visitor that must visit the instructions.

    - #### iterator

          public ListIterator<AbstractInsnNode> iterator()

      Returns an iterator over the instructions in this list.
      Returns:
        an iterator over the instructions in this list.

    - #### iterator

          public ListIterator<AbstractInsnNode> iterator(int index)

      Returns an iterator over the instructions in this list.
      Returns:
        an iterator over the instructions in this list.

    - #### toArray

          public AbstractInsnNode[] toArray()

      Returns an array containing all of the instructions in this list.
      Returns:
        an array containing all of the instructions in this list.

    - #### set

          public void set(AbstractInsnNode location,
                 AbstractInsnNode insn)

      Replaces an instruction of this list with another instruction.
      Parameters:
        `location` - an instruction of this list.
        `insn` - another instruction, which must not belong to any `InsnList`.

    - #### add

          public void add(AbstractInsnNode insn)

      Adds the given instruction to the end of this list.
      Parameters:
        `insn` - an instruction, which must not belong to any `InsnList`.

    - #### add

          public void add(InsnList insns)

      Adds the given instructions to the end of this list.
      Parameters:
        `insns` - an instruction list, which is cleared during the process. This list must be different from 'this'.

    - #### insert

          public void insert(AbstractInsnNode insn)

      Inserts the given instruction at the begining of this list.
      Parameters:
        `insn` - an instruction, which must not belong to any `InsnList`.

    - #### insert

          public void insert(InsnList insns)

      Inserts the given instructions at the begining of this list.
      Parameters:
        `insns` - an instruction list, which is cleared during the process. This list must be different from 'this'.

    - #### insert

          public void insert(AbstractInsnNode location,
                    AbstractInsnNode insn)

      Inserts the given instruction after the specified instruction.
      Parameters:
        `location` - an instruction of this list after which insn must be inserted.
        `insn` - the instruction to be inserted, which must not belong to any `InsnList`.

    - #### insert

          public void insert(AbstractInsnNode location,
                    InsnList insns)

      Inserts the given instructions after the specified instruction.
      Parameters:
        `location` - an instruction of this list after which the instructions must be inserted.
        `insns` - the instruction list to be inserted, which is cleared during the process. This list must be different from 'this'.

    - #### insertBefore

          public void insertBefore(AbstractInsnNode location,
                          AbstractInsnNode insn)

      Inserts the given instruction before the specified instruction.
      Parameters:
        `location` - an instruction of this list before which insn must be inserted.
        `insn` - the instruction to be inserted, which must not belong to any `InsnList`.

    - #### insertBefore

          public void insertBefore(AbstractInsnNode location,
                          InsnList insns)

      Inserts the given instructions before the specified instruction.
      Parameters:
        `location` - an instruction of this list before which the instructions must be inserted.
        `insns` - the instruction list to be inserted, which is cleared during the process. This list must be different from 'this'.

    - #### remove

          public void remove(AbstractInsnNode insn)

      Removes the given instruction from this list.
      Parameters:
        `insn` - the instruction of this list that must be removed.

    - #### clear

          public void clear()

      Removes all of the instructions of this list.

    - #### resetLabels

          public void resetLabels()

      Reset all labels in the instruction list. This method should be called before reusing same instructions list between several `ClassWriter`s.