Package org.objectweb.asm.tree
Class InsnList
java.lang.Object
org.objectweb.asm.tree.InsnList
- All Implemented Interfaces:
Iterable<AbstractInsnNode>
A doubly linked list of
AbstractInsnNode
objects. This implementation is not thread
safe.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(org.objectweb.asm.MethodVisitor methodVisitor) Makes the given visitor visit all the instructions in this list.void
add
(AbstractInsnNode insnNode) Adds the given instruction to the end of this list.void
Adds the given instructions to the end of this list.void
clear()
Removes all the instructions of this list.boolean
contains
(AbstractInsnNode insnNode) Returns true if the given instruction belongs to this list.get
(int index) Returns the instruction whose index is given.getFirst()
Returns the first instruction in this list.getLast()
Returns the last instruction in this list.int
indexOf
(AbstractInsnNode insnNode) Returns the index of the given instruction in this list.void
insert
(AbstractInsnNode insnNode) Inserts the given instruction at the beginning of this list.void
insert
(AbstractInsnNode previousInsn, AbstractInsnNode insnNode) Inserts the given instruction after the specified instruction.void
insert
(AbstractInsnNode previousInsn, InsnList insnList) Inserts the given instructions after the specified instruction.void
Inserts the given instructions at the beginning of this list.void
insertBefore
(AbstractInsnNode nextInsn, AbstractInsnNode insnNode) Inserts the given instruction before the specified instruction.void
insertBefore
(AbstractInsnNode nextInsn, InsnList insnList) Inserts the given instructions before the specified instruction.iterator()
Returns an iterator over the instructions in this list.iterator
(int index) Returns an iterator over the instructions in this list.void
remove
(AbstractInsnNode insnNode) Removes the given instruction from this list.void
Resets all the labels in the instruction list.void
set
(AbstractInsnNode oldInsnNode, AbstractInsnNode newInsnNode) Replaces an instruction of this list with another instruction.int
size()
Returns the number of instructions in this list.toArray()
Returns an array containing all the instructions in this list.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
InsnList
public InsnList()
-
-
Method Details
-
size
public int size()Returns the number of instructions in this list.- Returns:
- the number of instructions in this list.
-
getFirst
Returns the first instruction in this list.- Returns:
- the first instruction in this list, or null if the list is empty.
-
getLast
Returns the last instruction in this list.- Returns:
- the last instruction in this list, or null if the list is empty.
-
get
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 runs 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
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:
insnNode
- an instruction.- Returns:
- true if the given instruction belongs to this list.
-
indexOf
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:
insnNode
- 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(org.objectweb.asm.tree.AbstractInsnNode)
to test if an instruction belongs to an instruction list or not.
-
accept
public void accept(org.objectweb.asm.MethodVisitor methodVisitor) Makes the given visitor visit all the instructions in this list.- Parameters:
methodVisitor
- the method visitor that must visit the instructions.
-
iterator
Returns an iterator over the instructions in this list.- Specified by:
iterator
in interfaceIterable<AbstractInsnNode>
- Returns:
- an iterator over the instructions in this list.
-
iterator
Returns an iterator over the instructions in this list.- Parameters:
index
- index of instruction for the iterator to start at.- Returns:
- an iterator over the instructions in this list.
-
toArray
Returns an array containing all the instructions in this list.- Returns:
- an array containing all the instructions in this list.
-
set
Replaces an instruction of this list with another instruction.- Parameters:
oldInsnNode
- an instruction of this list.newInsnNode
- another instruction, which must not belong to anyInsnList
.
-
add
Adds the given instruction to the end of this list.- Parameters:
insnNode
- an instruction, which must not belong to anyInsnList
.
-
add
Adds the given instructions to the end of this list.- Parameters:
insnList
- an instruction list, which is cleared during the process. This list must be different from 'this'.
-
insert
Inserts the given instruction at the beginning of this list.- Parameters:
insnNode
- an instruction, which must not belong to anyInsnList
.
-
insert
Inserts the given instructions at the beginning of this list.- Parameters:
insnList
- an instruction list, which is cleared during the process. This list must be different from 'this'.
-
insert
Inserts the given instruction after the specified instruction.- Parameters:
previousInsn
- an instruction of this list after which insnNode must be inserted.insnNode
- the instruction to be inserted, which must not belong to anyInsnList
.
-
insert
Inserts the given instructions after the specified instruction.- Parameters:
previousInsn
- an instruction of this list after which the instructions must be inserted.insnList
- the instruction list to be inserted, which is cleared during the process. This list must be different from 'this'.
-
insertBefore
Inserts the given instruction before the specified instruction.- Parameters:
nextInsn
- an instruction of this list before which insnNode must be inserted.insnNode
- the instruction to be inserted, which must not belong to anyInsnList
.
-
insertBefore
Inserts the given instructions before the specified instruction.- Parameters:
nextInsn
- an instruction of this list before which the instructions must be inserted.insnList
- the instruction list to be inserted, which is cleared during the process. This list must be different from 'this'.
-
remove
Removes the given instruction from this list.- Parameters:
insnNode
- the instruction of this list that must be removed.
-
clear
public void clear()Removes all the instructions of this list. -
resetLabels
public void resetLabels()Resets all the labels in the instruction list. This method should be called before reusing an instruction list between severalClassWriter
s.
-