summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/reporters/Reporter.scala
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2014-06-10 15:59:23 +0200
committerAdriaan Moors <adriaan.moors@typesafe.com>2014-07-04 15:26:52 +0200
commitffb0e25fc8ec9d6ecb0cd806bc534e9430e37bd4 (patch)
tree94bdbf3809b8029ced7adb53e9731c79d344c9f9 /src/compiler/scala/tools/nsc/reporters/Reporter.scala
parentb38fc5eaac3eb938902fe56a69e44830d41c1f87 (diff)
downloadscala-ffb0e25fc8ec9d6ecb0cd806bc534e9430e37bd4.tar.gz
scala-ffb0e25fc8ec9d6ecb0cd806bc534e9430e37bd4.tar.bz2
scala-ffb0e25fc8ec9d6ecb0cd806bc534e9430e37bd4.zip
Unclutter Reporter. Move truncation to ReplReporter.
Refactor to reduce the Reporter interface. Working towards minimal interfaces in scala.reflect.internal that can be consumed by sbt/IDE/.... The scala.tools.nsc package is entirely private to the compiler (in principle). A `Reporter` should only be used to inform (info/warning/error). No state. Ideally, we'd move to having only one reporter, whose lifetime is adjusted appropriately (from per-run in general to per-context for type checking, so errors can be buffered -- "silenced" -- during nested type checking calls). Start the clean up by moving truncation to the REPL, since it's not relevant for regular reporting. Perversely, we were checking truncation all the time, even though it's only on during a repl run. (Truncation is now always turned off in the repl under -verbose.) Untangle error resetting on symbols from error reporting (reportAdditionalErrors). This fixes a nice&subtle bug that caused feature warnings to be suppressed under `-Xfatal-warnings`: ``` def reportCompileErrors() { if (!reporter.hasErrors && reporter.hasWarnings && settings.fatalWarnings) globalError("No warnings can be incurred under -Xfatal-warnings.") if (reporter.hasErrors) { ... } else { // will erroneously not get here if // `reporter.hasWarnings && settings.fatalWarnings` // since the `globalError` call above means `reporter.hasErrors`... allConditionalWarnings foreach (_.summarize()) ... } } ``` The second `if`'s condition depends on the `globalError` call in the first `if`...
Diffstat (limited to 'src/compiler/scala/tools/nsc/reporters/Reporter.scala')
-rw-r--r--src/compiler/scala/tools/nsc/reporters/Reporter.scala37
1 files changed, 14 insertions, 23 deletions
diff --git a/src/compiler/scala/tools/nsc/reporters/Reporter.scala b/src/compiler/scala/tools/nsc/reporters/Reporter.scala
index 68362c066d..766a35960b 100644
--- a/src/compiler/scala/tools/nsc/reporters/Reporter.scala
+++ b/src/compiler/scala/tools/nsc/reporters/Reporter.scala
@@ -8,9 +8,10 @@ package reporters
import scala.reflect.internal.util._
-/**
- * This interface provides methods to issue information, warning and
- * error messages.
+/** 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
@@ -29,19 +30,6 @@ abstract class Reporter {
override def toString: String = "ERROR"
}
- /** Whether very long lines can be truncated. This exists so important
- * debugging information (like printing the classpath) is not rendered
- * invisible due to the max message length.
- */
- private var _truncationOK: Boolean = true
- def truncationOK = _truncationOK
- def withoutTruncating[T](body: => T): T = {
- val saved = _truncationOK
- _truncationOK = false
- try body
- finally _truncationOK = saved
- }
-
private var incompleteHandler: (Position, String) => Unit = null
def incompleteHandled = incompleteHandler != null
def withIncompleteHandler[T](handler: (Position, String) => Unit)(thunk: => T) = {
@@ -51,6 +39,7 @@ abstract class Reporter {
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
@@ -58,21 +47,23 @@ abstract class Reporter {
/** 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)
+ def echo(msg: String): Unit = info(NoPosition, msg, force = true)
+ def echo(pos: Position, msg: String): Unit = info(pos, msg, force = true)
- /** Informational messages, suppressed unless -verbose or force=true. */
- def info(pos: Position, msg: String, force: Boolean): Unit = info0(pos, msg, INFO, force)
+ /** 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 = withoutTruncating(info0(pos, msg, WARNING, force = false))
- def error(pos: Position, msg: String): Unit = withoutTruncating(info0(pos, msg, ERROR, force = false))
+ 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)
}
- def comment(pos: Position, msg: String) { }
+ // 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