Permalink
Browse files

prototype code for Scala 2.13.0-M5

  • Loading branch information...
magnolia-k committed Oct 1, 2018
1 parent 299a179 commit d4d4f5e5e63bfa5ee6950d803d0175cf278bfb02
Showing with 19 additions and 11 deletions.
  1. +19 −11 scalate-core/src/main/scala/org/fusesource/scalate/support/ScalaCompiler.scala
@@ -23,10 +23,12 @@ import org.fusesource.scalate._
import org.fusesource.scalate.util.{ ClassPathBuilder, Log }
import scala.reflect.internal.util.{ FakePos, NoPosition, Position }
import scala.reflect.internal.Reporter
import scala.runtime.ByteRef
import scala.tools.nsc.{ Global, Settings }
import scala.tools.nsc.reporters.{ ConsoleReporter, Reporter }
import scala.tools.nsc.reporters.{ ConsoleReporter, DisplayReporter }
import scala.util.parsing.input.OffsetPosition
import Position.formatMessage
object ScalaCompiler extends Log {
@@ -62,18 +64,24 @@ class ScalaCompiler(
super.reset()
}
override def printMessage(posIn: Position, msg: String): Unit = {
val pos = if (posIn eq null) NoPosition
else if (posIn.isDefined) posIn.finalPosition
else posIn
pos match {
case FakePos(fmsg) => super.printMessage(posIn, msg);
case NoPosition => super.printMessage(posIn, msg);
override def display(pos: Position, msg: String, severity: Severity): Unit = {
val p = if (pos eq null) NoPosition
else if (pos.isDefined) pos.finalPosition
else pos
p match {
case FakePos(fmsg) => super.display(pos, msg, severity)
case NoPosition => super.display(pos, msg, severity);
case _ =>
compilerErrors ::= CompilerError(posIn.source.file.file.getPath, msg, OffsetPosition(posIn.source.content, posIn.point))
super.printMessage(posIn, msg);
val text = formatMessage(pos, s"${clabel(severity)}${DisplayReporter.explanation(msg)}", false)
compilerErrors ::= CompilerError(pos.source.file.file.getPath, text, OffsetPosition(pos.source.content, pos.point))
super.display(pos, msg, severity);
}
}
private def clabel(severity: Severity): String = severity match {
case ERROR => "error: "
case WARNING => "warning: "
case _ => ""
}
}
@@ -90,7 +98,7 @@ class ScalaCompiler(
// Bail out if compilation failed
if (reporter.hasErrors) {
reporter.printSummary()
reporter.finish()
throw new CompilerException("Compilation failed:\n" + reporter.messages, reporter.compilerErrors)
}
}

0 comments on commit d4d4f5e

Please sign in to comment.