Skip to content

Commit a4070dd

Browse files
committed
Rename Diagnostic to diagnostic.Message
1 parent 974c64e commit a4070dd

File tree

9 files changed

+67
-50
lines changed

9 files changed

+67
-50
lines changed

src/dotty/tools/dotc/printing/Formatting.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import collection.Map
88
import Decorators._
99
import scala.annotation.switch
1010
import scala.util.control.NonFatal
11-
import reporting.Diagnostic
11+
import reporting.diagnostic.Message
1212

1313
object Formatting {
1414

@@ -75,7 +75,8 @@ object Formatting {
7575
case _ => true
7676
}
7777
val str = super.showArg(arg)
78-
if (isSensical(arg)) str else Diagnostic.nonSensicalStartTag + str + Diagnostic.nonSensicalEndTag
78+
if (isSensical(arg)) str
79+
else Message.nonSensicalStartTag + str + Message.nonSensicalEndTag
7980
}
8081
}
8182

src/dotty/tools/dotc/reporting/ConsoleReporter.scala

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import core.Contexts._
88
import Reporter._
99
import java.io.{ BufferedReader, IOException, PrintWriter }
1010
import scala.reflect.internal.util._
11+
import diagnostic.Message
1112

1213
/**
1314
* This class implements a Reporter that displays messages on a text
@@ -40,17 +41,17 @@ class ConsoleReporter(
4041
}
4142
}
4243

43-
override def doReport(d: Diagnostic)(implicit ctx: Context): Unit = d match {
44-
case d: Error =>
45-
printMessageAndPos(d.message, d.pos, d.kind)
44+
override def doReport(m: Message)(implicit ctx: Context): Unit = m match {
45+
case m: Error =>
46+
printMessageAndPos(m.message, m.pos, m.kind)
4647
if (ctx.settings.prompt.value) displayPrompt()
47-
case d: ConditionalWarning if !d.enablingOption.value =>
48-
case d: MigrationWarning =>
49-
printMessageAndPos(d.message, d.pos, d.kind)
50-
case d: Warning =>
51-
printMessageAndPos(d.message, d.pos, d.kind)
48+
case m: ConditionalWarning if !m.enablingOption.value =>
49+
case m: MigrationWarning =>
50+
printMessageAndPos(m.message, m.pos, m.kind)
51+
case m: Warning =>
52+
printMessageAndPos(m.message, m.pos, m.kind)
5253
case _ =>
53-
printMessageAndPos(d.message, d.pos, d.kind)
54+
printMessageAndPos(m.message, m.pos, m.kind)
5455
}
5556

5657
def displayPrompt(): Unit = {

src/dotty/tools/dotc/reporting/HideNonSensicalMessages.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dotc
33
package reporting
44

55
import core.Contexts.Context
6+
import diagnostic.Message
67

78
/**
89
* This trait implements `isHidden` so that we avoid reporting non-sensical messages.
@@ -11,9 +12,9 @@ trait HideNonSensicalMessages extends Reporter {
1112
/** Hides non-sensical messages, unless we haven't reported any error yet or
1213
* `-Yshow-suppressed-errors` is set.
1314
*/
14-
override def isHidden(d: Diagnostic)(implicit ctx: Context): Boolean =
15-
super.isHidden(d) || {
16-
d.isNonSensical &&
15+
override def isHidden(m: Message)(implicit ctx: Context): Boolean =
16+
super.isHidden(m) || {
17+
m.isNonSensical &&
1718
hasErrors && // if there are no errors yet, report even if diagnostic is non-sensical
1819
!ctx.settings.YshowSuppressedErrors.value
1920
}

src/dotty/tools/dotc/reporting/Reporter.scala

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,47 @@ import java.lang.System.currentTimeMillis
1313
import core.Mode
1414
import interfaces.Diagnostic.{ERROR, WARNING, INFO}
1515
import dotty.tools.dotc.core.Symbols.Symbol
16+
import diagnostic.Message
1617
import ErrorMessages._
1718

1819
object Reporter {
19-
class Error(msgFn: => String, pos: SourcePosition, kind: String = "Error") extends Diagnostic(msgFn, pos, ERROR, kind)
20-
class Warning(msgFn: => String, pos: SourcePosition, kind: String = "Warning") extends Diagnostic(msgFn, pos, WARNING, kind)
21-
class Info(msgFn: => String, pos: SourcePosition, kind: String = "Info") extends Diagnostic(msgFn, pos, INFO, kind)
20+
class Error(msgFn: => String, pos: SourcePosition, kind: String = "Error")
21+
extends Message(msgFn, pos, ERROR, kind)
2222

23-
abstract class ConditionalWarning(msgFn: => String, pos: SourcePosition, kind: String) extends Warning(msgFn, pos, kind) {
23+
class Warning(msgFn: => String, pos: SourcePosition, kind: String = "Warning")
24+
extends Message(msgFn, pos, WARNING, kind)
25+
26+
class Info(msgFn: => String, pos: SourcePosition, kind: String = "Info")
27+
extends Message(msgFn, pos, INFO, kind)
28+
29+
abstract class ConditionalWarning(msgFn: => String, pos: SourcePosition, kind: String)
30+
extends Warning(msgFn, pos, kind) {
2431
def enablingOption(implicit ctx: Context): Setting[Boolean]
2532
}
26-
class FeatureWarning(msgFn: => String, pos: SourcePosition, kind: String = "Feature Warning") extends ConditionalWarning(msgFn, pos, kind) {
33+
class FeatureWarning(msgFn: => String, pos: SourcePosition, kind: String = "Feature Warning")
34+
extends ConditionalWarning(msgFn, pos, kind) {
2735
def enablingOption(implicit ctx: Context) = ctx.settings.feature
2836
}
29-
class UncheckedWarning(msgFn: => String, pos: SourcePosition, kind: String = "Unchecked Warning") extends ConditionalWarning(msgFn, pos, kind) {
37+
class UncheckedWarning(msgFn: => String, pos: SourcePosition, kind: String = "Unchecked Warning")
38+
extends ConditionalWarning(msgFn, pos, kind) {
3039
def enablingOption(implicit ctx: Context) = ctx.settings.unchecked
3140
}
32-
class DeprecationWarning(msgFn: => String, pos: SourcePosition, kind: String = "Deprecation Warning") extends ConditionalWarning(msgFn, pos, kind) {
41+
class DeprecationWarning(msgFn: => String, pos: SourcePosition, kind: String = "Deprecation Warning")
42+
extends ConditionalWarning(msgFn, pos, kind) {
3343
def enablingOption(implicit ctx: Context) = ctx.settings.deprecation
3444
}
35-
class MigrationWarning(msgFn: => String, pos: SourcePosition, kind: String = "Migration Warning") extends ConditionalWarning(msgFn, pos, kind) {
45+
class MigrationWarning(msgFn: => String, pos: SourcePosition, kind: String = "Migration Warning") extends
46+
ConditionalWarning(msgFn, pos, kind) {
3647
def enablingOption(implicit ctx: Context) = ctx.settings.migration
3748
}
3849

3950
/** Convert a SimpleReporter into a real Reporter */
4051
def fromSimpleReporter(simple: interfaces.SimpleReporter): Reporter =
4152
new Reporter with UniqueMessagePositions with HideNonSensicalMessages {
42-
override def doReport(d: Diagnostic)(implicit ctx: Context): Unit = d match {
43-
case d: ConditionalWarning if !d.enablingOption.value =>
53+
override def doReport(m: Message)(implicit ctx: Context): Unit = m match {
54+
case m: ConditionalWarning if !m.enablingOption.value =>
4455
case _ =>
45-
simple.report(d)
56+
simple.report(m)
4657
}
4758
}
4859
}
@@ -207,7 +218,7 @@ trait Reporting { this: Context =>
207218
abstract class Reporter extends interfaces.ReporterResult {
208219

209220
/** Report a diagnostic */
210-
def doReport(d: Diagnostic)(implicit ctx: Context): Unit
221+
def doReport(d: Message)(implicit ctx: Context): Unit
211222

212223
/** Whether very long lines can be truncated. This exists so important
213224
* debugging information (like printing the classpath) is not rendered
@@ -222,7 +233,7 @@ abstract class Reporter extends interfaces.ReporterResult {
222233
finally _truncationOK = saved
223234
}
224235

225-
type ErrorHandler = Diagnostic => Context => Unit
236+
type ErrorHandler = Message => Context => Unit
226237
private var incompleteHandler: ErrorHandler = d => c => report(d)(c)
227238
def withIncompleteHandler[T](handler: ErrorHandler)(op: => T): T = {
228239
val saved = incompleteHandler
@@ -251,7 +262,7 @@ abstract class Reporter extends interfaces.ReporterResult {
251262
override def default(key: String) = 0
252263
}
253264

254-
def report(d: Diagnostic)(implicit ctx: Context): Unit =
265+
def report(d: Message)(implicit ctx: Context): Unit =
255266
if (!isHidden(d)) {
256267
doReport(d)(ctx.addMode(Mode.Printing))
257268
d match {
@@ -265,7 +276,7 @@ abstract class Reporter extends interfaces.ReporterResult {
265276
}
266277
}
267278

268-
def incomplete(d: Diagnostic)(implicit ctx: Context): Unit =
279+
def incomplete(d: Message)(implicit ctx: Context): Unit =
269280
incompleteHandler(d)(ctx)
270281

271282

@@ -298,7 +309,7 @@ abstract class Reporter extends interfaces.ReporterResult {
298309
}
299310

300311
/** Should this diagnostic not be reported at all? */
301-
def isHidden(d: Diagnostic)(implicit ctx: Context): Boolean = ctx.mode.is(Mode.Printing)
312+
def isHidden(m: Message)(implicit ctx: Context): Boolean = ctx.mode.is(Mode.Printing)
302313

303314
/** Does this reporter contain not yet reported errors or warnings? */
304315
def hasPending: Boolean = false

src/dotty/tools/dotc/reporting/StoreReporter.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,25 @@ import core.Contexts.Context
66
import collection.mutable
77
import Reporter.{Error, Warning}
88
import config.Printers._
9+
import diagnostic.Message
910

1011
/**
1112
* This class implements a Reporter that stores all messages
1213
*/
1314
class StoreReporter(outer: Reporter) extends Reporter {
1415

15-
private var infos: mutable.ListBuffer[Diagnostic] = null
16+
private var infos: mutable.ListBuffer[Message] = null
1617

17-
def doReport(d: Diagnostic)(implicit ctx: Context): Unit = {
18-
typr.println(s">>>> StoredError: ${d.message}") // !!! DEBUG
18+
def doReport(m: Message)(implicit ctx: Context): Unit = {
19+
typr.println(s">>>> StoredError: ${m.message}") // !!! DEBUG
1920
if (infos == null) infos = new mutable.ListBuffer
20-
infos += d
21+
infos += m
2122
}
2223

2324
override def hasPending: Boolean = infos != null && {
2425
infos exists {
25-
case d: Error => true
26-
case d: Warning => true
26+
case _: Error => true
27+
case _: Warning => true
2728
case _ => false
2829
}
2930
}

src/dotty/tools/dotc/reporting/ThrowingReporter.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ package reporting
44

55
import core.Contexts.Context
66
import collection.mutable
7+
import diagnostic.Message
78
import Reporter._
89

910
/**
1011
* This class implements a Reporter that throws all errors and sends warnings and other
1112
* info to the underlying reporter.
1213
*/
1314
class ThrowingReporter(reportInfo: Reporter) extends Reporter {
14-
def doReport(d: Diagnostic)(implicit ctx: Context): Unit = d match {
15-
case _: Error => throw d
16-
case _ => reportInfo.doReport(d)
15+
def doReport(m: Message)(implicit ctx: Context): Unit = m match {
16+
case _: Error => throw m
17+
case _ => reportInfo.doReport(m)
1718
}
1819
}

src/dotty/tools/dotc/reporting/UniqueMessagePositions.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package reporting
55
import scala.collection.mutable
66
import util.{SourcePosition, SourceFile}
77
import core.Contexts.Context
8+
import diagnostic.Message
89

910
/**
1011
* This trait implements `isHidden` so that multiple messages per position
@@ -17,12 +18,12 @@ trait UniqueMessagePositions extends Reporter {
1718
/** Logs a position and returns true if it was already logged.
1819
* @note Two positions are considered identical for logging if they have the same point.
1920
*/
20-
override def isHidden(d: Diagnostic)(implicit ctx: Context): Boolean =
21-
super.isHidden(d) || {
22-
d.pos.exists && {
23-
positions get (ctx.source, d.pos.point) match {
24-
case Some(level) if level >= d.level => true
25-
case _ => positions((ctx.source, d.pos.point)) = d.level; false
21+
override def isHidden(m: Message)(implicit ctx: Context): Boolean =
22+
super.isHidden(m) || {
23+
m.pos.exists && {
24+
positions get (ctx.source, m.pos.point) match {
25+
case Some(level) if level >= m.level => true
26+
case _ => positions((ctx.source, m.pos.point)) = m.level; false
2627
}
2728
}
2829
}

src/dotty/tools/dotc/reporting/Diagnostic.scala renamed to src/dotty/tools/dotc/reporting/diagnostic/Diagnostic.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
package dotty.tools
22
package dotc
33
package reporting
4+
package diagnostic
45

56
import util.SourcePosition
67

78
import java.util.Optional
89

9-
object Diagnostic {
10+
object Message {
1011
val nonSensicalStartTag = "<nonsensical>"
1112
val nonSensicalEndTag = "</nonsensical>"
1213
}
1314

14-
class Diagnostic(msgFn: => String, val pos: SourcePosition, val level: Int, val kind: String)
15-
extends Exception with interfaces.Diagnostic {
16-
import Diagnostic._
15+
class Message(msgFn: => String, val pos: SourcePosition, val level: Int, val kind: String)
16+
extends Exception with interfaces.Diagnostic {
17+
import Message._
1718
private var myMsg: String = null
1819
private var myIsNonSensical: Boolean = false
1920

src/dotty/tools/dotc/typer/ErrorReporting.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import Trees._
88
import Types._, ProtoTypes._, Contexts._, Decorators._, Denotations._, Symbols._
99
import Applications._, Implicits._, Flags._
1010
import util.Positions._
11-
import reporting.Diagnostic
1211
import printing.{Showable, RefinedPrinter}
1312
import scala.collection.mutable
1413
import java.util.regex.Matcher.quoteReplacement

0 commit comments

Comments
 (0)