@@ -29,7 +29,7 @@ class ScoveragePlugin(val global: Global) extends Plugin {
29
29
options.excludedSymbols = opt.substring(" excludedSymbols:" .length).split(" ;" ).map(_.trim).filterNot(_.isEmpty)
30
30
} else if (opt.startsWith(" dataDir:" )) {
31
31
options.dataDir = opt.substring(" dataDir:" .length)
32
- } else if (opt.startsWith(" extraAfterPhase:" ) || opt.startsWith(" extraBeforePhase:" )){
32
+ } else if (opt.startsWith(" extraAfterPhase:" ) || opt.startsWith(" extraBeforePhase:" )) {
33
33
// skip here, these flags are processed elsewhere
34
34
} else {
35
35
error(" Unknown option: " + opt)
@@ -82,8 +82,8 @@ class ScoverageOptions {
82
82
83
83
class ScoverageInstrumentationComponent (val global : Global , extraAfterPhase : Option [String ], extraBeforePhase : Option [String ])
84
84
extends PluginComponent
85
- with TypingTransformers
86
- with Transform {
85
+ with TypingTransformers
86
+ with Transform {
87
87
88
88
import global ._
89
89
@@ -95,11 +95,11 @@ class ScoverageInstrumentationComponent(val global: Global, extraAfterPhase: Opt
95
95
override val runsBefore : List [String ] = List (" patmat" ) ::: extraBeforePhase.toList
96
96
97
97
/**
98
- * Our options are not provided at construction time, but shortly after,
99
- * so they start as None.
100
- * You must call "setOptions" before running any commands that rely on
101
- * the options.
102
- */
98
+ * Our options are not provided at construction time, but shortly after,
99
+ * so they start as None.
100
+ * You must call "setOptions" before running any commands that rely on
101
+ * the options.
102
+ */
103
103
private var options : ScoverageOptions = new ScoverageOptions ()
104
104
private var coverageFilter : CoverageFilter = AllCoverageFilter
105
105
@@ -135,14 +135,14 @@ class ScoverageInstrumentationComponent(val global: Global, extraAfterPhase: Opt
135
135
import global ._
136
136
137
137
// contains the location of the last node
138
- var location : Location = null
138
+ var location : Location = _
139
139
140
140
/**
141
- * The 'start' of the position, if it is available, else -1
142
- * We cannot use 'isDefined' to test whether pos.start will work, as some
143
- * classes (e.g. scala.reflect.internal.util.OffsetPosition have
144
- * isDefined true, but throw on `start`
145
- */
141
+ * The 'start' of the position, if it is available, else -1
142
+ * We cannot use 'isDefined' to test whether pos.start will work, as some
143
+ * classes (e.g. scala.reflect.internal.util.OffsetPosition have
144
+ * isDefined true, but throw on `start`
145
+ */
146
146
def safeStart (tree : Tree ): Int = scala.util.Try (tree.pos.start).getOrElse(- 1 )
147
147
def safeEnd (tree : Tree ): Int = scala.util.Try (tree.pos.end).getOrElse(- 1 )
148
148
def safeLine (tree : Tree ): Int = if (tree.pos.isDefined) tree.pos.line else - 1
@@ -250,7 +250,7 @@ class ScoverageInstrumentationComponent(val global: Global, extraAfterPhase: Opt
250
250
)
251
251
)
252
252
case _ =>
253
- reporter.error(c.pos , " Cannot instrument partial function apply. Please file bug report" )
253
+ reporter.error(c.pos, " Cannot instrument partial function apply. Please file bug report" )
254
254
d
255
255
}
256
256
case other => other
@@ -301,17 +301,17 @@ class ScoverageInstrumentationComponent(val global: Global, extraAfterPhase: Opt
301
301
// case a: GenericApply if a.symbol.isConstructor => instrument(a)
302
302
303
303
/**
304
- * When an apply has no parameters, or is an application of purely literals or idents
305
- * then we can simply instrument the outer call. Ie, we can treat it all as one single statement
306
- * for the purposes of code coverage.
307
- * This will include calls to case apply.
308
- */
304
+ * When an apply has no parameters, or is an application of purely literals or idents
305
+ * then we can simply instrument the outer call. Ie, we can treat it all as one single statement
306
+ * for the purposes of code coverage.
307
+ * This will include calls to case apply.
308
+ */
309
309
case a : GenericApply if allConstArgs(a.args) => instrument(a, a)
310
310
311
311
/**
312
- * Applications of methods with non trivial args means the args themselves
313
- * must also be instrumented
314
- */
312
+ * Applications of methods with non trivial args means the args themselves
313
+ * must also be instrumented
314
+ */
315
315
// todo remove once scala merges into Apply proper
316
316
case a : ApplyToImplicitArgs =>
317
317
instrument(treeCopy.Apply (a, traverseApplication(a.fun), transformStatements(a.args)), a)
@@ -370,7 +370,7 @@ class ScoverageInstrumentationComponent(val global: Global, extraAfterPhase: Opt
370
370
// this will catch methods defined as macros, eg def test = macro testImpl
371
371
// it will not catch macro implementations
372
372
case d : DefDef if d.symbol != null
373
- && d.symbol.annotations.size > 0
373
+ && d.symbol.annotations.nonEmpty
374
374
&& d.symbol.annotations.toString() == " macroImpl" =>
375
375
tree
376
376
@@ -383,31 +383,31 @@ class ScoverageInstrumentationComponent(val global: Global, extraAfterPhase: Opt
383
383
case d : DefDef if d.symbol.isPrimaryConstructor => tree
384
384
385
385
/**
386
- * Case class accessors for vals
387
- * EG for case class CreditReject(req: MarketOrderRequest, client: ActorRef)
388
- * <stable> <caseaccessor> <accessor> <paramaccessor> def req: com.sksamuel.scoverage.samples.MarketOrderRequest
389
- * <stable> <caseaccessor> <accessor> <paramaccessor> def client: akka.actor.ActorRef
390
- */
386
+ * Case class accessors for vals
387
+ * EG for case class CreditReject(req: MarketOrderRequest, client: ActorRef)
388
+ * <stable> <caseaccessor> <accessor> <paramaccessor> def req: com.sksamuel.scoverage.samples.MarketOrderRequest
389
+ * <stable> <caseaccessor> <accessor> <paramaccessor> def client: akka.actor.ActorRef
390
+ */
391
391
case d : DefDef if d.symbol.isCaseAccessor => tree
392
392
393
393
// Compiler generated case apply and unapply. Ignore these
394
394
case d : DefDef if d.symbol.isCaseApplyOrUnapply => tree
395
395
396
396
/**
397
- * Lazy stable DefDefs are generated as the impl for lazy vals.
398
- */
397
+ * Lazy stable DefDefs are generated as the impl for lazy vals.
398
+ */
399
399
case d : DefDef if d.symbol.isStable && d.symbol.isGetter && d.symbol.isLazy =>
400
400
updateLocation(d)
401
401
treeCopy.DefDef (d, d.mods, d.name, d.tparams, d.vparamss, d.tpt, process(d.rhs))
402
402
403
403
/**
404
- * Stable getters are methods generated for access to a top level val.
405
- * Should be ignored as this is compiler generated code.
406
- *
407
- * Eg
408
- * <stable> <accessor> def MaxCredit: scala.math.BigDecimal = CreditEngine.this.MaxCredit
409
- * <stable> <accessor> def alwaysTrue: String = InstrumentLoader.this.alwaysTrue
410
- */
404
+ * Stable getters are methods generated for access to a top level val.
405
+ * Should be ignored as this is compiler generated code.
406
+ *
407
+ * Eg
408
+ * <stable> <accessor> def MaxCredit: scala.math.BigDecimal = CreditEngine.this.MaxCredit
409
+ * <stable> <accessor> def alwaysTrue: String = InstrumentLoader.this.alwaysTrue
410
+ */
411
411
case d : DefDef if d.symbol.isStable && d.symbol.isGetter => tree
412
412
413
413
/** Accessors are auto generated setters and getters.
@@ -496,30 +496,30 @@ class ScoverageInstrumentationComponent(val global: Global, extraAfterPhase: Opt
496
496
}
497
497
498
498
/**
499
- * match with syntax `New(tpt)`.
500
- * This AST node corresponds to the following Scala code:
501
- *
502
- * `new` T
503
- *
504
- * This node always occurs in the following context:
505
- *
506
- * (`new` tpt).<init>[targs](args)
507
- *
508
- * For example, an AST representation of:
509
- *
510
- * new Example[Int](2)(3)
511
- *
512
- * is the following code:
513
- *
514
- * Apply(
515
- * Apply(
516
- * TypeApply(
517
- * Select(New(TypeTree(typeOf[Example])), nme.CONSTRUCTOR)
518
- * TypeTree(typeOf[Int])),
519
- * List(Literal(Constant(2)))),
520
- * List(Literal(Constant(3))))
521
- *
522
- */
499
+ * match with syntax `New(tpt)`.
500
+ * This AST node corresponds to the following Scala code:
501
+ *
502
+ * `new` T
503
+ *
504
+ * This node always occurs in the following context:
505
+ *
506
+ * (`new` tpt).<init>[targs](args)
507
+ *
508
+ * For example, an AST representation of:
509
+ *
510
+ * new Example[Int](2)(3)
511
+ *
512
+ * is the following code:
513
+ *
514
+ * Apply(
515
+ * Apply(
516
+ * TypeApply(
517
+ * Select(New(TypeTree(typeOf[Example])), nme.CONSTRUCTOR)
518
+ * TypeTree(typeOf[Int])),
519
+ * List(Literal(Constant(2)))),
520
+ * List(Literal(Constant(3))))
521
+ *
522
+ */
523
523
case n : New => n
524
524
525
525
case s@ Select (n@ New (tpt), name) =>
@@ -547,9 +547,9 @@ class ScoverageInstrumentationComponent(val global: Global, extraAfterPhase: Opt
547
547
case s : Select if location == null => tree
548
548
549
549
/**
550
- * I think lazy selects are the LHS of a lazy assign.
551
- * todo confirm we can ignore
552
- */
550
+ * I think lazy selects are the LHS of a lazy assign.
551
+ * todo confirm we can ignore
552
+ */
553
553
case s : Select if s.symbol.isLazy => tree
554
554
555
555
case s : Select => instrument(treeCopy.Select (s, traverseApplication(s.qualifier), s.name), s)
@@ -581,45 +581,41 @@ class ScoverageInstrumentationComponent(val global: Global, extraAfterPhase: Opt
581
581
582
582
case _ : TypeTree => super .transform(tree)
583
583
584
+ // if the rhs of a val is a literal we can just leave it
585
+ case v : ValDef if v.rhs.isInstanceOf [Literal ] => tree
586
+
584
587
/**
585
- * We can ignore lazy val defs as they are implemented by a generated defdef
586
- */
587
- case v : ValDef if v.symbol.isLazy =>
588
- val w = v
589
- tree
588
+ * We can ignore lazy val defs as they are implemented by a generated defdef
589
+ */
590
+ case v : ValDef if v.symbol.isLazy => tree
590
591
591
592
/**
592
- * <synthetic> val default: A1 => B1 =
593
- * <synthetic> val x1: Any = _
594
- */
595
- case v : ValDef if v.symbol.isSynthetic =>
596
- val w = v
597
- tree
593
+ * <synthetic> val default: A1 => B1 =
594
+ * <synthetic> val x1: Any = _
595
+ */
596
+ case v : ValDef if v.symbol.isSynthetic => tree
598
597
599
598
/**
600
- * Vals declared in case constructors
601
- */
602
- case v : ValDef if v.symbol.isParamAccessor && v.symbol.isCaseAccessor =>
603
- val w = v
604
- tree
599
+ * Vals declared in case constructors
600
+ */
601
+ case v : ValDef if v.symbol.isParamAccessor && v.symbol.isCaseAccessor => tree
605
602
606
603
// we need to remove the final mod so that we keep the code in order to check its invoked
607
604
case v : ValDef if v.mods.isFinal =>
608
- updateLocation(v)
609
605
treeCopy.ValDef (v, v.mods.&~ (ModifierFlags .FINAL ), v.name, v.tpt, process(v.rhs))
610
606
611
607
/**
612
- * This AST node corresponds to any of the following Scala code:
613
- *
614
- * mods `val` name: tpt = rhs
615
- * mods `var` name: tpt = rhs
616
- * mods name: tpt = rhs // in signatures of function and method definitions
617
- * self: Bar => // self-types
618
- *
619
- * For user defined value statements, we will instrument the RHS.
620
- *
621
- * This includes top level non-lazy vals. Lazy vals are generated as stable defs.
622
- */
608
+ * This AST node corresponds to any of the following Scala code:
609
+ *
610
+ * mods `val` name: tpt = rhs
611
+ * mods `var` name: tpt = rhs
612
+ * mods name: tpt = rhs // in signatures of function and method definitions
613
+ * self: Bar => // self-types
614
+ *
615
+ * For user defined value statements, we will instrument the RHS.
616
+ *
617
+ * This includes top level non-lazy vals. Lazy vals are generated as stable defs.
618
+ */
623
619
case v : ValDef =>
624
620
updateLocation(v)
625
621
treeCopy.ValDef (tree, v.mods, v.name, v.tpt, process(v.rhs))
0 commit comments