/* NSC -- new Scala compiler
* Copyright 2002-2013 LAMP/EPFL
* @author Martin Odersky
*/
package scala.tools.nsc
package reporters
import scala.reflect.internal.util._
/** Report information, warnings and errors.
*
* This describes the stable interface for issuing information, warnings and errors.
* The only abstract method in this class must be info0.
*/
abstract class Reporter {
protected def info0(pos: Position, msg: String, severity: Severity, force: Boolean): Unit
object severity extends Enumeration
class Severity(val id: Int) extends severity.Value {
var count: Int = 0
}
val INFO = new Severity(0) {
override def toString: String = "INFO"
}
val WARNING = new Severity(1) {
override def toString: String = "WARNING"
}
val ERROR = new Severity(2) {
override def toString: String = "ERROR"
}
private var incompleteHandler: (Position, String) => Unit = null
def incompleteHandled = incompleteHandler != null
def withIncompleteHandler[T](handler: (Position, String) => Unit)(thunk: => T) = {
val saved = incompleteHandler
incompleteHandler = handler
try thunk
finally incompleteHandler = saved
}
// used by sbt (via unit.cancel) to cancel a compile (see hasErrors)
var cancelled = false
def hasErrors = ERROR.count > 0 || cancelled
def hasWarnings = WARNING.count > 0
/** For sending a message which should not be labeled as a warning/error,
* but also shouldn't require -verbose to be visible.
*/
def echo(msg: String): Unit = info(NoPosition, msg, force = true)
def echo(pos: Position, msg: String): Unit = info(pos, msg, force = true)
/** Informational messages. If `!force`, they may be suppressed. */
final def info(pos: Position, msg: String, force: Boolean): Unit = info0(pos, msg, INFO, force)
/** Warnings and errors. */
def warning(pos: Position, msg: String): Unit = info0(pos, msg, WARNING, force = false)
def error(pos: Position, msg: String): Unit = info0(pos, msg, ERROR, force = false)
def incompleteInputError(pos: Position, msg: String): Unit = {
if (incompleteHandled) incompleteHandler(pos, msg)
else error(pos, msg)
}
// overridden by sbt, IDE:
// `comment` is unrelated to reporting and should move out (IDE receives comments from ScaladocAnalyzer)
def comment(pos: Position, msg: String) {}
def flush() { }
def reset() {
INFO.count = 0
ERROR.count = 0
WARNING.count = 0
cancelled = false
}
}