aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/reporting/diagnostic/Message.scala
blob: 443dc4de87afe82f92cedebc76a6011d3937c6b2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package dotty.tools
package dotc
package reporting
package diagnostic

import util.{SourcePosition, NoSourcePosition}
import core.Contexts.Context

object Message {
  implicit def toNoExplanation(str: String): Message =
    new NoExplanation(str)
}

abstract class Message(val errorId: String) { self =>
  import messages._

  def msg: String
  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
    val explanation = self.explanation
  }

  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 = ""
}

object NoExplanation {
  def unapply(m: Message): Option[Message] =
    if (m.explanation == "") Some(m)
    else None
}