aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/reporting
diff options
context:
space:
mode:
authorliu fengyun <liu@fengy.me>2016-10-18 18:57:36 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-11-09 13:06:27 +0100
commit1496db4b6fe039033f7d42d203c1563202c79868 (patch)
tree36d2780f7a86c5f4164dcbf1908e2041e7632895 /src/dotty/tools/dotc/reporting
parent64a23e00c34dac6fc5a73d2339486c4440b9a2c2 (diff)
downloaddotty-1496db4b6fe039033f7d42d203c1563202c79868.tar.gz
dotty-1496db4b6fe039033f7d42d203c1563202c79868.tar.bz2
dotty-1496db4b6fe039033f7d42d203c1563202c79868.zip
add back classic reporter
Diffstat (limited to 'src/dotty/tools/dotc/reporting')
-rw-r--r--src/dotty/tools/dotc/reporting/ClassicReporter.scala85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/reporting/ClassicReporter.scala b/src/dotty/tools/dotc/reporting/ClassicReporter.scala
new file mode 100644
index 000000000..bd881eb4f
--- /dev/null
+++ b/src/dotty/tools/dotc/reporting/ClassicReporter.scala
@@ -0,0 +1,85 @@
+package dotty.tools
+package dotc
+package reporting
+
+import scala.collection.mutable
+import util.SourcePosition
+import core.Contexts._
+import Reporter._
+import java.io.{ BufferedReader, IOException, PrintWriter }
+import scala.reflect.internal.util._
+import diagnostic.{ Message, MessageContainer, NoExplanation }
+import diagnostic.messages._
+
+/**
+ * This class implements a Reporter that displays messages on a text
+ * console.
+ */
+class ClassicReporter(
+ reader: BufferedReader = Console.in,
+ writer: PrintWriter = new PrintWriter(Console.err, true))
+ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages {
+
+ import MessageContainer._
+
+ /** maximal number of error messages to be printed */
+ protected def ErrorLimit = 100
+
+ def printPos(pos: SourcePosition): Unit =
+ if (pos.exists) {
+ printMessage(pos.lineContent.stripLineEnd)
+ printMessage(" " * pos.column + "^")
+ if (pos.outer.exists) {
+ printMessage(s"\n... this location is in code that was inlined at ${pos.outer}:\n")
+ printPos(pos.outer)
+ }
+ }
+
+ /** Prints the message. */
+ def printMessage(msg: String): Unit = { writer.print(msg + "\n"); writer.flush() }
+
+ /** Prints the message with the given position indication. */
+ def printMessageAndPos(msg: String, pos: SourcePosition)(implicit ctx: Context): Unit = {
+ val posStr = if (pos.exists) s"$pos: " else ""
+ printMessage(posStr + msg)
+ printPos(pos)
+ }
+
+ override def doReport(m: MessageContainer)(implicit ctx: Context): Unit = m match {
+ case m: Error =>
+ printMessageAndPos(s"error: ${m.contained}", m.pos)
+ if (ctx.settings.prompt.value) displayPrompt()
+ case m: ConditionalWarning if !m.enablingOption.value =>
+ case m: FeatureWarning =>
+ printMessageAndPos(s"feature warning: ${m.contained.msg}", m.pos)
+ case m: DeprecationWarning =>
+ printMessageAndPos(s"deprecation warning: ${m.contained.msg}", m.pos)
+ case m: UncheckedWarning =>
+ printMessageAndPos(s"unchecked warning: ${m.contained.msg}", m.pos)
+ case m: Info =>
+ printMessageAndPos(m.contained.msg, m.pos)
+ case m: MigrationWarning =>
+ printMessageAndPos(s"migration warning: ${m.contained.msg}", m.pos)
+ case m: Warning =>
+ printMessageAndPos(s"warning: ${m.contained.msg}", m.pos)
+ case _ =>
+ printMessageAndPos(m.contained.msg, m.pos)
+ }
+
+ def displayPrompt(): Unit = {
+ writer.print("\na)bort, s)tack, r)esume: ")
+ writer.flush()
+ if (reader != null) {
+ val response = reader.read().asInstanceOf[Char].toLower
+ if (response == 'a' || response == 's') {
+ Thread.dumpStack()
+ if (response == 'a')
+ sys.exit(1)
+ }
+ writer.print("\n")
+ writer.flush()
+ }
+ }
+
+ override def flush()(implicit ctx: Context): Unit = { writer.flush() }
+}