Skip to content

Commit c143f6d

Browse files
committed
Updated plugin to use fileIncluded in filter
1 parent 357bd3f commit c143f6d

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/main/scala/scoverage/coverage.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ case class MeasuredStatement(source: String,
101101
case class Location(_package: String,
102102
_class: String,
103103
classType: ClassType,
104-
method: String)
104+
method: String,
105+
path: String)
105106
extends java.io.Serializable {
106107
val fqn = (_package + ".").replace("<empty>.", "") + _class
107108
}

src/main/scala/scoverage/plugin.scala

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import java.io.File
44
import java.util.concurrent.atomic.AtomicInteger
55

66
import scala.reflect.internal.ModifierFlags
7+
import scala.reflect.internal.util.SourceFile
78
import scala.tools.nsc._
89
import scala.tools.nsc.plugins.{Plugin, PluginComponent}
910
import scala.tools.nsc.transform.{Transform, TypingTransformers}
10-
import scala.tools.nsc.util.SourceFile
1111

1212
/** @author Stephen Samuel */
1313
class ScoveragePlugin(val global: Global) extends Plugin {
@@ -75,7 +75,7 @@ class ScoverageInstrumentationComponent(val global: Global)
7575

7676
def setOptions(options: ScoverageOptions): Unit = {
7777
this.options = options
78-
coverageFilter = new RegexCoverageFilter(options.excludedPackages)
78+
coverageFilter = new RegexCoverageFilter(options.excludedPackages, options.excludedFiles)
7979
new File(options.dataDir).mkdirs() // ensure data directory is created
8080
}
8181

@@ -182,13 +182,9 @@ class ScoverageInstrumentationComponent(val global: Global)
182182
}
183183
}
184184

185-
def isClassIncluded(symbol: Symbol): Boolean = {
186-
coverageFilter.isClassIncluded(symbol.fullNameString)
187-
}
188-
189-
def isStatementIncluded(pos: Position): Boolean = {
190-
coverageFilter.isLineIncluded(pos)
191-
}
185+
def isClassIncluded(symbol: Symbol): Boolean = coverageFilter.isClassIncluded(symbol.fullNameString)
186+
def isFileIncluded(source: SourceFile): Boolean = coverageFilter.isFileIncluded(source)
187+
def isStatementIncluded(pos: Position): Boolean = coverageFilter.isLineIncluded(pos)
192188

193189
def className(s: Symbol): String = {
194190
if (s.enclClass.isAnonymousFunction || s.enclClass.isAnonymousFunction)
@@ -214,7 +210,8 @@ class ScoverageInstrumentationComponent(val global: Global)
214210
s.enclosingPackage.fullName,
215211
className(s),
216212
classType,
217-
enclosingMethod(s)
213+
enclosingMethod(s),
214+
s.sourceFile.canonicalPath
218215
)
219216
}
220217

@@ -327,14 +324,14 @@ class ScoverageInstrumentationComponent(val global: Global)
327324
// scalac generated classes, we just instrument the enclosed methods/statments
328325
// the location would stay as the source class
329326
case c: ClassDef if c.symbol.isAnonymousClass || c.symbol.isAnonymousFunction =>
330-
if (isClassIncluded(c.symbol))
327+
if (isFileIncluded(c.pos.source) && isClassIncluded(c.symbol))
331328
super.transform(tree)
332329
else {
333330
c
334331
}
335332

336333
case c: ClassDef =>
337-
if (isClassIncluded(c.symbol)) {
334+
if (isFileIncluded(c.pos.source) && isClassIncluded(c.symbol)) {
338335
updateLocation(c.symbol)
339336
super.transform(tree)
340337
} else {
@@ -453,7 +450,7 @@ class ScoverageInstrumentationComponent(val global: Global)
453450

454451
// user defined objects
455452
case m: ModuleDef =>
456-
if (isClassIncluded(m.symbol)) {
453+
if (isFileIncluded(m.pos.source) && isClassIncluded(m.symbol)) {
457454
updateLocation(m.symbol)
458455
super.transform(tree)
459456
}

0 commit comments

Comments
 (0)