@@ -138,10 +138,6 @@ class ScoverageInstrumentationComponent(val global: Global)
138
138
139
139
override def transform (tree : Tree ) = process(tree)
140
140
141
- def transformIf (tree : Tree ) = {
142
- instrument(process(tree), true )
143
- }
144
-
145
141
def transformStatements (trees : List [Tree ]): List [Tree ] = trees.map(process)
146
142
147
143
def transformCases (cases : List [CaseDef ]): List [CaseDef ] = {
@@ -260,7 +256,8 @@ class ScoverageInstrumentationComponent(val global: Global)
260
256
261
257
/**
262
258
* When an apply has no parameters, or is an application of purely literals or idents
263
- * then we can simply instrument the outer call.
259
+ * then we can simply instrument the outer call. Ie, we can treat it all as one single statement
260
+ * for the purposes of code coverage.
264
261
* This will include calls to case apply.
265
262
*/
266
263
case a : GenericApply if allConstArgs(a.args) => instrument(a)
@@ -402,8 +399,12 @@ class ScoverageInstrumentationComponent(val global: Global)
402
399
403
400
case _ : Ident => tree
404
401
402
+ // the If statement itself doesn't need to be instrumented, because instrumenting the condition is
403
+ // enough to determine if the If statement was executed.
404
+ // The two procedures (then and else) are instrumented seperately to determine if we entered
405
+ // both branches.
405
406
case i : If =>
406
- treeCopy.If (i, process(i.cond), transformIf( i.thenp), transformIf( i.elsep))
407
+ treeCopy.If (i, process(i.cond), instrument(process( i.thenp), true ), instrument(process( i.elsep), true ))
407
408
408
409
case _ : Import => tree
409
410
@@ -477,6 +478,7 @@ class ScoverageInstrumentationComponent(val global: Global)
477
478
// This AST node corresponds to the following Scala code: `return` expr
478
479
case r : Return =>
479
480
treeCopy.Return (r, transform(r.expr))
481
+
480
482
/** pattern match with syntax `Select(qual, name)`.
481
483
* This AST node corresponds to the following Scala code:
482
484
*
0 commit comments