Class 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. Extends InsnList, 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
      • 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 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 pattern
        endNode - 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 class org.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 class org.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 replace
        newNode - 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 replace
        newNode - the replacement node
        amount - 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 replace
        newNode - the replacement node
        reverse - whether the search should be done from the end
        amount - 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 cut
        reverse - true if should cut from the end, false otherwise