aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/reporting/diagnostic/Message.scala
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-09-19 19:26:16 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-10-10 13:25:34 +0200
commite24289ac19a21c6b3794d02e8fe42766224f173c (patch)
tree94dae1ffb70995c2851550952f0f17a953936711 /src/dotty/tools/dotc/reporting/diagnostic/Message.scala
parent628b7f317756ce2c366359a7399b8dda9d0190b7 (diff)
downloaddotty-e24289ac19a21c6b3794d02e8fe42766224f173c.tar.gz
dotty-e24289ac19a21c6b3794d02e8fe42766224f173c.tar.bz2
dotty-e24289ac19a21c6b3794d02e8fe42766224f173c.zip
Make relevant parts of compiler conform to new error handling
Diffstat (limited to 'src/dotty/tools/dotc/reporting/diagnostic/Message.scala')
-rw-r--r--src/dotty/tools/dotc/reporting/diagnostic/Message.scala98
1 files changed, 46 insertions, 52 deletions
diff --git a/src/dotty/tools/dotc/reporting/diagnostic/Message.scala b/src/dotty/tools/dotc/reporting/diagnostic/Message.scala
index b3c19820f..443dc4de8 100644
--- a/src/dotty/tools/dotc/reporting/diagnostic/Message.scala
+++ b/src/dotty/tools/dotc/reporting/diagnostic/Message.scala
@@ -3,66 +3,60 @@ package dotc
package reporting
package diagnostic
-import util.SourcePosition
+import util.{SourcePosition, NoSourcePosition}
import core.Contexts.Context
-import java.util.Optional
-
object Message {
- val nonSensicalStartTag = "<nonsensical>"
- val nonSensicalEndTag = "</nonsensical>"
-
- implicit class MessageContext(val c: Context) extends AnyVal {
- def shouldExplain(msg: Message): Boolean = {
- implicit val ctx: Context = c
- msg.explanation match {
- case "" => false
- case _ => ctx.settings.explain.value
- }
- }
- }
+ implicit def toNoExplanation(str: String): Message =
+ new NoExplanation(str)
}
-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
+abstract class Message(val errorId: String) { self =>
+ import messages._
+
+ def msg: String
+ def kind: String
+ def explanation: String
- override def position: Optional[interfaces.SourcePosition] =
- if (pos.exists && pos.source.exists) Optional.of(pos) else Optional.empty()
+ def container(c: String) =
+ if (kind == "") c
+ else s"$kind $c"
- /** The message to report */
- def message: String = {
- if (myMsg == null) {
- 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
+ def mapMsg(f: String => String) = new Message(errorId) {
+ val msg = f(self.msg)
+ val kind = self.kind
+ val explanation = self.explanation
}
- /** 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 }
+ def error(pos: SourcePosition) =
+ new Error(self, pos, container("Error"), explanation)
+
+ def warning(pos: SourcePosition) =
+ new Warning(self, pos, container("Warning"), explanation)
+
+ def info(pos: SourcePosition) =
+ new Info(self, pos, container("Info"), explanation)
+
+ def featureWarning(pos: SourcePosition) =
+ new FeatureWarning(self, pos, container("Feature Warning"), explanation)
+
+ def uncheckedWarning(pos: SourcePosition) =
+ new UncheckedWarning(self, pos, container("Unchecked Warning"), explanation)
+
+ def deprecationWarning(pos: SourcePosition) =
+ new DeprecationWarning(self, pos, container("Deprecation Warning"), explanation)
+
+ def migrationWarning(pos: SourcePosition) =
+ new MigrationWarning(self, pos, container("Migration Warning"), explanation)
+}
+
+class NoExplanation(val msg: String) extends Message("") {
+ val explanation = ""
+ val kind = ""
+}
- 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
}