aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/reporting/diagnostic/Message.scala
blob: 125ac2e1c67f93e45aae4d2e8453ec893d60ee9f (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
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 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, explanation)

  def warning(pos: SourcePosition) =
    new Warning(self, pos, explanation)

  def info(pos: SourcePosition) =
    new Info(self, pos, explanation)

  def featureWarning(pos: SourcePosition) =
    new FeatureWarning(self, pos, explanation)

  def uncheckedWarning(pos: SourcePosition) =
    new UncheckedWarning(self, pos, explanation)

  def deprecationWarning(pos: SourcePosition) =
    new DeprecationWarning(self, pos, explanation)

  def migrationWarning(pos: SourcePosition) =
    new MigrationWarning(self, pos, 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
}