@@ -12,27 +12,30 @@ import Diagnostic.{ Error, ConditionalWarning }
12
12
class ConsoleReporter (
13
13
reader : BufferedReader = Console .in,
14
14
writer : PrintWriter = new PrintWriter (Console .err, true )
15
- ) extends AbstractReporter {
15
+ ) extends ConsoleReporter .AbstractConsoleReporter {
16
+ override def printMessage (msg : String ): Unit = { writer.print(msg + " \n " ); writer.flush() }
17
+ override def flush ()(using Context ): Unit = writer.flush()
16
18
17
- import Diagnostic ._
18
-
19
- /** Prints the message. */
20
- def printMessage (msg : String ): Unit = { writer.print(msg + " \n " ); writer.flush() }
21
-
22
- /** Prints the message with the given position indication. */
23
- def doReport (dia : Diagnostic )(using Context ): Unit = {
19
+ override def doReport (dia : Diagnostic )(using Context ): Unit = {
20
+ super .doReport(dia)
24
21
dia match
25
- case dia : Error =>
26
- printMessage(messageAndPos(dia))
27
- if (ctx.settings.Xprompt .value) Reporter .displayPrompt(reader, writer)
28
- case dia =>
29
- printMessage(messageAndPos(dia))
30
-
31
- if shouldExplain(dia) then
32
- printMessage(explanation(dia.msg))
33
- else if dia.msg.canExplain then
34
- printMessage(" \n longer explanation available when compiling with `-explain`" )
22
+ case dia : Error if ctx.settings.Xprompt .value => Reporter .displayPrompt(reader, writer)
23
+ case _ =>
35
24
}
25
+ }
26
+
27
+ object ConsoleReporter {
28
+ abstract class AbstractConsoleReporter extends AbstractReporter {
29
+ /** Prints the message. */
30
+ def printMessage (msg : String ): Unit
36
31
37
- override def flush ()(using Context ): Unit = { writer.flush() }
32
+ /** Prints the message with the given position indication. */
33
+ def doReport (dia : Diagnostic )(using Context ): Unit = {
34
+ printMessage(messageAndPos(dia))
35
+ if Diagnostic .shouldExplain(dia) then
36
+ printMessage(explanation(dia.msg))
37
+ else if dia.msg.canExplain then
38
+ printMessage(" \n longer explanation available when compiling with `-explain`" )
39
+ }
40
+ }
38
41
}
0 commit comments