From 18d63fe71ebc80bc8e111dbb20b6b0ea1f3700af Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Wed, 28 Sep 2016 10:39:12 +0200 Subject: Get rid of `kind` in `MessageContainer` --- src/dotty/tools/dotc/printing/Formatting.scala | 5 +++- .../tools/dotc/reporting/ConsoleReporter.scala | 33 ++++++++++++++-------- .../tools/dotc/reporting/diagnostic/Message.scala | 18 +++++------- .../reporting/diagnostic/MessageContainer.scala | 1 - .../tools/dotc/reporting/diagnostic/messages.scala | 24 ++++++---------- 5 files changed, 40 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/dotty/tools/dotc/printing/Formatting.scala b/src/dotty/tools/dotc/printing/Formatting.scala index ae3819513..95ac03647 100644 --- a/src/dotty/tools/dotc/printing/Formatting.scala +++ b/src/dotty/tools/dotc/printing/Formatting.scala @@ -75,7 +75,7 @@ object Formatting { class SyntaxFormatter(sc: StringContext) extends StringFormatter(sc) { override protected def showArg(arg: Any)(implicit ctx: Context): String = { - arg match { + if (ctx.settings.color.value != "never") arg match { case arg: Showable => val highlighted = SyntaxHighlighting(wrapNonSensical(arg, super.showArg(arg))) @@ -84,8 +84,11 @@ object Formatting { hl.show case hb: HighlightBuffer => hb.toString + case str: String => + new String(SyntaxHighlighting(str).toArray) case _ => super.showArg(arg) } + else super.showArg(arg) } } diff --git a/src/dotty/tools/dotc/reporting/ConsoleReporter.scala b/src/dotty/tools/dotc/reporting/ConsoleReporter.scala index 261357924..e4c24643b 100644 --- a/src/dotty/tools/dotc/reporting/ConsoleReporter.scala +++ b/src/dotty/tools/dotc/reporting/ConsoleReporter.scala @@ -14,9 +14,8 @@ import diagnostic.{ Message, MessageContainer } import diagnostic.messages._ /** - * This class implements a more Fancy version (with colors!) of the regular - * `ConsoleReporter` - */ + * This class implements a Reporter that displays messages on a text console + */ class ConsoleReporter( reader: BufferedReader = Console.in, writer: PrintWriter = new PrintWriter(Console.err, true) @@ -66,18 +65,22 @@ class ConsoleReporter( .mkString(sys.props("line.separator")) } - def posStr(pos: SourcePosition, kind: String, errorId: String)(implicit ctx: Context) = + def posStr(pos: SourcePosition, diagnosticLevel: String, message: Message)(implicit ctx: Context) = if (pos.exists) Blue({ val file = pos.source.file.toString - val errId = if (errorId != "") s"[$errorId] " else "" + val errId = if (message.errorId != "") s"[${message.errorId}] " else "" + val kind = + if (message.kind == "") diagnosticLevel + else s"${message.kind} $diagnosticLevel" val prefix = s"-- ${errId}${kind}: $file " + prefix + ("-" * math.max(ctx.settings.pageWidth.value - stripColor(prefix).length, 0)) }).show else "" /** Prints the message with the given position indication. */ - def printMessageAndPos(msg: Message, pos: SourcePosition, kind: String)(implicit ctx: Context): Unit = { - printMessage(posStr(pos, kind, msg.errorId)) + def printMessageAndPos(msg: Message, pos: SourcePosition, diagnosticLevel: String)(implicit ctx: Context): Unit = { + printMessage(posStr(pos, diagnosticLevel, msg)) if (pos.exists) { val (src, offset) = sourceLine(pos) val marker = columnMarker(pos, offset) @@ -97,15 +100,21 @@ class ConsoleReporter( override def doReport(m: MessageContainer)(implicit ctx: Context): Unit = { m match { case m: Error => - printMessageAndPos(m.contained, m.pos, m.kind) + printMessageAndPos(m.contained, m.pos, "Error") if (ctx.settings.prompt.value) displayPrompt() case m: ConditionalWarning if !m.enablingOption.value => + case m: FeatureWarning => + printMessageAndPos(m.contained, m.pos, "Feature Warning") + case m: DeprecationWarning => + printMessageAndPos(m.contained, m.pos, "Deprecation Warning") + case m: UncheckedWarning => + printMessageAndPos(m.contained, m.pos, "Unchecked Warning") case m: MigrationWarning => - printMessageAndPos(m.contained, m.pos, m.kind) + printMessageAndPos(m.contained, m.pos, "Migration Warning") case m: Warning => - printMessageAndPos(m.contained, m.pos, m.kind) - case _ => - printMessageAndPos(m.contained, m.pos, m.kind) + printMessageAndPos(m.contained, m.pos, "Warning") + case m: Info => + printMessageAndPos(m.contained, m.pos, "Info") } if (ctx.shouldExplain(m)) printExplanation(m.contained) diff --git a/src/dotty/tools/dotc/reporting/diagnostic/Message.scala b/src/dotty/tools/dotc/reporting/diagnostic/Message.scala index 443dc4de8..125ac2e1c 100644 --- a/src/dotty/tools/dotc/reporting/diagnostic/Message.scala +++ b/src/dotty/tools/dotc/reporting/diagnostic/Message.scala @@ -18,10 +18,6 @@ abstract class Message(val errorId: String) { self => def kind: String def explanation: String - def container(c: String) = - if (kind == "") c - else s"$kind $c" - def mapMsg(f: String => String) = new Message(errorId) { val msg = f(self.msg) val kind = self.kind @@ -29,25 +25,25 @@ abstract class Message(val errorId: String) { self => } def error(pos: SourcePosition) = - new Error(self, pos, container("Error"), explanation) + new Error(self, pos, explanation) def warning(pos: SourcePosition) = - new Warning(self, pos, container("Warning"), explanation) + new Warning(self, pos, explanation) def info(pos: SourcePosition) = - new Info(self, pos, container("Info"), explanation) + new Info(self, pos, explanation) def featureWarning(pos: SourcePosition) = - new FeatureWarning(self, pos, container("Feature Warning"), explanation) + new FeatureWarning(self, pos, explanation) def uncheckedWarning(pos: SourcePosition) = - new UncheckedWarning(self, pos, container("Unchecked Warning"), explanation) + new UncheckedWarning(self, pos, explanation) def deprecationWarning(pos: SourcePosition) = - new DeprecationWarning(self, pos, container("Deprecation Warning"), explanation) + new DeprecationWarning(self, pos, explanation) def migrationWarning(pos: SourcePosition) = - new MigrationWarning(self, pos, container("Migration Warning"), explanation) + new MigrationWarning(self, pos, explanation) } class NoExplanation(val msg: String) extends Message("") { diff --git a/src/dotty/tools/dotc/reporting/diagnostic/MessageContainer.scala b/src/dotty/tools/dotc/reporting/diagnostic/MessageContainer.scala index a1a99f17d..f49bebd94 100644 --- a/src/dotty/tools/dotc/reporting/diagnostic/MessageContainer.scala +++ b/src/dotty/tools/dotc/reporting/diagnostic/MessageContainer.scala @@ -27,7 +27,6 @@ class MessageContainer( msgFn: => Message, val pos: SourcePosition, val level: Int, - val kind: String, val explanation: String ) extends Exception with interfaces.Diagnostic { import MessageContainer._ diff --git a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 034e14267..26c5622fa 100644 --- a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -18,66 +18,58 @@ object messages { class Error( msgFn: => Message, pos: SourcePosition, - kind: String, explanation: String = "" - ) extends MessageContainer(msgFn, pos, ERROR, kind, explanation) + ) extends MessageContainer(msgFn, pos, ERROR, explanation) class Warning( msgFn: => Message, pos: SourcePosition, - kind: String, explanation: String = "" - ) extends MessageContainer(msgFn, pos, WARNING, kind, explanation) + ) extends MessageContainer(msgFn, pos, WARNING, explanation) class Info( msgFn: => Message, pos: SourcePosition, - kind: String, explanation: String = "" - ) extends MessageContainer(msgFn, pos, INFO, kind, explanation) + ) extends MessageContainer(msgFn, pos, INFO, explanation) abstract class ConditionalWarning( msgFn: => Message, pos: SourcePosition, - kind: String, explanation: String = "" - ) extends Warning(msgFn, pos, kind, explanation) { + ) extends Warning(msgFn, pos, explanation) { def enablingOption(implicit ctx: Context): Setting[Boolean] } class FeatureWarning( msgFn: => Message, pos: SourcePosition, - kind: String = "Feature Warning", explanation: String = "" - ) extends ConditionalWarning(msgFn, pos, kind, explanation) { + ) extends ConditionalWarning(msgFn, pos, explanation) { def enablingOption(implicit ctx: Context) = ctx.settings.feature } class UncheckedWarning( msgFn: => Message, pos: SourcePosition, - kind: String = "Unchecked Warning", explanation: String = "" - ) extends ConditionalWarning(msgFn, pos, kind, explanation) { + ) extends ConditionalWarning(msgFn, pos, explanation) { def enablingOption(implicit ctx: Context) = ctx.settings.unchecked } class DeprecationWarning( msgFn: => Message, pos: SourcePosition, - kind: String = "Deprecation Warning", explanation: String = "" - ) extends ConditionalWarning(msgFn, pos, kind, explanation) { + ) extends ConditionalWarning(msgFn, pos, explanation) { def enablingOption(implicit ctx: Context) = ctx.settings.deprecation } class MigrationWarning( msgFn: => Message, pos: SourcePosition, - kind: String = "Migration Warning", explanation: String = "" - ) extends ConditionalWarning(msgFn, pos, kind, explanation) { + ) extends ConditionalWarning(msgFn, pos, explanation) { def enablingOption(implicit ctx: Context) = ctx.settings.migration } -- cgit v1.2.3