diff options
author | Som Snytt <som.snytt@gmail.com> | 2015-06-08 11:09:42 -0700 |
---|---|---|
committer | Som Snytt <som.snytt@gmail.com> | 2015-06-29 10:26:44 -0700 |
commit | 7a076931491ee2467e76f480386ea05e319ec3a2 (patch) | |
tree | d5335f61005653b5a02b86133161de208773d6b9 /src/compiler/scala/tools/nsc/reporters | |
parent | ffcf07347925cabdfc205aec1e4ff42de840ba5e (diff) | |
download | scala-7a076931491ee2467e76f480386ea05e319ec3a2.tar.gz scala-7a076931491ee2467e76f480386ea05e319ec3a2.tar.bz2 scala-7a076931491ee2467e76f480386ea05e319ec3a2.zip |
SI-9350 Command option -Xreporter
Add a setting to take a custom Reporter.
Example of reporter that discounts deprecations for purposes of
(not) failing the build:
```
import scala.tools.nsc.Settings
import scala.tools.nsc.reporters.ConsoleReporter
import scala.reflect.internal.util._
class MyReporter(ss: Settings) extends ConsoleReporter(ss) {
var deprecationCount = 0
override def warning(pos: Position, msg: String): Unit = {
if (msg contains "is deprecated") deprecationCount += 1
super.warning(pos, msg)
}
override def hasWarnings: Boolean = count(WARNING) - deprecationCount > 0
override def reset() = { deprecationCount = 0 ; super.reset() }
}
```
Invoked as:
```
$ scalac -toolcp . -Xreporter myrep.MyReporter -Xfatal-warnings -deprecation test.scala
test.scala:8: warning: class C in package tester is deprecated: Don't use me
Console println s"${new C}"
^
one warning found
```
where the reporter class is in the current directory, placed on the tool class path.
Also flush on early-reported errors.
Diffstat (limited to 'src/compiler/scala/tools/nsc/reporters')
-rw-r--r-- | src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala b/src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala index 5bf611a7b0..4bf92fd1fb 100644 --- a/src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala +++ b/src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala @@ -11,8 +11,7 @@ import java.io.{ BufferedReader, IOException, PrintWriter } import scala.reflect.internal.util._ import StringOps._ -/** - * This class implements a Reporter that displays messages on a text console. +/** This class implements a Reporter that displays messages on a text console. */ class ConsoleReporter(val settings: Settings, reader: BufferedReader, writer: PrintWriter) extends AbstractReporter { def this(settings: Settings) = this(settings, Console.in, new PrintWriter(Console.err, true)) @@ -85,5 +84,7 @@ class ConsoleReporter(val settings: Settings, reader: BufferedReader, writer: Pr } } - override def flush() { writer.flush() } + override def flush() = writer.flush() + + override def finish() = printSummary() } |