aboutsummaryrefslogblamecommitdiff
path: root/src/dotty/tools/dotc/reporting/diagnostic/Message.scala
blob: 443dc4de87afe82f92cedebc76a6011d3937c6b2 (plain) (tree)
1
2
3
4
5
6
7
8
9


                   
                  
 
                                              
                            
 
                

                                                      

 





                                                     
 


                            
 



                                                          

   

























                                                                                    
 



                                            
 
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
}