diff options
author | Guillaume Massé <masgui@gmail.com> | 2016-09-21 14:00:23 -0400 |
---|---|---|
committer | Guillaume Massé <masgui@gmail.com> | 2016-09-22 13:44:50 -0400 |
commit | 1e2bbb2c0bc7c9ba4bb626d4e45a5ab8519ec751 (patch) | |
tree | 93a2a5a47c044aedc64833960189ba4939adea39 /bridge/src/main/scala/xsbt/DelegatingReporter.scala | |
parent | bcbc62ec8940fb9639da51778282cc805c23f84a (diff) | |
download | dotty-1e2bbb2c0bc7c9ba4bb626d4e45a5ab8519ec751.tar.gz dotty-1e2bbb2c0bc7c9ba4bb626d4e45a5ab8519ec751.tar.bz2 dotty-1e2bbb2c0bc7c9ba4bb626d4e45a5ab8519ec751.zip |
delegate compilation info to sbt reporter
Diffstat (limited to 'bridge/src/main/scala/xsbt/DelegatingReporter.scala')
-rw-r--r-- | bridge/src/main/scala/xsbt/DelegatingReporter.scala | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/bridge/src/main/scala/xsbt/DelegatingReporter.scala b/bridge/src/main/scala/xsbt/DelegatingReporter.scala new file mode 100644 index 000000000..726570d71 --- /dev/null +++ b/bridge/src/main/scala/xsbt/DelegatingReporter.scala @@ -0,0 +1,58 @@ +/* sbt -- Simple Build Tool + * Copyright 2008, 2009 Mark Harrah + */ +package xsbt + +import dotty.tools._ +import dotc._ +import reporting._ +import core.Contexts._ + +import xsbti.{Maybe, Position} + +final class DelegatingReporter(delegate: xsbti.Reporter) extends Reporter + with UniqueMessagePositions + with HideNonSensicalMessages { + + override def printSummary(implicit ctx: Context): Unit = delegate.printSummary() + + def doReport(d: Diagnostic)(implicit ctx: Context): Unit = { + val severity = + d match { + case _: Reporter.Error => xsbti.Severity.Error + case _: Reporter.Warning => xsbti.Severity.Warn + case _ => xsbti.Severity.Info + } + val pos = + if (d.pos.exists) Some(d.pos) + else None + + val file = + if (d.pos.source.file.exists) Option(d.pos.source.file.file) + else None + + val offset0 = pos.map(_.point) + + val position = new Position { + def line: Maybe[Integer] = maybe(pos.map(_.line)) + def lineContent: String = pos.map(_.lineContent).getOrElse("") + def offset: Maybe[Integer] = maybeInt(offset0) + def pointer: Maybe[Integer] = offset + def pointerSpace: Maybe[String] = maybe(offset0.map(" " * _)) + def sourceFile: Maybe[java.io.File] = maybe(file) + def sourcePath: Maybe[String] = maybe(file.map(_.getPath)) + } + + delegate.log(position, d.message, severity) + } + + private[this] def maybe[T](opt: Option[T]): Maybe[T] = opt match { + case None => Maybe.nothing[T] + case Some(s) => Maybe.just[T](s) + } + import java.lang.{ Integer => I } + private[this] def maybeInt(opt: Option[Int]): Maybe[I] = opt match { + case None => Maybe.nothing[I] + case Some(s) => Maybe.just[I](s) + } +}
\ No newline at end of file |