summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/reporters
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2014-06-14 00:38:30 +0200
committerAdriaan Moors <adriaan.moors@typesafe.com>2014-07-04 15:49:06 +0200
commit62c8f90f3105b8f19a9f29f104ff232438372c73 (patch)
tree0540ae1ba8aece6fdaffd0210719c979c36d02b3 /src/compiler/scala/tools/nsc/reporters
parent98216be3f3e546fc320ab5182ac5c129707db1ce (diff)
downloadscala-62c8f90f3105b8f19a9f29f104ff232438372c73.tar.gz
scala-62c8f90f3105b8f19a9f29f104ff232438372c73.tar.bz2
scala-62c8f90f3105b8f19a9f29f104ff232438372c73.zip
Uniformly route reporting through reporter.
Sharpen interfaces, reduce footprint of Reporting trait. Ideally, all reporting should indirect through reporter, and the `Reporting` trait itself should be restricted to a single method that retrieves the current `reporter`. Pull up some more reporting to reflect.internal. Would like to do more, but need to move partest to the reflect.internal interface first. (Its `errorCount` relies on `ERROR.count` in `tools.nsc.Reporter`.)
Diffstat (limited to 'src/compiler/scala/tools/nsc/reporters')
-rw-r--r--src/compiler/scala/tools/nsc/reporters/AbstractReporter.scala11
-rw-r--r--src/compiler/scala/tools/nsc/reporters/Reporter.scala69
2 files changed, 35 insertions, 45 deletions
diff --git a/src/compiler/scala/tools/nsc/reporters/AbstractReporter.scala b/src/compiler/scala/tools/nsc/reporters/AbstractReporter.scala
index 16d432438a..6c592ead0d 100644
--- a/src/compiler/scala/tools/nsc/reporters/AbstractReporter.scala
+++ b/src/compiler/scala/tools/nsc/reporters/AbstractReporter.scala
@@ -62,12 +62,13 @@ abstract class AbstractReporter extends Reporter {
*/
private def testAndLog(pos: Position, severity: Severity, msg: String): Boolean =
pos != null && pos.isDefined && {
- val fpos = pos.focus
+ val fpos = pos.focus
val suppress = positions(fpos) match {
- case ERROR => true // already error at position
- case highest if highest > severity => true // already message higher than present severity
- case `severity` => messages(fpos) contains msg // already issued this exact message
- case _ => false // good to go
+ 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 || {
diff --git a/src/compiler/scala/tools/nsc/reporters/Reporter.scala b/src/compiler/scala/tools/nsc/reporters/Reporter.scala
index b617e7b530..5b576a547d 100644
--- a/src/compiler/scala/tools/nsc/reporters/Reporter.scala
+++ b/src/compiler/scala/tools/nsc/reporters/Reporter.scala
@@ -10,59 +10,48 @@ import scala.reflect.internal.util._
/** Report information, warnings and errors.
*
- * This describes the stable interface for issuing information, warnings and errors.
+ * This describes the internal interface for issuing information, warnings and errors.
* The only abstract method in this class must be info0.
+ *
+ * TODO: Move external clients (sbt/ide/partest) to reflect.internal.Reporter
+ * This interface should be considered private to the compiler.
*/
-abstract class Reporter {
- protected def info0(pos: Position, msg: String, severity: Severity, force: Boolean): Unit
-
+abstract class Reporter extends scala.reflect.internal.Reporter {
/** Informational messages. If `!force`, they may be suppressed. */
final def info(pos: Position, msg: String, force: Boolean): Unit = info0(pos, msg, INFO, force)
/** 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)
-
- /** 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 flush(): Unit = { }
+ def echo(msg: String): Unit = info(NoPosition, msg, force = true)
- // overridden by sbt, IDE
- def reset(): Unit = {
- INFO.count = 0
- WARNING.count = 0
- ERROR.count = 0
- cancelled = false
- }
-
- 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"
- }
+ // overridden by sbt, IDE -- should not be in the reporting interface
+ // (IDE receives comments from ScaladocAnalyzer using this hook method)
+ // TODO: IDE should override a hook method in the parser instead
+ def comment(pos: Position, msg: String): Unit = {}
// used by sbt (via unit.cancel) to cancel a compile (see hasErrors)
+ // TODO: figure out how sbt uses this, come up with a separate interface for controlling the build
var cancelled: Boolean = false
- // overridden by sbt
- def hasErrors: Boolean = ERROR.count > 0 || cancelled
+ override def hasErrors: Boolean = super.hasErrors || cancelled
- // overridden by sbt
- def hasWarnings: Boolean = WARNING.count > 0
+ override def reset(): Unit = {
+ super.reset()
+ cancelled = false
+ }
- // overridden by sbt, IDE -- should move out of this interface
- // it's unrelated to reporting (IDE receives comments from ScaladocAnalyzer)
- def comment(pos: Position, msg: String): Unit = {}
+ // the below is copy/pasted from ReporterImpl for now
+ // partest expects this inner class
+ // TODO: rework partest to use the scala.reflect.internal interface,
+ // remove duplication here, and consolidate reflect.internal.{ReporterImpl & ReporterImpl}
+ class Severity(val id: Int)(name: String) { var count: Int = 0 ; override def toString = name}
+ object INFO extends Severity(0)("INFO")
+ object WARNING extends Severity(1)("WARNING")
+ // reason for copy/paste: this is used by partest (must be a val, not an object)
+ // TODO: use count(ERROR) in scala.tools.partest.nest.DirectCompiler#errorCount, rather than ERROR.count
+ lazy val ERROR = new Severity(2)("ERROR")
+
+ def count(severity: Severity): Int = severity.count
+ def resetCount(severity: Severity): Unit = severity.count = 0
}