@@ -12,13 +12,13 @@ import core.Mode
12
12
import dotty .tools .dotc .core .Symbols .Symbol
13
13
import diagnostic .messages ._
14
14
import diagnostic ._
15
- import MessageCreator ._
15
+ import Message ._
16
16
17
17
object Reporter {
18
18
/** Convert a SimpleReporter into a real Reporter */
19
19
def fromSimpleReporter (simple : interfaces.SimpleReporter ): Reporter =
20
20
new Reporter with UniqueMessagePositions with HideNonSensicalMessages {
21
- override def doReport (m : Message )(implicit ctx : Context ): Unit = m match {
21
+ override def doReport (m : MessageContainer )(implicit ctx : Context ): Unit = m match {
22
22
case m : ConditionalWarning if ! m.enablingOption.value =>
23
23
case _ =>
24
24
simple.report(m)
@@ -37,17 +37,17 @@ trait Reporting { this: Context =>
37
37
def echo (msg : => String , pos : SourcePosition = NoSourcePosition ): Unit =
38
38
reporter.report(new Info (msg, pos, " Info" ))
39
39
40
- def deprecationWarning (msg : => String , pos : SourcePosition = NoSourcePosition ): Unit =
41
- reporter.report(new DeprecationWarning ( msg, pos, " Deprecation Warning " ))
40
+ def deprecationWarning (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
41
+ reporter.report(msg.deprecationWarning( pos))
42
42
43
- def migrationWarning (msg : => String , pos : SourcePosition = NoSourcePosition ): Unit =
44
- reporter.report(new MigrationWarning ( msg, pos, " Migration Warning " ))
43
+ def migrationWarning (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
44
+ reporter.report(msg.migrationWarning( pos))
45
45
46
- def uncheckedWarning (msg : => String , pos : SourcePosition = NoSourcePosition ): Unit =
47
- reporter.report(new UncheckedWarning ( msg, pos, " Unchecked Warning " ))
46
+ def uncheckedWarning (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
47
+ reporter.report(msg.uncheckedWarning( pos))
48
48
49
- def featureWarning (msg : => String , pos : SourcePosition = NoSourcePosition ): Unit =
50
- reporter.report(new FeatureWarning ( msg, pos, " Feature Warning " ))
49
+ def featureWarning (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
50
+ reporter.report(msg.featureWarning( pos))
51
51
52
52
def featureWarning (feature : String , featureDescription : String , isScala2Feature : Boolean ,
53
53
featureUseSite : Symbol , required : Boolean , pos : SourcePosition ): Unit = {
@@ -72,32 +72,24 @@ trait Reporting { this: Context =>
72
72
else reporter.report(new FeatureWarning (msg, pos))
73
73
}
74
74
75
- def warning (msg : => String , pos : SourcePosition = NoSourcePosition ): Unit =
76
- reporter.report(new Warning (msg, pos))
77
-
78
- def explainWarning (msg : => MessageCreator , pos : SourcePosition = NoSourcePosition ): Unit =
75
+ def warning (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
79
76
reporter.report(msg.warning(pos))
80
77
81
- def strictWarning (msg : => String , pos : SourcePosition = NoSourcePosition ): Unit =
78
+ def strictWarning (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
82
79
if (this .settings.strict.value) error(msg, pos)
83
- else warning(msg + " \n (This would be an error under strict mode)" , pos)
84
-
85
- def error (msg : => String , pos : SourcePosition = NoSourcePosition ): Unit = {
86
- // println("*** ERROR: " + msg) // !!! DEBUG
87
- reporter.report(new Error (msg, pos))
88
- }
80
+ else warning(msg.mapMsg(_ + " \n (This would be an error under strict mode)" ), pos)
89
81
90
- def explainError (msg : => MessageCreator , pos : SourcePosition = NoSourcePosition ): Unit =
82
+ def error (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
91
83
reporter.report(msg.error(pos))
92
84
93
- def errorOrMigrationWarning (msg : => String , pos : SourcePosition = NoSourcePosition ): Unit =
85
+ def errorOrMigrationWarning (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
94
86
if (ctx.scala2Mode) migrationWarning(msg, pos) else error(msg, pos)
95
87
96
- def restrictionError (msg : => String , pos : SourcePosition = NoSourcePosition ): Unit =
97
- error(s " Implementation restriction: $msg " , pos)
88
+ def restrictionError (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
89
+ error(msg.mapMsg(m => s " Implementation restriction: $m " ) , pos)
98
90
99
- def incompleteInputError (msg : String , pos : SourcePosition = NoSourcePosition )(implicit ctx : Context ): Unit =
100
- reporter.incomplete(new Error ( msg, pos))(ctx)
91
+ def incompleteInputError (msg : Message , pos : SourcePosition = NoSourcePosition )(implicit ctx : Context ): Unit =
92
+ reporter.incomplete(msg.error( pos))(ctx)
101
93
102
94
/** Log msg if settings.log contains the current phase.
103
95
* See [[config.CompilerCommand#explainAdvanced ]] for the exact meaning of
@@ -184,7 +176,7 @@ trait Reporting { this: Context =>
184
176
abstract class Reporter extends interfaces.ReporterResult {
185
177
186
178
/** Report a diagnostic */
187
- def doReport (d : Message )(implicit ctx : Context ): Unit
179
+ def doReport (d : MessageContainer )(implicit ctx : Context ): Unit
188
180
189
181
/** Whether very long lines can be truncated. This exists so important
190
182
* debugging information (like printing the classpath) is not rendered
@@ -199,7 +191,7 @@ abstract class Reporter extends interfaces.ReporterResult {
199
191
finally _truncationOK = saved
200
192
}
201
193
202
- type ErrorHandler = Message => Context => Unit
194
+ type ErrorHandler = MessageContainer => Context => Unit
203
195
private var incompleteHandler : ErrorHandler = d => c => report(d)(c)
204
196
def withIncompleteHandler [T ](handler : ErrorHandler )(op : => T ): T = {
205
197
val saved = incompleteHandler
@@ -228,7 +220,7 @@ abstract class Reporter extends interfaces.ReporterResult {
228
220
override def default (key : String ) = 0
229
221
}
230
222
231
- def report (d : Message )(implicit ctx : Context ): Unit =
223
+ def report (d : MessageContainer )(implicit ctx : Context ): Unit =
232
224
if (! isHidden(d)) {
233
225
doReport(d)(ctx.addMode(Mode .Printing ))
234
226
d match {
@@ -242,12 +234,11 @@ abstract class Reporter extends interfaces.ReporterResult {
242
234
}
243
235
}
244
236
245
- def incomplete (d : Message )(implicit ctx : Context ): Unit =
237
+ def incomplete (d : MessageContainer )(implicit ctx : Context ): Unit =
246
238
incompleteHandler(d)(ctx)
247
239
248
-
249
240
/** Summary of warnings and errors */
250
- def summary /* (implicit ctx: Context) */ : String = {
241
+ def summary : String = {
251
242
val b = new mutable.ListBuffer [String ]
252
243
if (warningCount > 0 )
253
244
b += countString(warningCount, " warning" ) + " found"
@@ -275,7 +266,7 @@ abstract class Reporter extends interfaces.ReporterResult {
275
266
}
276
267
277
268
/** Should this diagnostic not be reported at all? */
278
- def isHidden (m : Message )(implicit ctx : Context ): Boolean = ctx.mode.is(Mode .Printing )
269
+ def isHidden (m : MessageContainer )(implicit ctx : Context ): Boolean = ctx.mode.is(Mode .Printing )
279
270
280
271
/** Does this reporter contain not yet reported errors or warnings? */
281
272
def hasPending : Boolean = false
0 commit comments