Package ftbsc.lll.utils
Class InsnSequence
- java.lang.Object
-
- org.objectweb.asm.tree.InsnList
-
- ftbsc.lll.utils.InsnSequence
-
- All Implemented Interfaces:
java.lang.Iterable<org.objectweb.asm.tree.AbstractInsnNode>
public class InsnSequence extends org.objectweb.asm.tree.InsnList
Represents a sequence of instructions contained within two given nodes. ExtendsInsnList
, but provides additional flexibility and features.
-
-
Constructor Summary
Constructors Constructor Description InsnSequence()
Public constructor.InsnSequence(org.objectweb.asm.tree.AbstractInsnNode node)
Public constructor for list with single item.InsnSequence(org.objectweb.asm.tree.AbstractInsnNode startNode, org.objectweb.asm.tree.AbstractInsnNode endNode)
Public constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(org.objectweb.asm.tree.AbstractInsnNode node)
Wraps InsnList's add() to throw an exception when given null values.void
add(org.objectweb.asm.tree.AbstractInsnNode... nodes)
Adds an array of nodes to the list.void
cut(int amount, boolean reverse)
Cut a number of nodes from the list.org.objectweb.asm.tree.AbstractInsnNode
get(int index)
Extends the existing get function from InsnList to allow for negative indexes.boolean
replace(int opcode, org.objectweb.asm.tree.AbstractInsnNode newNode, int amount)
Replaces n occurrences of said opcode with the given node.boolean
replace(int opcode, org.objectweb.asm.tree.AbstractInsnNode newNode, int amount, boolean reverse)
Replaces n occurrences of said opcode with the given node.void
replaceNode(org.objectweb.asm.tree.AbstractInsnNode oldNode, org.objectweb.asm.tree.AbstractInsnNode newNode)
Replaces a node with another one.-
Methods inherited from class org.objectweb.asm.tree.InsnList
accept, add, clear, contains, getFirst, getLast, indexOf, insert, insert, insert, insert, insertBefore, insertBefore, iterator, iterator, remove, resetLabels, set, size, toArray
-
-
-
-
Constructor Detail
-
InsnSequence
public InsnSequence()
Public constructor. This creates an empty sequence.
-
InsnSequence
public InsnSequence(org.objectweb.asm.tree.AbstractInsnNode node)
Public constructor for list with single item. Must be given a single non-null node.- Parameters:
node
- the node in question
-
InsnSequence
public InsnSequence(org.objectweb.asm.tree.AbstractInsnNode startNode, org.objectweb.asm.tree.AbstractInsnNode endNode)
Public constructor. Must be given two non-null, connected nodes.- Parameters:
startNode
- the starting node of the patternendNode
- the first node of the pattern
-
-
Method Detail
-
get
public org.objectweb.asm.tree.AbstractInsnNode get(int index)
Extends the existing get function from InsnList to allow for negative indexes.- Overrides:
get
in classorg.objectweb.asm.tree.InsnList
- Parameters:
index
- the index of the instruction that must be returned- Returns:
- the instruction whose index is given
-
add
public void add(org.objectweb.asm.tree.AbstractInsnNode... nodes)
Adds an array of nodes to the list.- Parameters:
nodes
- the nodes to add
-
add
public void add(org.objectweb.asm.tree.AbstractInsnNode node)
Wraps InsnList's add() to throw an exception when given null values.- Overrides:
add
in classorg.objectweb.asm.tree.InsnList
- Parameters:
node
- to add
-
replaceNode
public void replaceNode(org.objectweb.asm.tree.AbstractInsnNode oldNode, org.objectweb.asm.tree.AbstractInsnNode newNode)
Replaces a node with another one. Mostly used internally.- Parameters:
oldNode
- node to replacenewNode
- new node
-
replace
public boolean replace(int opcode, org.objectweb.asm.tree.AbstractInsnNode newNode, int amount)
Replaces n occurrences of said opcode with the given node.- Parameters:
opcode
- the opcode to replacenewNode
- the replacement nodeamount
- how many occurrences to replace, set to 0 to replace all- Returns:
- true if anything was changed, false otherwise
-
replace
public boolean replace(int opcode, org.objectweb.asm.tree.AbstractInsnNode newNode, int amount, boolean reverse)
Replaces n occurrences of said opcode with the given node.- Parameters:
opcode
- the opcode to replacenewNode
- the replacement nodereverse
- whether the search should be done from the endamount
- how many occurrences to replace, set to 0 to replace all- Returns:
- true if anything was changed, false otherwise
-
cut
public void cut(int amount, boolean reverse)
Cut a number of nodes from the list.- Parameters:
amount
- how many nodes to cutreverse
- true if should cut from the end, false otherwise
-
-