@@ -4,10 +4,10 @@ import java.io.File
4
4
import java .util .concurrent .atomic .AtomicInteger
5
5
6
6
import scala .reflect .internal .ModifierFlags
7
+ import scala .reflect .internal .util .SourceFile
7
8
import scala .tools .nsc ._
8
9
import scala .tools .nsc .plugins .{Plugin , PluginComponent }
9
10
import scala .tools .nsc .transform .{Transform , TypingTransformers }
10
- import scala .tools .nsc .util .SourceFile
11
11
12
12
/** @author Stephen Samuel */
13
13
class ScoveragePlugin (val global : Global ) extends Plugin {
@@ -75,7 +75,7 @@ class ScoverageInstrumentationComponent(val global: Global)
75
75
76
76
def setOptions (options : ScoverageOptions ): Unit = {
77
77
this .options = options
78
- coverageFilter = new RegexCoverageFilter (options.excludedPackages)
78
+ coverageFilter = new RegexCoverageFilter (options.excludedPackages, options.excludedFiles )
79
79
new File (options.dataDir).mkdirs() // ensure data directory is created
80
80
}
81
81
@@ -182,13 +182,9 @@ class ScoverageInstrumentationComponent(val global: Global)
182
182
}
183
183
}
184
184
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)
192
188
193
189
def className (s : Symbol ): String = {
194
190
if (s.enclClass.isAnonymousFunction || s.enclClass.isAnonymousFunction)
@@ -214,7 +210,8 @@ class ScoverageInstrumentationComponent(val global: Global)
214
210
s.enclosingPackage.fullName,
215
211
className(s),
216
212
classType,
217
- enclosingMethod(s)
213
+ enclosingMethod(s),
214
+ s.sourceFile.canonicalPath
218
215
)
219
216
}
220
217
@@ -327,14 +324,14 @@ class ScoverageInstrumentationComponent(val global: Global)
327
324
// scalac generated classes, we just instrument the enclosed methods/statments
328
325
// the location would stay as the source class
329
326
case c : ClassDef if c.symbol.isAnonymousClass || c.symbol.isAnonymousFunction =>
330
- if (isClassIncluded(c.symbol))
327
+ if (isFileIncluded(c.pos.source) && isClassIncluded(c.symbol))
331
328
super .transform(tree)
332
329
else {
333
330
c
334
331
}
335
332
336
333
case c : ClassDef =>
337
- if (isClassIncluded(c.symbol)) {
334
+ if (isFileIncluded(c.pos.source) && isClassIncluded(c.symbol)) {
338
335
updateLocation(c.symbol)
339
336
super .transform(tree)
340
337
} else {
@@ -453,7 +450,7 @@ class ScoverageInstrumentationComponent(val global: Global)
453
450
454
451
// user defined objects
455
452
case m : ModuleDef =>
456
- if (isClassIncluded(m.symbol)) {
453
+ if (isFileIncluded(m.pos.source) && isClassIncluded(m.symbol)) {
457
454
updateLocation(m.symbol)
458
455
super .transform(tree)
459
456
}
0 commit comments