Skip to content

Commit 75b3ff2

Browse files
committed
Partially working lazys
1 parent 993942b commit 75b3ff2

File tree

1 file changed

+39
-12
lines changed

1 file changed

+39
-12
lines changed

src/main/scala/scoverage/plugin.scala

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ class ScoverageComponent(val global: Global)
280280
// Compiler generated case apply and unapply. Ignore these
281281
case d: DefDef if d.symbol.isCaseApplyOrUnapply => tree
282282

283-
case d: DefDef if d.symbol.isStable && d.symbol.isGetter => tree
283+
case d: DefDef if d.symbol.isStable && d.symbol.isGetter && d.symbol.isLazy =>
284+
println("LAZY DEF: " + d.toString() + " " + d.symbol)
285+
tree
284286

285287
/**
286288
* Stable getters are methods generated for access to a top level val.
@@ -347,9 +349,33 @@ class ScoverageComponent(val global: Global)
347349
updateLocation(m.symbol)
348350
super.transform(tree)
349351

350-
case n: New =>
351-
println("NEW " + n)
352-
super.transform(n)
352+
/**
353+
* match with syntax `New(tpt)`.
354+
* This AST node corresponds to the following Scala code:
355+
*
356+
* `new` T
357+
*
358+
* This node always occurs in the following context:
359+
*
360+
* (`new` tpt).<init>[targs](args)
361+
*
362+
* For example, an AST representation of:
363+
*
364+
* new Example[Int](2)(3)
365+
*
366+
* is the following code:
367+
*
368+
* Apply(
369+
* Apply(
370+
* TypeApply(
371+
* Select(New(TypeTree(typeOf[Example])), nme.CONSTRUCTOR)
372+
* TypeTree(typeOf[Int])),
373+
* List(Literal(Constant(2)))),
374+
* List(Literal(Constant(3))))
375+
*
376+
* We can ignore New as they should be profiled by the outer select.
377+
*/
378+
case n: New => super.transform(n)
353379

354380
case p: PackageDef => super.transform(p)
355381

@@ -369,14 +395,15 @@ class ScoverageComponent(val global: Global)
369395
* Foo#Bar // represented as SelectFromTypeTree(Ident(<Foo>), <Bar>)
370396
*/
371397
case s: Select if location == null => super.transform(s)
372-
case s: Select if location.classType == ClassType.Class => instrument(s)
373-
case s: Select => super.transform(s)
374-
// def nested(s: Tree): Tree = {
375-
// s.children.head match {
376-
// case _: Select => nested(s.children.head)
377-
// case _ => process(s.children.head)
378-
// }
379-
// }
398+
case s: Select => // instrument outer select only until we hit an apply or run out of selects
399+
def nested(s: Tree): Tree = {
400+
s.children.head match {
401+
case a: Apply => process(a)
402+
case s: Select => nested(s.children.head)
403+
case _ => s
404+
}
405+
}
406+
instrument(s)
380407

381408
case s: Super => tree
382409

0 commit comments

Comments
 (0)