@@ -18,10 +18,9 @@ object Reporter {
1818 /** Convert a SimpleReporter into a real Reporter */
1919 def fromSimpleReporter (simple : interfaces.SimpleReporter ): Reporter =
2020 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
2524 }
2625 }
2726}
@@ -35,19 +34,19 @@ trait Reporting { this: Context =>
3534 if (this .settings.verbose.value) this .echo(msg, pos)
3635
3736 def echo (msg : => String , pos : SourcePosition = NoSourcePosition ): Unit =
38- reporter.report (new Info (msg, pos))
37+ reporter.prepareReport (new Info (msg, pos))
3938
4039 def deprecationWarning (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
41- reporter.report (new DeprecationWarning (msg, pos))
40+ reporter.prepareReport (new DeprecationWarning (msg, pos))
4241
4342 def migrationWarning (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
44- reporter.report (new MigrationWarning (msg, pos))
43+ reporter.prepareReport (new MigrationWarning (msg, pos))
4544
4645 def uncheckedWarning (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
47- reporter.report (new UncheckedWarning (msg, pos))
46+ reporter.prepareReport (new UncheckedWarning (msg, pos))
4847
4948 def featureWarning (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
50- reporter.report (new FeatureWarning (msg, pos))
49+ reporter.prepareReport (new FeatureWarning (msg, pos))
5150
5251 def featureWarning (feature : String , featureDescription : String , isScala2Feature : Boolean ,
5352 featureUseSite : Symbol , required : Boolean , pos : SourcePosition ): Unit = {
@@ -69,26 +68,26 @@ trait Reporting { this: Context =>
6968
7069 val msg = s " $featureDescription $req be enabled \n by making the implicit value $fqname visible. $explain"
7170 if (required) error(msg, pos)
72- else reporter.report (new FeatureWarning (msg, pos))
71+ else reporter.prepareReport (new FeatureWarning (msg, pos))
7372 }
7473
7574 def warning (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
76- reporter.report (new Warning (msg, pos))
75+ reporter.prepareReport (new Warning (msg, pos))
7776
7877 def strictWarning (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
7978 if (this .settings.strict.value) error(msg, pos)
80- else reporter.report {
79+ else reporter.prepareReport {
8180 new ExtendMessage (() => msg)(_ + " \n (This would be an error under strict mode)" ).warning(pos)
8281 }
8382
8483 def error (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
85- reporter.report (new Error (msg, pos))
84+ reporter.prepareReport (new Error (msg, pos))
8685
8786 def errorOrMigrationWarning (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
8887 if (ctx.scala2Mode) migrationWarning(msg, pos) else error(msg, pos)
8988
9089 def restrictionError (msg : => Message , pos : SourcePosition = NoSourcePosition ): Unit =
91- reporter.report {
90+ reporter.prepareReport {
9291 new ExtendMessage (() => msg)(m => s " Implementation restriction: $m" ).error(pos)
9392 }
9493
@@ -190,13 +189,58 @@ trait Reporting { this: Context =>
190189}
191190
192191/**
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+ */
196198abstract class Reporter extends interfaces.ReporterResult {
197199
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+ }
200244
201245 /** Whether very long lines can be truncated. This exists so important
202246 * debugging information (like printing the classpath) is not rendered
@@ -240,20 +284,6 @@ abstract class Reporter extends interfaces.ReporterResult {
240284 override def default (key : String ) = 0
241285 }
242286
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-
257287 def incomplete (d : MessageContainer )(implicit ctx : Context ): Unit =
258288 incompleteHandler(d)(ctx)
259289
@@ -285,11 +315,8 @@ abstract class Reporter extends interfaces.ReporterResult {
285315 case _ => n + " " + elements + " s"
286316 }
287317
288- /** Should this diagnostic not be reported at all? */
289- def isHidden (m : MessageContainer )(implicit ctx : Context ): Boolean = ctx.mode.is(Mode .Printing )
290-
291318 /** Does this reporter contain not yet reported errors or warnings? */
292- def hasPending : Boolean = false
319+ def hasPending ( implicit ctx : Context ) : Boolean = false
293320
294321 /** Issue all error messages in this reporter to next outer one, or make sure they are written. */
295322 def flush ()(implicit ctx : Context ): Unit = {}
0 commit comments