@@ -5,8 +5,8 @@ import java.util.concurrent.atomic.AtomicInteger
5
5
6
6
import scala .reflect .internal .ModifierFlags
7
7
import scala .reflect .internal .util .SourceFile
8
- import scala .tools .nsc ._
9
- import scala .tools .nsc .plugins .{Plugin , PluginComponent }
8
+ import scala .tools .nsc .Global
9
+ import scala .tools .nsc .plugins .{PluginComponent , Plugin }
10
10
import scala .tools .nsc .transform .{Transform , TypingTransformers }
11
11
12
12
/** @author Stephen Samuel */
@@ -142,6 +142,16 @@ class ScoverageInstrumentationComponent(val global: Global)
142
142
143
143
def transformStatements (trees : List [Tree ]): List [Tree ] = trees.map(process)
144
144
145
+ def transformForCases (cases : List [CaseDef ]): List [CaseDef ] = {
146
+ // we don't instrument the synthetic case _ => false clause
147
+ cases.dropRight(1 ).map(c => {
148
+ treeCopy.CaseDef (
149
+ // in a for-loop we don't care about instrumenting the guards, as they are synthetically generated
150
+ c, c.pat, process(c.guard), process(c.body)
151
+ )
152
+ }) ++ cases.takeRight(1 )
153
+ }
154
+
145
155
def transformCases (cases : List [CaseDef ]): List [CaseDef ] = {
146
156
cases.map(c => {
147
157
treeCopy.CaseDef (
@@ -167,7 +177,7 @@ class ScoverageInstrumentationComponent(val global: Global)
167
177
safeStart(tree),
168
178
safeEnd(tree),
169
179
safeLine(tree),
170
- original.toString() ,
180
+ original.toString,
171
181
Option (original.symbol).fold(" <nosymbol>" )(_.fullNameString),
172
182
tree.getClass.getSimpleName,
173
183
branch
@@ -225,6 +235,8 @@ class ScoverageInstrumentationComponent(val global: Global)
225
235
def traverseApplication (t : Tree ): Tree = {
226
236
t match {
227
237
case a : ApplyToImplicitArgs => treeCopy.Apply (a, traverseApplication(a.fun), transformStatements(a.args))
238
+ case Apply (Select (_, TermName (" withFilter" )), List (fun@ Function (params, body)))
239
+ if fun.symbol.isSynthetic && fun.toString.contains(" check$ifrefutable$1" ) => t
228
240
case a : Apply => treeCopy.Apply (a, traverseApplication(a.fun), transformStatements(a.args))
229
241
case a : TypeApply => treeCopy.TypeApply (a, traverseApplication(a.fun), transformStatements(a.args))
230
242
case s : Select => treeCopy.Select (s, traverseApplication(s.qualifier), s.name)
@@ -323,11 +335,6 @@ class ScoverageInstrumentationComponent(val global: Global)
323
335
// ignore macro definitions in 2.11
324
336
case DefDef (mods, _, _, _, _, _) if mods.isMacro => tree
325
337
326
- case d : DefDef =>
327
- println(d)
328
- val e = d
329
- d
330
-
331
338
// this will catch methods defined as macros, eg def test = macro testImpl
332
339
// it will not catch macro implemenations
333
340
case d : DefDef if d.symbol != null
@@ -428,16 +435,17 @@ class ScoverageInstrumentationComponent(val global: Global)
428
435
// pattern match clauses will be instrumented per case
429
436
case m@ Match (selector : Tree , cases : List [CaseDef ]) =>
430
437
// we can be fairly sure this was generated as part of a for loop
431
- if (selector.toString() .contains(" check$" )
438
+ if (selector.toString.contains(" check$" )
432
439
&& selector.tpe.annotations.mkString == " unchecked"
433
440
&& m.cases.last.toString == " case _ => false" ) {
434
- // todo check these assumptions for 2.11
435
- treeCopy
436
- .Match (tree, instrument(selector, selector), transformCases(cases.dropRight(1 )) ++ cases.takeRight(1 ))
441
+ treeCopy.Match (tree, process(selector), transformForCases(cases))
437
442
} else {
438
- if (selector.symbol.isSynthetic)
443
+ // if the selector was added by compiler, we don't want to instrument it....
444
+ // that usually means some construct is being transformed into a match
445
+ if (Option (selector.symbol).exists(_.isSynthetic))
439
446
treeCopy.Match (tree, selector, transformCases(cases))
440
447
else
448
+ // .. but we will if it was a user match
441
449
treeCopy.Match (tree, process(selector), transformCases(cases))
442
450
}
443
451
0 commit comments