@@ -101,6 +101,7 @@ class ScoverageInstrumentationComponent(val global: Global)
101
101
102
102
import global ._
103
103
104
+ // contains the location of the last node
104
105
var location : Location = null
105
106
106
107
/**
@@ -185,33 +186,11 @@ class ScoverageInstrumentationComponent(val global: Global)
185
186
def isFileIncluded (source : SourceFile ): Boolean = coverageFilter.isFileIncluded(source)
186
187
def isStatementIncluded (pos : Position ): Boolean = coverageFilter.isLineIncluded(pos)
187
188
188
- def className (s : Symbol ): String = {
189
- if (s.enclClass.isAnonymousFunction || s.enclClass.isAnonymousFunction)
190
- className(s.owner)
191
- else
192
- s.enclClass.nameString
193
- }
194
-
195
- def enclosingMethod (s : Symbol ): String = {
196
- if (s.enclClass.isAnonymousFunction || s.enclClass.isAnonymousFunction)
197
- enclosingMethod(s.owner)
198
- else
199
- Option (s.owner.enclMethod.nameString).getOrElse(" <none>" )
200
- }
201
-
202
- def updateLocation (s : Symbol ) {
203
- val classType = {
204
- if (s.owner.enclClass.isTrait) ClassType .Trait
205
- else if (s.owner.enclClass.isModule) ClassType .Object
206
- else ClassType .Class
189
+ def updateLocation (t : Tree ) {
190
+ Location (global)(t) match {
191
+ case Some (loc) => this .location = loc
192
+ case _ => println(s " [warn] Cannot update location for $t" )
207
193
}
208
- location = Location (
209
- s.enclosingPackage.fullName,
210
- className(s),
211
- classType,
212
- enclosingMethod(s),
213
- s.sourceFile.canonicalPath
214
- )
215
194
}
216
195
217
196
def transformPartial (c : ClassDef ): ClassDef = {
@@ -331,7 +310,7 @@ class ScoverageInstrumentationComponent(val global: Global)
331
310
332
311
case c : ClassDef =>
333
312
if (isFileIncluded(c.pos.source) && isClassIncluded(c.symbol)) {
334
- updateLocation(c.symbol )
313
+ updateLocation(c)
335
314
super .transform(tree)
336
315
} else {
337
316
c
@@ -352,10 +331,13 @@ class ScoverageInstrumentationComponent(val global: Global)
352
331
case d : DefDef if d.symbol != null && d.tpt.symbol.fullNameString == " scala.reflect.api.Exprs.Expr" =>
353
332
tree
354
333
355
- // todo do we really want to ignore?
356
- case d : DefDef if d.symbol.isPrimaryConstructor => tree
357
- // todo definitely want to instrument user level constructors
358
- case d : DefDef if tree.symbol.isConstructor => tree
334
+ case d : DefDef if d.symbol.isPrimaryConstructor =>
335
+ updateLocation(d)
336
+ super .transform(d)
337
+
338
+ case d : DefDef if tree.symbol.isConstructor =>
339
+ updateLocation(d)
340
+ super .transform(d)
359
341
360
342
/**
361
343
* Case class accessors for vals
@@ -372,7 +354,7 @@ class ScoverageInstrumentationComponent(val global: Global)
372
354
* Lazy stable DefDefs are generated as the impl for lazy vals.
373
355
*/
374
356
case d : DefDef if d.symbol.isStable && d.symbol.isGetter && d.symbol.isLazy =>
375
- updateLocation(d.symbol )
357
+ updateLocation(d)
376
358
treeCopy.DefDef (d, d.mods, d.name, d.tparams, d.vparamss, d.tpt, process(d.rhs))
377
359
378
360
/**
@@ -409,7 +391,7 @@ class ScoverageInstrumentationComponent(val global: Global)
409
391
* this is expressed by having `tpt` set to `TypeTree()` (but not to an `EmptyTree`!).
410
392
*/
411
393
case d : DefDef =>
412
- updateLocation(d.symbol )
394
+ updateLocation(d)
413
395
treeCopy.DefDef (d, d.mods, d.name, d.tparams, d.vparamss, d.tpt, process(d.rhs))
414
396
415
397
case EmptyTree => tree
@@ -445,16 +427,18 @@ class ScoverageInstrumentationComponent(val global: Global)
445
427
}
446
428
447
429
// a synthetic object is a generated object, such as case class companion
448
- case m : ModuleDef if m.symbol.isSynthetic => super .transform(tree)
430
+ case m : ModuleDef if m.symbol.isSynthetic =>
431
+ updateLocation(m)
432
+ super .transform(tree)
449
433
450
434
// user defined objects
451
435
case m : ModuleDef =>
452
436
if (isFileIncluded(m.pos.source) && isClassIncluded(m.symbol)) {
453
- updateLocation(m.symbol )
437
+ updateLocation(m)
454
438
super .transform(tree)
455
- }
456
- else
439
+ } else {
457
440
m
441
+ }
458
442
459
443
/**
460
444
* match with syntax `New(tpt)`.
@@ -532,6 +516,7 @@ class ScoverageInstrumentationComponent(val global: Global)
532
516
case t : TypeDef => super .transform(tree)
533
517
534
518
case t : Template =>
519
+ updateLocation(t)
535
520
treeCopy.Template (tree, t.parents, t.self, transformStatements(t.body))
536
521
537
522
case _ : TypeTree => super .transform(tree)
@@ -554,7 +539,7 @@ class ScoverageInstrumentationComponent(val global: Global)
554
539
555
540
// we need to remove the final mod so that we keep the code in order to check its invoked
556
541
case v : ValDef if v.mods.isFinal =>
557
- updateLocation(v.symbol )
542
+ updateLocation(v)
558
543
treeCopy.ValDef (v, v.mods.&~ (ModifierFlags .FINAL ), v.name, v.tpt, process(v.rhs))
559
544
560
545
/**
@@ -570,7 +555,7 @@ class ScoverageInstrumentationComponent(val global: Global)
570
555
* This includes top level non-lazy vals. Lazy vals are generated as stable defs.
571
556
*/
572
557
case v : ValDef =>
573
- updateLocation(v.symbol )
558
+ updateLocation(v)
574
559
treeCopy.ValDef (tree, v.mods, v.name, v.tpt, process(v.rhs))
575
560
576
561
case _ =>
0 commit comments