summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/reflect/package.scala
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2012-09-26 07:43:48 +0200
committerEugene Burmako <xeno.by@gmail.com>2012-09-27 15:49:01 +0200
commitca9d2149e964604daf3a8d88d6946217ef90c643 (patch)
tree0d285f2f1a28382be9a43cddd8d148a73b7422f5 /src/compiler/scala/tools/reflect/package.scala
parent7911f9e85b3798d449d6b551d7c8be15cc63f240 (diff)
downloadscala-ca9d2149e964604daf3a8d88d6946217ef90c643.tar.gz
scala-ca9d2149e964604daf3a8d88d6946217ef90c643.tar.bz2
scala-ca9d2149e964604daf3a8d88d6946217ef90c643.zip
removes front ends from scala-reflect.jar
It was an interesting idea to give macro developers control over front ends, but it hasn't given any visible results. To the contrast, front ends have proven useful for toolboxes to easily control what errors get printed where. Therefore I'm moving front ends to scala-compiler.jar to clean up the API. Yay for scaladoc-driven development!
Diffstat (limited to 'src/compiler/scala/tools/reflect/package.scala')
-rw-r--r--src/compiler/scala/tools/reflect/package.scala90
1 files changed, 88 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/reflect/package.scala b/src/compiler/scala/tools/reflect/package.scala
index 901071d91a..8a1e3628e2 100644
--- a/src/compiler/scala/tools/reflect/package.scala
+++ b/src/compiler/scala/tools/reflect/package.scala
@@ -6,9 +6,12 @@
package scala.tools
import scala.reflect.api.JavaUniverse
+import scala.reflect.internal.util.Position
import scala.language.implicitConversions
+import scala.tools.nsc.reporters._
+import scala.tools.nsc.Settings
-package object reflect extends FrontEnds {
+package object reflect {
// [todo: can we generalize this?
import scala.reflect.runtime.{universe => ru}
implicit def ToolBox(mirror0: ru.Mirror): ToolBoxFactory[ru.type] =
@@ -17,9 +20,92 @@ package object reflect extends FrontEnds {
}
// todo. replace this with an implicit class, once the pesky warning is gone
+ // we don't provide `Eval` for trees, because it's unclear where to get an evaluation mirror from
implicit def Eval[T](expr: JavaUniverse # Expr[T]): Eval[T] = new Eval[T](expr)
- // we don't provide `Eval` for trees, because it's unclear where to get an evaluation mirror from
+ /** Creates a UI-less reporter that simply accumulates all the messages
+ */
+ def mkSilentFrontEnd(): FrontEnd = new FrontEnd {
+ def display(info: Info) {}
+ def interactive() {}
+ }
+
+ /** Creates a reporter that prints messages to the console according to the settings.
+ *
+ * ``minSeverity'' determines minimum severity of the messages to be printed.
+ * 0 stands for INFO, 1 stands for WARNING and 2 stands for ERROR.
+ */
+ // todo. untangle warningsAsErrors from Reporters. I don't feel like moving this flag here!
+ def mkConsoleFrontEnd(minSeverity: Int = 1): FrontEnd = {
+ val settings = new Settings()
+ if (minSeverity <= 0) settings.verbose.value = true
+ if (minSeverity > 1) settings.nowarn.value = true
+ reporterToFrontEnd(new ConsoleReporter(settings))
+ }
+
+ private[reflect] def reporterToFrontEnd(reporter: Reporter): FrontEnd = new FrontEnd {
+ val API_INFO = INFO
+ val API_WARNING = WARNING
+ val API_ERROR = ERROR
+
+ override def hasErrors = reporter.hasErrors
+ override def hasWarnings = reporter.hasWarnings
+
+ def display(info: Info): Unit = info.severity match {
+ case API_INFO => reporter.info(info.pos, info.msg, false)
+ case API_WARNING => reporter.warning(info.pos, info.msg)
+ case API_ERROR => reporter.error(info.pos, info.msg)
+ }
+
+ def interactive(): Unit = reporter match {
+ case reporter: AbstractReporter => reporter.displayPrompt()
+ case _ => // do nothing
+ }
+
+ override def flush(): Unit = {
+ super.flush()
+ reporter.flush()
+ }
+
+ override def reset(): Unit = {
+ super.reset()
+ reporter.reset()
+ }
+ }
+
+ private[reflect] def frontEndToReporter(frontEnd: FrontEnd, settings0: Settings): Reporter = new AbstractReporter {
+ val settings = settings0
+
+ import frontEnd.{Severity => ApiSeverity}
+ val API_INFO = frontEnd.INFO
+ val API_WARNING = frontEnd.WARNING
+ val API_ERROR = frontEnd.ERROR
+
+ type NscSeverity = Severity
+ val NSC_INFO = INFO
+ val NSC_WARNING = WARNING
+ val NSC_ERROR = ERROR
+
+ def display(pos: Position, msg: String, nscSeverity: NscSeverity): Unit =
+ frontEnd.log(pos, msg, nscSeverity match {
+ case NSC_INFO => API_INFO
+ case NSC_WARNING => API_WARNING
+ case NSC_ERROR => API_ERROR
+ })
+
+ def displayPrompt(): Unit =
+ frontEnd.interactive()
+
+ override def flush(): Unit = {
+ super.flush()
+ frontEnd.flush()
+ }
+
+ override def reset(): Unit = {
+ super.reset()
+ frontEnd.reset()
+ }
+ }
}
package reflect {