aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/reporting/diagnostic/MessageCreator.scala
blob: 99ccca4cc7b6817be22e997d966815eb052db905 (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
package dotty.tools
package dotc
package reporting
package diagnostic

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

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

trait MessageCreator {
  import messages._

  def msg: String
  def kind: String
  def explanation: String

  def error(pos: SourcePosition) =
    new Error(msg, pos, kind, explanation)

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

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

  def featureWarnign(pos: SourcePosition) =
    new FeatureWarning(msg, pos, kind, explanation)

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

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

  def migrationWarning(pos: SourcePosition) =
    new MigrationWarning(msg, pos, kind, explanation)
}

class NoExplanation(val msg: String) extends MessageCreator {
  val explanation = ""
  val kind = ""
}

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