Class InstructionsBuilder
java.lang.Object
org.jacoco.core.internal.analysis.InstructionsBuilder
Stateful builder for the
Instruction
s 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 -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate 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 correspondingInstruction
instance.private final List
<InstructionsBuilder.Jump> List of all jumps within the control flow.private final boolean[]
Probe array of the class the analyzed method belongs to. -
Constructor Summary
ConstructorsConstructorDescriptionInstructionsBuilder
(boolean[] probes) Creates a new builder instance which can be used to analyze a single method. -
Method Summary
Modifier and TypeMethodDescription(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.
-
Field Details
-
probes
private final boolean[] probesProbe array of the class the analyzed method belongs to. -
currentLine
private int currentLineThe line which belong to subsequently added instructions. -
currentInsn
The last instruction which has been added. -
instructions
All instructions of a method mapped from the ASM node to the correspondingInstruction
instance. -
currentLabel
The labels which mark the subsequent instructions. Due to ASM issue #315745 there can be more than one label per instruction -
jumps
List of all jumps within the control flow. We need to store jumps temporarily as the targetInstruction
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 multipleLabel
s 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 targetbranch
- unique branch number
-
addProbe
void addProbe(int probeId, int branch) Adds a new probe for the last instruction.- Parameters:
probeId
- index in the probe arraybranch
- 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
-