Class InstructionsBuilder
- java.lang.Object
-
- org.jacoco.core.internal.analysis.InstructionsBuilder
-
class InstructionsBuilder extends java.lang.Object
Stateful builder for theInstruction
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 thegetInstructions()
method.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
InstructionsBuilder.Jump
-
Field Summary
Fields Modifier and Type Field Description private Instruction
currentInsn
The last instruction which has been added.private java.util.List<org.objectweb.asm.Label>
currentLabel
The labels which mark the subsequent instructions.private int
currentLine
The line which belong to subsequently added instructions.private java.util.Map<org.objectweb.asm.tree.AbstractInsnNode,Instruction>
instructions
All instructions of a method mapped from the ASM node to the correspondingInstruction
instance.private java.util.List<InstructionsBuilder.Jump>
jumps
List of all jumps within the control flow.private boolean[]
probes
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
All Methods Instance Methods Concrete Methods 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) java.util.Map<org.objectweb.asm.tree.AbstractInsnNode,Instruction>
getInstructions()
Returns the status for all instructions of this method.(package private) void
noSuccessor()
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 Detail
-
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 java.util.Map<org.objectweb.asm.tree.AbstractInsnNode,Instruction> instructions
All instructions of a method mapped from the ASM node to the correspondingInstruction
instance.
-
currentLabel
private final java.util.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 java.util.List<InstructionsBuilder.Jump> jumps
List of all jumps within the control flow. We need to store jumps temporarily as the targetInstruction
may not been known yet.
-
-
Method Detail
-
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
java.util.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
-
-