package scala.tools.nsc
package reporters
import scala.collection.mutable.HashMap
import scala.tools.nsc.Settings
import scala.tools.nsc.util.Position
abstract class AbstractReporter extends Reporter {
val settings: Settings
def display(pos: Position, msg: String, severity: Severity): Unit
def displayPrompt(): Unit
private val positions = new HashMap[Position, Severity]
override def reset() {
super.reset
positions.clear
}
private def isVerbose = settings.verbose.value
private def noWarnings = settings.nowarnings.value
private def isPromptSet = settings.prompt.value
protected def info0(pos: Position, msg: String, _severity: Severity, force: Boolean) {
val severity =
if (settings.fatalWarnings.value && _severity == WARNING) ERROR
else _severity
if (severity == INFO) {
if (isVerbose || force)
display(pos, msg, severity)
}
else {
val hidden = testAndLog(pos, severity)
if (severity == WARNING && noWarnings) ()
else {
if (!hidden || isPromptSet) display(pos, msg, severity)
if (isPromptSet) displayPrompt
}
}
}
private def testAndLog(pos: Position, severity: Severity): Boolean =
pos != null && pos.isDefined && {
val fpos = pos.focus
(positions get fpos) match {
case Some(level) if level >= severity => true
case _ => positions += (fpos -> severity) ; false
}
}
}