@@ -4,10 +4,10 @@ import java.io.File
44import java .util .concurrent .atomic .AtomicInteger
55
66import scala .reflect .internal .ModifierFlags
7+ import scala .reflect .internal .util .SourceFile
78import scala .tools .nsc ._
89import scala .tools .nsc .plugins .{Plugin , PluginComponent }
910import scala .tools .nsc .transform .{Transform , TypingTransformers }
10- import scala .tools .nsc .util .SourceFile
1111
1212/** @author Stephen Samuel */
1313class 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