aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-09-16 13:56:59 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-10-10 13:25:33 +0200
commit2b2cfe71aacb50e91d6956f0d4ee7d555537698a (patch)
tree039b512880367adc61d0b287f75d0c453946967c
parent18a69f7bd230bc06696e41be53a6735aa6e94ccc (diff)
downloaddotty-2b2cfe71aacb50e91d6956f0d4ee7d555537698a.tar.gz
dotty-2b2cfe71aacb50e91d6956f0d4ee7d555537698a.tar.bz2
dotty-2b2cfe71aacb50e91d6956f0d4ee7d555537698a.zip
Refactor common error messages to `diagnostic.basic`
-rw-r--r--interfaces/src/main/java/dotty/tools/dotc/interfaces/Diagnostic.java3
-rw-r--r--src/dotty/tools/dotc/printing/SyntaxHighlighting.scala2
-rw-r--r--src/dotty/tools/dotc/reporting/ConsoleReporter.scala1
-rw-r--r--src/dotty/tools/dotc/reporting/Reporter.scala34
-rw-r--r--src/dotty/tools/dotc/reporting/StoreReporter.scala1
-rw-r--r--src/dotty/tools/dotc/reporting/ThrowingReporter.scala1
-rw-r--r--src/dotty/tools/dotc/reporting/diagnostic/Message.scala (renamed from src/dotty/tools/dotc/reporting/diagnostic/Diagnostic.scala)35
-rw-r--r--src/dotty/tools/dotc/reporting/diagnostic/basic.scala80
-rw-r--r--src/dotty/tools/dotc/reporting/diagnostic/parser.scala8
9 files changed, 121 insertions, 44 deletions
diff --git a/interfaces/src/main/java/dotty/tools/dotc/interfaces/Diagnostic.java b/interfaces/src/main/java/dotty/tools/dotc/interfaces/Diagnostic.java
index ed1c37b1c..e62c1193e 100644
--- a/interfaces/src/main/java/dotty/tools/dotc/interfaces/Diagnostic.java
+++ b/interfaces/src/main/java/dotty/tools/dotc/interfaces/Diagnostic.java
@@ -20,6 +20,9 @@ public interface Diagnostic {
/** @return The message to report */
String message();
+ /** @return The explanation behind the message */
+ String explanation();
+
/** @return Level of the diagnostic, can be either ERROR, WARNING or INFO */
int level();
diff --git a/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala b/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala
index 958e71086..d94f6796d 100644
--- a/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala
+++ b/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala
@@ -12,7 +12,7 @@ object SyntaxHighlighting {
implicit class SyntaxFormatting(val sc: StringContext) extends AnyVal {
def hl(args: Any*)(implicit ctx: Context): String =
- if (ctx.settings.color.value == "never") sc.s(args)
+ if (ctx.settings.color.value == "never") sc.s(args: _*)
else sc.s(args.map(x => new String(apply(x.toString).toArray)): _*)
}
diff --git a/src/dotty/tools/dotc/reporting/ConsoleReporter.scala b/src/dotty/tools/dotc/reporting/ConsoleReporter.scala
index 1ed889683..4d8897820 100644
--- a/src/dotty/tools/dotc/reporting/ConsoleReporter.scala
+++ b/src/dotty/tools/dotc/reporting/ConsoleReporter.scala
@@ -9,6 +9,7 @@ import Reporter._
import java.io.{ BufferedReader, IOException, PrintWriter }
import scala.reflect.internal.util._
import diagnostic.Message
+import diagnostic.basic._
/**
* This class implements a Reporter that displays messages on a text
diff --git a/src/dotty/tools/dotc/reporting/Reporter.scala b/src/dotty/tools/dotc/reporting/Reporter.scala
index 8c9308ba5..ccbae94bf 100644
--- a/src/dotty/tools/dotc/reporting/Reporter.scala
+++ b/src/dotty/tools/dotc/reporting/Reporter.scala
@@ -4,49 +4,17 @@ package reporting
import core.Contexts._
import util.{SourcePosition, NoSourcePosition}
-import util.{SourceFile, NoSource}
import core.Decorators.PhaseListDecorator
import collection.mutable
-import config.Settings.Setting
import config.Printers
import java.lang.System.currentTimeMillis
import core.Mode
-import interfaces.Diagnostic.{ERROR, WARNING, INFO}
import dotty.tools.dotc.core.Symbols.Symbol
import diagnostic.Message
import ErrorMessages._
+import diagnostic.basic._
object Reporter {
- class Error(msgFn: => String, pos: SourcePosition, kind: String = "Error")
- extends Message(msgFn, pos, ERROR, kind)
-
- class Warning(msgFn: => String, pos: SourcePosition, kind: String = "Warning")
- extends Message(msgFn, pos, WARNING, kind)
-
- class Info(msgFn: => String, pos: SourcePosition, kind: String = "Info")
- extends Message(msgFn, pos, INFO, kind)
-
- abstract class ConditionalWarning(msgFn: => String, pos: SourcePosition, kind: String)
- extends Warning(msgFn, pos, kind) {
- def enablingOption(implicit ctx: Context): Setting[Boolean]
- }
- class FeatureWarning(msgFn: => String, pos: SourcePosition, kind: String = "Feature Warning")
- extends ConditionalWarning(msgFn, pos, kind) {
- def enablingOption(implicit ctx: Context) = ctx.settings.feature
- }
- class UncheckedWarning(msgFn: => String, pos: SourcePosition, kind: String = "Unchecked Warning")
- extends ConditionalWarning(msgFn, pos, kind) {
- def enablingOption(implicit ctx: Context) = ctx.settings.unchecked
- }
- class DeprecationWarning(msgFn: => String, pos: SourcePosition, kind: String = "Deprecation Warning")
- extends ConditionalWarning(msgFn, pos, kind) {
- def enablingOption(implicit ctx: Context) = ctx.settings.deprecation
- }
- class MigrationWarning(msgFn: => String, pos: SourcePosition, kind: String = "Migration Warning") extends
- ConditionalWarning(msgFn, pos, kind) {
- def enablingOption(implicit ctx: Context) = ctx.settings.migration
- }
-
/** Convert a SimpleReporter into a real Reporter */
def fromSimpleReporter(simple: interfaces.SimpleReporter): Reporter =
new Reporter with UniqueMessagePositions with HideNonSensicalMessages {
diff --git a/src/dotty/tools/dotc/reporting/StoreReporter.scala b/src/dotty/tools/dotc/reporting/StoreReporter.scala
index dd5935f4c..2aa2253a0 100644
--- a/src/dotty/tools/dotc/reporting/StoreReporter.scala
+++ b/src/dotty/tools/dotc/reporting/StoreReporter.scala
@@ -7,6 +7,7 @@ import collection.mutable
import Reporter.{Error, Warning}
import config.Printers.typr
import diagnostic.Message
+import diagnostic.basic._
/**
* This class implements a Reporter that stores all messages
diff --git a/src/dotty/tools/dotc/reporting/ThrowingReporter.scala b/src/dotty/tools/dotc/reporting/ThrowingReporter.scala
index 25adc6a41..b08145654 100644
--- a/src/dotty/tools/dotc/reporting/ThrowingReporter.scala
+++ b/src/dotty/tools/dotc/reporting/ThrowingReporter.scala
@@ -5,6 +5,7 @@ package reporting
import core.Contexts.Context
import collection.mutable
import diagnostic.Message
+import diagnostic.basic.Error
import Reporter._
/**
diff --git a/src/dotty/tools/dotc/reporting/diagnostic/Diagnostic.scala b/src/dotty/tools/dotc/reporting/diagnostic/Message.scala
index 230c1edc0..90ebf11a2 100644
--- a/src/dotty/tools/dotc/reporting/diagnostic/Diagnostic.scala
+++ b/src/dotty/tools/dotc/reporting/diagnostic/Message.scala
@@ -12,8 +12,13 @@ object Message {
val nonSensicalEndTag = "</nonsensical>"
}
-class Message(msgFn: => String, val pos: SourcePosition, val level: Int, val kind: String)
-extends Exception with interfaces.Diagnostic {
+class Message(
+ msgFn: => String,
+ val pos: SourcePosition,
+ val level: Int,
+ val kind: String,
+ val explanation: String
+) extends Exception with interfaces.Diagnostic {
import Message._
private var myMsg: String = null
private var myIsNonSensical: Boolean = false
@@ -27,22 +32,32 @@ extends Exception with interfaces.Diagnostic {
myMsg = msgFn
if (myMsg.contains(nonSensicalStartTag)) {
myIsNonSensical = true
- // myMsg might be composed of several d"..." invocations -> nested nonsensical tags possible
- myMsg = myMsg.replaceAllLiterally(nonSensicalStartTag, "").replaceAllLiterally(nonSensicalEndTag, "")
+ // myMsg might be composed of several d"..." invocations -> nested
+ // nonsensical tags possible
+ myMsg =
+ myMsg
+ .replaceAllLiterally(nonSensicalStartTag, "")
+ .replaceAllLiterally(nonSensicalEndTag, "")
}
}
myMsg
}
- /** A message is non-sensical if it contains references to <nonsensical> tags.
- * Such tags are inserted by the error diagnostic framework if a message
- * contains references to internally generated error types. Normally we
- * want to suppress error messages referring to types like this because
- * they look weird and are normally follow-up errors to something that
- * was diagnosed before.
+ /** A message is non-sensical if it contains references to <nonsensical>
+ * tags. Such tags are inserted by the error diagnostic framework if a
+ * message contains references to internally generated error types. Normally
+ * we want to suppress error messages referring to types like this because
+ * they look weird and are normally follow-up errors to something that was
+ * diagnosed before.
*/
def isNonSensical = { message; myIsNonSensical }
override def toString = s"$getClass at $pos: $message"
override def getMessage() = message
}
+
+object NoExplanation {
+ def unapply(m: Message): Option[Message] =
+ if (m.explanation == "") Some(m)
+ else None
+}
diff --git a/src/dotty/tools/dotc/reporting/diagnostic/basic.scala b/src/dotty/tools/dotc/reporting/diagnostic/basic.scala
new file mode 100644
index 000000000..2da986d89
--- /dev/null
+++ b/src/dotty/tools/dotc/reporting/diagnostic/basic.scala
@@ -0,0 +1,80 @@
+package dotty.tools
+package dotc
+package reporting
+package diagnostic
+
+import dotc.core.Contexts.Context
+import util.{SourceFile, NoSource}
+import util.{SourcePosition, NoSourcePosition}
+import config.Settings.Setting
+import interfaces.Diagnostic.{ERROR, WARNING, INFO}
+
+object basic {
+
+ class Error(
+ msgFn: => String,
+ pos: SourcePosition,
+ kind: String = "Error",
+ explanation: String = ""
+ ) extends Message(msgFn, pos, ERROR, kind, explanation)
+
+ class Warning(
+ msgFn: => String,
+ pos: SourcePosition,
+ kind: String = "Warning",
+ explanation: String = ""
+ ) extends Message(msgFn, pos, WARNING, kind, explanation)
+
+ class Info(
+ msgFn: => String,
+ pos: SourcePosition,
+ kind: String = "Info",
+ explanation: String = ""
+ ) extends Message(msgFn, pos, INFO, kind, explanation)
+
+ abstract class ConditionalWarning(
+ msgFn: => String,
+ pos: SourcePosition,
+ kind: String,
+ explanation: String = ""
+ ) extends Warning(msgFn, pos, kind, explanation) {
+ def enablingOption(implicit ctx: Context): Setting[Boolean]
+ }
+
+ class FeatureWarning(
+ msgFn: => String,
+ pos: SourcePosition,
+ kind: String = "Feature Warning",
+ explanation: String = ""
+ ) extends ConditionalWarning(msgFn, pos, kind, explanation) {
+ def enablingOption(implicit ctx: Context) = ctx.settings.feature
+ }
+
+ class UncheckedWarning(
+ msgFn: => String,
+ pos: SourcePosition,
+ kind: String = "Unchecked Warning",
+ explanation: String = ""
+ ) extends ConditionalWarning(msgFn, pos, kind, explanation) {
+ def enablingOption(implicit ctx: Context) = ctx.settings.unchecked
+ }
+
+ class DeprecationWarning(
+ msgFn: => String,
+ pos: SourcePosition,
+ kind: String = "Deprecation Warning",
+ explanation: String = ""
+ ) extends ConditionalWarning(msgFn, pos, kind, explanation) {
+ def enablingOption(implicit ctx: Context) = ctx.settings.deprecation
+ }
+
+ class MigrationWarning(
+ msgFn: => String,
+ pos: SourcePosition,
+ kind: String = "Migration Warning",
+ explanation: String = ""
+ ) extends ConditionalWarning(msgFn, pos, kind, explanation) {
+ def enablingOption(implicit ctx: Context) = ctx.settings.migration
+ }
+
+}
diff --git a/src/dotty/tools/dotc/reporting/diagnostic/parser.scala b/src/dotty/tools/dotc/reporting/diagnostic/parser.scala
new file mode 100644
index 000000000..b73e353eb
--- /dev/null
+++ b/src/dotty/tools/dotc/reporting/diagnostic/parser.scala
@@ -0,0 +1,8 @@
+package dotty.tools
+package dotc
+package reporting
+package diagnostic
+
+object parser {
+
+}