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/settings/ScalaSettings.scala | |
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/settings/ScalaSettings.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/settings/ScalaSettings.scala | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala index c9d97a9469..c8251a542c 100644 --- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala @@ -134,6 +134,7 @@ trait ScalaSettings extends AbsScalaSettings val Xshowobj = StringSetting ("-Xshow-object", "object", "Show internal representation of object.", "") val showPhases = BooleanSetting ("-Xshow-phases", "Print a synopsis of compiler phases.") val sourceReader = StringSetting ("-Xsource-reader", "classname", "Specify a custom method for reading source files.", "") + val reporter = StringSetting ("-Xreporter", "classname", "Specify a custom reporter for compiler messages.", "scala.tools.nsc.reporters.ConsoleReporter") val strictInference = BooleanSetting ("-Xstrict-inference", "Don't infer known-unsound types") val source = ScalaVersionSetting ("-Xsource", "version", "Treat compiler input as Scala source for the specified version, see SI-8126.", initial = ScalaVersion("2.11")) |