@@ -18,10 +18,9 @@ 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 : MessageContainer )(implicit ctx : Context ): Unit = m match {
22
- case m : ConditionalWarning if ! m.enablingOption.value =>
23
- case _ =>
24
- simple.report(m)
21
+ def report (m : MessageContainer )(implicit ctx : Context ): Boolean = m match {
22
+ case m : ConditionalWarning if ! m.enablingOption.value => false
23
+ case _ => simple.report(m); true
25
24
}
26
25
}
27
26
}
@@ -35,19 +34,19 @@ trait Reporting { this: Context =>
35
34
if (this .settings.verbose.value) this .echo(msg, pos)
36
35
37
36
def echo (msg : => String , pos : SourcePosition = NoSourcePosition ): Unit =
38
- reporter.report (new Info (msg, pos))
37
+ reporter.prepareReport (new Info (msg, pos))
39
38
40
39
def deprecationWarning (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
41
- reporter.report (new DeprecationWarning (msg, pos))
40
+ reporter.prepareReport (new DeprecationWarning (msg, pos))
42
41
43
42
def migrationWarning (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
44
- reporter.report (new MigrationWarning (msg, pos))
43
+ reporter.prepareReport (new MigrationWarning (msg, pos))
45
44
46
45
def uncheckedWarning (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
47
- reporter.report (new UncheckedWarning (msg, pos))
46
+ reporter.prepareReport (new UncheckedWarning (msg, pos))
48
47
49
48
def featureWarning (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
50
- reporter.report (new FeatureWarning (msg, pos))
49
+ reporter.prepareReport (new FeatureWarning (msg, pos))
51
50
52
51
def featureWarning (feature : String , featureDescription : String , isScala2Feature : Boolean ,
53
52
featureUseSite : Symbol , required : Boolean , pos : SourcePosition ): Unit = {
@@ -69,26 +68,26 @@ trait Reporting { this: Context =>
69
68
70
69
val msg = s " $featureDescription $req be enabled \n by making the implicit value $fqname visible. $explain"
71
70
if (required) error(msg, pos)
72
- else reporter.report (new FeatureWarning (msg, pos))
71
+ else reporter.prepareReport (new FeatureWarning (msg, pos))
73
72
}
74
73
75
74
def warning (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
76
- reporter.report (new Warning (msg, pos))
75
+ reporter.prepareReport (new Warning (msg, pos))
77
76
78
77
def strictWarning (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
79
78
if (this .settings.strict.value) error(msg, pos)
80
- else reporter.report {
79
+ else reporter.prepareReport {
81
80
new ExtendMessage (() => msg)(_ + " \n (This would be an error under strict mode)" ).warning(pos)
82
81
}
83
82
84
83
def error (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
85
- reporter.report (new Error (msg, pos))
84
+ reporter.prepareReport (new Error (msg, pos))
86
85
87
86
def errorOrMigrationWarning (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
88
87
if (ctx.scala2Mode) migrationWarning(msg, pos) else error(msg, pos)
89
88
90
89
def restrictionError (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
91
- reporter.report {
90
+ reporter.prepareReport {
92
91
new ExtendMessage (() => msg)(m => s " Implementation restriction: $m" ).error(pos)
93
92
}
94
93
@@ -190,13 +189,58 @@ trait Reporting { this: Context =>
190
189
}
191
190
192
191
/**
193
- * This interface provides methods to issue information, warning and
194
- * error messages.
195
- */
192
+ * This interface provides methods to issue information, warning and
193
+ * error messages.
194
+ *
195
+ * To implement this interface one only needs to implement `report` which
196
+ * should do the actual reporting.
197
+ */
196
198
abstract class Reporter extends interfaces.ReporterResult {
197
199
198
- /** Report a diagnostic */
199
- def doReport (d : MessageContainer )(implicit ctx : Context ): Unit
200
+ /** Report should be defined in leaf node reporters where forcing of the
201
+ * message is allowed.
202
+ *
203
+ * @note Report should make a call to `reportable` which, when applied will
204
+ * have forced the message depending on which traits have been mixed
205
+ * in
206
+ * @return true if did report, else false
207
+ */
208
+ protected def report (m : MessageContainer )(implicit ctx : Context ): Boolean
209
+
210
+ /** `reportable` will return a function which can inspect `MessageContainer`s
211
+ * to see if they should be reported or not
212
+ *
213
+ * @note implementing traits should compose functions by calling
214
+ * `super.reportable(m)` so that all mixins get applied
215
+ * @return `MessageContainer => Some[MessageContainer]` iff should report
216
+ */
217
+ def reportable (implicit ctx : Context ): MessageContainer => Option [MessageContainer ] =
218
+ m => if (ctx.mode.is(Mode .Printing )) Some (m) else None
219
+
220
+ /** Called when for each generated `MessageContainer`, the implementing reporter
221
+ * will then decide whether to report the message or not
222
+ *
223
+ * @return `true` iff message was reported
224
+ */
225
+ def prepareReport (m : MessageContainer )(implicit ctx : Context ): Boolean = {
226
+ val didReport = report(m)(ctx.addMode(Mode .Printing ))
227
+
228
+ if (didReport) {
229
+ m match {
230
+ case m : ConditionalWarning if ! m.enablingOption.value =>
231
+ unreportedWarnings(m.enablingOption.name) += 1
232
+ case m : Warning =>
233
+ warningCount += 1
234
+ case m : Error =>
235
+ errors = m :: errors
236
+ errorCount += 1
237
+ case m : Info =>
238
+ // nothing to do here, match error if other container
239
+ }
240
+ }
241
+
242
+ didReport
243
+ }
200
244
201
245
/** Whether very long lines can be truncated. This exists so important
202
246
* debugging information (like printing the classpath) is not rendered
@@ -240,20 +284,6 @@ abstract class Reporter extends interfaces.ReporterResult {
240
284
override def default (key : String ) = 0
241
285
}
242
286
243
- def report (d : => MessageContainer )(implicit ctx : Context ): Unit =
244
- if (! isHidden(d)) {
245
- doReport(d)(ctx.addMode(Mode .Printing ))
246
- d match {
247
- case d : ConditionalWarning if ! d.enablingOption.value => unreportedWarnings(d.enablingOption.name) += 1
248
- case d : Warning => warningCount += 1
249
- case d : Error =>
250
- errors = d :: errors
251
- errorCount += 1
252
- case d : Info => // nothing to do here
253
- // match error if d is something else
254
- }
255
- }
256
-
257
287
def incomplete (d : MessageContainer )(implicit ctx : Context ): Unit =
258
288
incompleteHandler(d)(ctx)
259
289
@@ -285,11 +315,8 @@ abstract class Reporter extends interfaces.ReporterResult {
285
315
case _ => n + " " + elements + " s"
286
316
}
287
317
288
- /** Should this diagnostic not be reported at all? */
289
- def isHidden (m : MessageContainer )(implicit ctx : Context ): Boolean = ctx.mode.is(Mode .Printing )
290
-
291
318
/** Does this reporter contain not yet reported errors or warnings? */
292
- def hasPending : Boolean = false
319
+ def hasPending ( implicit ctx : Context ) : Boolean = false
293
320
294
321
/** Issue all error messages in this reporter to next outer one, or make sure they are written. */
295
322
def flush ()(implicit ctx : Context ): Unit = {}
0 commit comments