aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/reporting/Reporter.scala
diff options
context:
space:
mode:
authorGuillaume Martres <smarter@ubuntu.com>2016-02-24 23:53:35 +0100
committerGuillaume Martres <smarter@ubuntu.com>2016-02-28 20:08:59 +0100
commit7e7ee820df7647680d9aaf1ca991fe9718159097 (patch)
tree26095cec3a83fc12984e745e459dcb3d0996d045 /src/dotty/tools/dotc/reporting/Reporter.scala
parent94b41d5c491878543288af1bedb4daf57226ca07 (diff)
downloaddotty-7e7ee820df7647680d9aaf1ca991fe9718159097.tar.gz
dotty-7e7ee820df7647680d9aaf1ca991fe9718159097.tar.bz2
dotty-7e7ee820df7647680d9aaf1ca991fe9718159097.zip
Add a `dotty-interfaces` package
We introduce a new entry point for the compiler in `dotty.tools.dotc.Driver`: ``` def process(args: Array[String], simple: interfaces.SimpleReporter, callback: interfaces.CompilerCallback): interfaces.ReporterResult ``` Except for `args` which is just an array, the argument types and return type of this method are Java interfaces defined in a new package called `dotty-interfaces` which has a stable ABI. This means that you can programmatically run a compiler with a custom reporter and callbacks without having to recompile it against every version of dotty: you only need to have `dotty-interfaces` present at compile-time and call the `process` method using Java reflection. See `test/test/InterfaceEntryPointTest.scala` for a concrete example. This design is based on discussions with the IntelliJ IDEA Scala plugin team. Thanks to Nikolay Tropin for the discussions and his PR proposal (see #1011).
Diffstat (limited to 'src/dotty/tools/dotc/reporting/Reporter.scala')
-rw-r--r--src/dotty/tools/dotc/reporting/Reporter.scala14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/reporting/Reporter.scala b/src/dotty/tools/dotc/reporting/Reporter.scala
index f4eb551a1..8236f93ef 100644
--- a/src/dotty/tools/dotc/reporting/Reporter.scala
+++ b/src/dotty/tools/dotc/reporting/Reporter.scala
@@ -11,7 +11,7 @@ import config.Settings.Setting
import config.Printers
import java.lang.System.currentTimeMillis
import typer.Mode
-import Diagnostic.{ERROR, WARNING, INFO}
+import interfaces.Diagnostic.{ERROR, WARNING, INFO}
object Reporter {
class Error(msgFn: => String, pos: SourcePosition) extends Diagnostic(msgFn, pos, ERROR)
@@ -33,6 +33,16 @@ object Reporter {
class MigrationWarning(msgFn: => String, pos: SourcePosition) extends ConditionalWarning(msgFn, pos) {
def enablingOption(implicit ctx: Context) = ctx.settings.migration
}
+
+ /** Convert a SimpleReporter into a real Reporter */
+ def fromSimpleReporter(simple: interfaces.SimpleReporter): Reporter =
+ new Reporter with UniqueMessagePositions with HideNonSensicalMessages {
+ override def doReport(d: Diagnostic)(implicit ctx: Context): Unit = d match {
+ case d: ConditionalWarning if !d.enablingOption.value =>
+ case _ =>
+ simple.report(d)
+ }
+ }
}
import Reporter._
@@ -157,7 +167,7 @@ trait Reporting { this: Context =>
* This interface provides methods to issue information, warning and
* error messages.
*/
-abstract class Reporter {
+abstract class Reporter extends interfaces.ReporterResult {
/** Report a diagnostic */
def doReport(d: Diagnostic)(implicit ctx: Context): Unit