diff options
author | Som Snytt <som.snytt@gmail.com> | 2017-02-12 21:27:38 -0800 |
---|---|---|
committer | Som Snytt <som.snytt@gmail.com> | 2017-02-13 02:48:09 -0800 |
commit | f7c17d2d8f0b5a3c23f2551fb2071e72e0f368c2 (patch) | |
tree | 09ebaf5f5a68af26f2ad8594466059b9c34c2893 /src/compiler | |
parent | 502e3c6296e5e997549b7e496e0bbfa62c522110 (diff) | |
download | scala-f7c17d2d8f0b5a3c23f2551fb2071e72e0f368c2.tar.gz scala-f7c17d2d8f0b5a3c23f2551fb2071e72e0f368c2.tar.bz2 scala-f7c17d2d8f0b5a3c23f2551fb2071e72e0f368c2.zip |
EOL is System.lineSeparator
The old EOL is EOL. Use `println()` when feasible and obvious.
Minor cleanup of surrounding code.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala | 69 |
1 files changed, 30 insertions, 39 deletions
diff --git a/src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala b/src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala index 342031b601..99263bf834 100644 --- a/src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala +++ b/src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala @@ -7,9 +7,10 @@ package scala package tools.nsc package reporters -import java.io.{ BufferedReader, PrintWriter } -import scala.reflect.internal.util._ -import StringOps._ +import java.io.{BufferedReader, PrintWriter} +import scala.reflect.internal.util.{Position, StringOps} +import Position.formatMessage +import StringOps.{countElementsAsString => countAs, trimAllTrailingSpace => trimTrailing} /** This class implements a Reporter that displays messages on a text console. */ @@ -26,47 +27,35 @@ class ConsoleReporter(val settings: Settings, reader: BufferedReader, writer: Pr private def label(severity: Severity): String = severity match { case ERROR => "error" case WARNING => "warning" - case INFO => null + case INFO => "" } - protected def clabel(severity: Severity): String = { - val label0 = label(severity) - if (label0 eq null) "" else label0 + ": " + protected def clabel(severity: Severity): String = label(severity) match { + case "" => "" + case s => s"$s: " } - /** Returns the number of errors issued totally as a string. - */ - private def getCountString(severity: Severity): String = - StringOps.countElementsAsString((severity).count, label(severity)) - /** Prints the message. */ - def printMessage(msg: String) { - writer print trimAllTrailingSpace(msg) + "\n" + def printMessage(msg: String): Unit = { + writer.println(trimTrailing(msg)) writer.flush() } /** Prints the message with the given position indication. */ - def printMessage(posIn: Position, msg: String) { - printMessage(Position.formatMessage(posIn, msg, shortname)) - } - def print(pos: Position, msg: String, severity: Severity) { - printMessage(pos, clabel(severity) + msg) - } + def printMessage(posIn: Position, msg: String): Unit = printMessage(formatMessage(posIn, msg, shortname)) - /** Prints the column marker of the given position. - */ - def printColumnMarker(pos: Position) = - if (pos.isDefined) { printMessage(" " * (pos.column - 1) + "^") } + def print(pos: Position, msg: String, severity: Severity): Unit = printMessage(pos, s"${clabel(severity)}${msg}") - /** Prints the number of errors and warnings if their are non-zero. */ - def printSummary() { - if (WARNING.count > 0) printMessage(getCountString(WARNING) + " found") - if ( ERROR.count > 0) printMessage(getCountString(ERROR ) + " found") - } + /** Prints the column marker of the given position. */ + def printColumnMarker(pos: Position): Unit = if (pos.isDefined) printMessage(" " * (pos.column - 1) + "^") + + /** Prints the number of warnings and errors if there are any. */ + def printSummary(): Unit = + for (k <- List(WARNING, ERROR) if k.count > 0) printMessage(s"${countAs(k.count, label(k))} found") def display(pos: Position, msg: String, severity: Severity): Unit = { val ok = severity match { - case ERROR => ERROR.count <= settings.maxerrs.value + case ERROR => ERROR.count <= settings.maxerrs.value case WARNING => WARNING.count <= settings.maxwarns.value case _ => true } @@ -74,17 +63,19 @@ class ConsoleReporter(val settings: Settings, reader: BufferedReader, writer: Pr } def displayPrompt(): Unit = { - writer.print("\na)bort, s)tack, r)esume: ") + writer.println() + writer.print("a)bort, s)tack, r)esume: ") writer.flush() if (reader != null) { - val response = reader.read().asInstanceOf[Char].toLower - if (response == 'a' || response == 's') { - (new Exception).printStackTrace() - if (response == 'a') - sys exit 1 - - writer.print("\n") - writer.flush() + reader.read match { + case 'a' | 'A' => + new Throwable().printStackTrace() + System.exit(1) + case 's' | 'S' => + new Throwable().printStackTrace() + writer.println() + writer.flush() + case _ => } } } |