Class InstructionsBuilder

java.lang.Object
org.jacoco.core.internal.analysis.InstructionsBuilder

class InstructionsBuilder extends Object
Stateful builder for the Instructions of a method. All instructions of a method must be added in their original sequence along with additional information like line numbers. Afterwards the instructions can be obtained with the getInstructions() method.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private Instruction
    The last instruction which has been added.
    private final List<org.objectweb.asm.Label>
    The labels which mark the subsequent instructions.
    private int
    The line which belong to subsequently added instructions.
    private final Map<org.objectweb.asm.tree.AbstractInsnNode,Instruction>
    All instructions of a method mapped from the ASM node to the corresponding Instruction instance.
    List of all jumps within the control flow.
    private final boolean[]
    Probe array of the class the analyzed method belongs to.
  • Constructor Summary

    Constructors
    Constructor
    Description
    InstructionsBuilder(boolean[] probes)
    Creates a new builder instance which can be used to analyze a single method.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) void
    addInstruction(org.objectweb.asm.tree.AbstractInsnNode node)
    Adds a new instruction.
    (package private) void
    addJump(org.objectweb.asm.Label target, int branch)
    Adds a jump from the last added instruction.
    (package private) void
    addLabel(org.objectweb.asm.Label label)
    Adds a label which applies to the subsequently added instruction.
    (package private) void
    addProbe(int probeId, int branch)
    Adds a new probe for the last instruction.
    (package private) Map<org.objectweb.asm.tree.AbstractInsnNode,Instruction>
    Returns the status for all instructions of this method.
    (package private) void
    Declares that the next instruction will not be a successor of the current instruction.
    (package private) void
    setCurrentLine(int line)
    Sets the current source line.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • probes

      private final boolean[] probes
      Probe array of the class the analyzed method belongs to.
    • currentLine

      private int currentLine
      The line which belong to subsequently added instructions.
    • currentInsn

      private Instruction currentInsn
      The last instruction which has been added.
    • instructions

      private final Map<org.objectweb.asm.tree.AbstractInsnNode,Instruction> instructions
      All instructions of a method mapped from the ASM node to the corresponding Instruction instance.
    • currentLabel

      private final List<org.objectweb.asm.Label> currentLabel
      The labels which mark the subsequent instructions. Due to ASM issue #315745 there can be more than one label per instruction
    • jumps

      private final List<InstructionsBuilder.Jump> jumps
      List of all jumps within the control flow. We need to store jumps temporarily as the target Instruction may not been known yet.
  • Constructor Details

    • InstructionsBuilder

      InstructionsBuilder(boolean[] probes)
      Creates a new builder instance which can be used to analyze a single method.
      Parameters:
      probes - probe array of the corresponding class used to determine the coverage status of every instruction.
  • Method Details

    • setCurrentLine

      void setCurrentLine(int line)
      Sets the current source line. All subsequently added instructions will be assigned to this line. If no line is set (e.g. for classes compiled without debug information) ISourceNode.UNKNOWN_LINE is assigned to the instructions.
    • addLabel

      void addLabel(org.objectweb.asm.Label label)
      Adds a label which applies to the subsequently added instruction. Due to ASM internals multiple Labels can be added to an instruction.
    • addInstruction

      void addInstruction(org.objectweb.asm.tree.AbstractInsnNode node)
      Adds a new instruction. Instructions are by default linked with the previous instruction unless specified otherwise.
    • noSuccessor

      void noSuccessor()
      Declares that the next instruction will not be a successor of the current instruction. This is the case with an unconditional jump or technically when a probe was inserted before.
    • addJump

      void addJump(org.objectweb.asm.Label target, int branch)
      Adds a jump from the last added instruction.
      Parameters:
      target - jump target
      branch - unique branch number
    • addProbe

      void addProbe(int probeId, int branch)
      Adds a new probe for the last instruction.
      Parameters:
      probeId - index in the probe array
      branch - unique branch number for the last instruction
    • getInstructions

      Map<org.objectweb.asm.tree.AbstractInsnNode,Instruction> getInstructions()
      Returns the status for all instructions of this method. This method must be called exactly once after the instructions have been added.
      Returns:
      map of ASM instruction nodes to corresponding Instruction instances