Class Instruction
java.lang.Object
org.jacoco.core.internal.analysis.Instruction
Execution status of a single bytecode instruction internally used for
coverage analysis. The execution status is recorded separately for each
outgoing branch. Each instruction has at least one branch, for example in
case of a simple sequence of instructions (by convention branch 0). Instances
of this class are used in two steps:
Step 1: Building the CFG
For each bytecode instruction of a method aInstruction
instance is
created. In correspondence with the CFG these instances are linked with each
other with the addBranch()
methods. The executions status is
either directly derived from a probe which has been inserted in the execution
flow (addBranch(boolean, int)
) or indirectly propagated along the
CFG edges (addBranch(Instruction, int)
).
Step 2: Querying the Coverage Status
After all instructions have been created and linked each instruction knows its execution status and can be queried with: For the purpose of filtering instructions can be combined to new instructions. Note that these methods create newInstruction
instances and do not modify the existing ones.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
private final BitSet
private final int
private Instruction
private int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addBranch
(boolean executed, int branch) Adds a branch to this instruction which execution status is directly derived from a probe.void
addBranch
(Instruction target, int branch) Adds a branch to this instruction which execution status is indirectly derived from the execution status of the target instruction.Returns the branch coverage counter of this instruction.Returns the instruction coverage counter of this instruction.int
getLine()
Returns the source line this instruction belongs to.merge
(Instruction other) Merges information about covered branches of this instruction with another instruction.private static void
propagateExecutedBranch
(Instruction insn, int branch) replaceBranches
(Collection<Instruction> newBranches) Creates a copy of this instruction where all outgoing branches are replaced with the given instructions.
-
Field Details
-
line
private final int line -
branches
private int branches -
coveredBranches
-
predecessor
-
predecessorBranch
private int predecessorBranch
-
-
Constructor Details
-
Instruction
public Instruction(int line) New instruction at the given line.- Parameters:
line
- source line this instruction belongs to
-
-
Method Details
-
addBranch
Adds a branch to this instruction which execution status is indirectly derived from the execution status of the target instruction. In case the branch is covered the status is propagated also to the predecessors of this instruction. Note: This method is not idempotent and must be called exactly once for every branch.- Parameters:
target
- target instruction of this branchbranch
- branch identifier unique for this instruction
-
addBranch
public void addBranch(boolean executed, int branch) Adds a branch to this instruction which execution status is directly derived from a probe. In case the branch is covered the status is propagated also to the predecessors of this instruction. Note: This method is not idempotent and must be called exactly once for every branch.- Parameters:
executed
- whether the corresponding probe has been executedbranch
- branch identifier unique for this instruction
-
propagateExecutedBranch
-
getLine
public int getLine()Returns the source line this instruction belongs to.- Returns:
- corresponding source line
-
merge
Merges information about covered branches of this instruction with another instruction.- Parameters:
other
- instruction to merge with- Returns:
- new instance with merged branches
-
replaceBranches
Creates a copy of this instruction where all outgoing branches are replaced with the given instructions. The coverage status of the new instruction is derived from the status of the given instructions.- Parameters:
newBranches
- new branches to consider- Returns:
- new instance with replaced branches
-
getInstructionCounter
Returns the instruction coverage counter of this instruction. It is always 1 instruction which is covered or not.- Returns:
- the instruction coverage counter
-
getBranchCounter
Returns the branch coverage counter of this instruction. Only instructions with at least 2 outgoing edges report branches.- Returns:
- the branch coverage counter
-