1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
/* NSC -- new Scala compiler
* Copyright 2002-2013 LAMP/EPFL
* @author Martin Odersky
*/
package scala.tools.nsc
package reporters
import scala.collection.mutable
import scala.tools.nsc.Settings
import scala.reflect.internal.util.Position
/**
* This reporter implements filtering.
*/
abstract class AbstractReporter extends Reporter {
val settings: Settings
def display(pos: Position, msg: String, severity: Severity): Unit
def displayPrompt(): Unit
private val positions = mutable.Map[Position, Severity]() withDefaultValue INFO
private val messages = mutable.Map[Position, List[String]]() withDefaultValue Nil
override def reset() {
super.reset()
positions.clear()
messages.clear()
}
private def isVerbose = settings.verbose.value
private def noWarnings = settings.nowarnings.value
private def isPromptSet = settings.prompt.value
private def isDebug = settings.debug
protected def info0(pos: Position, msg: String, severity: Severity, force: Boolean) {
if (severity == INFO) {
if (isVerbose || force) {
severity.count += 1
display(pos, msg, severity)
}
}
else {
val hidden = testAndLog(pos, severity, msg)
if (severity == WARNING && noWarnings) ()
else {
if (!hidden || isPromptSet) {
severity.count += 1
display(pos, msg, severity)
}
else if (isDebug) {
severity.count += 1
display(pos, "[ suppressed ] " + msg, severity)
}
if (isPromptSet)
displayPrompt()
}
}
}
/** Logs a position and returns true if it was already logged.
* @note Two positions are considered identical for logging if they have the same point.
*/
private def testAndLog(pos: Position, severity: Severity, msg: String): Boolean =
pos != null && pos.isDefined && {
val fpos = pos.focus
val suppress = positions(fpos) match {
case ERROR => true // already error at position
case highest
if highest.id > severity.id => true // already message higher than present severity
case `severity` => messages(fpos) contains msg // already issued this exact message
case _ => false // good to go
}
suppress || {
positions(fpos) = severity
messages(fpos) ::= msg
false
}
}
}
|