本文整理汇总了Scala中scala.reflect.internal.util.Position类的典型用法代码示例。如果您正苦于以下问题:Scala Position类的具体用法?Scala Position怎么用?Scala Position使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Position类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: truncationOK
//设置package包名称以及导入依赖的类
package scala.tools.nsc
package interpreter
import reporters._
import SparkIMain._
import scala.reflect.internal.util.Position
private var _truncationOK: Boolean = !intp.settings.verbose
def truncationOK = _truncationOK
def withoutTruncating[T](body: => T): T = {
val saved = _truncationOK
_truncationOK = false
try body
finally _truncationOK = saved
}
override def warning(pos: Position, msg: String): Unit = withoutTruncating(super.warning(pos, msg))
override def error(pos: Position, msg: String): Unit = withoutTruncating(super.error(pos, msg))
override def printMessage(msg: String) {
// Avoiding deadlock if the compiler starts logging before
// the lazy val is complete.
if (intp.isInitializeComplete) {
if (intp.totalSilence) {
if (isReplTrace)
super.printMessage("[silent] " + msg)
}
else super.printMessage(msg)
}
else Console.println("[init] " + msg)
}
override def displayPrompt() {
if (intp.totalSilence) ()
else super.displayPrompt()
}
}
示例2: log
//设置package包名称以及导入依赖的类
package macroni.compiler
import scala.reflect.internal.util.Position
import scala.reflect.runtime.currentMirror
import scala.reflect.runtime.universe.Tree
import scala.tools.reflect.{FrontEnd, ToolBox}
import scala.util.{Try, Success, Failure}
import scala.collection.mutable
import macroni.macros.CompilerSettings
//TODO: needed because FrontEnd stores `infos` in a LinkedHashSet.
// Thus, messages with the same hashcode are lost. This can happen
// in quasiquotes, where the position may be NoPosition.
trait InfoListFrontEnd extends FrontEnd {
val infoList = new mutable.ArrayBuffer[Info]
override def log(pos: Position, msg: String, severity: Severity) {
super.log(pos, msg, severity)
infoList += Info(pos, msg, severity)
}
override def reset() {
super.reset()
infoList.clear()
}
}
class SilentReporter extends InfoListFrontEnd {
def display(info: Info) {}
def interactive() {}
}
object Config {
val compilerPlugins = CompilerSettings().filter(_.startsWith("-Xplugin")).mkString(" ")
val options = compilerPlugins
}
object Compiler {
def apply(tree: Tree): CompileResult = {
val reporter = new SilentReporter
val toolbox = currentMirror.mkToolBox(reporter, Config.options)
Try(toolbox.typecheck(tree)) match {
case Success(typedTree) => CompileResult(tree, toolbox.untypecheck(typedTree), reporter)
case Failure(e) => CompileResult(tree, e, reporter)
}
}
}
示例3: Unreporter
//设置package包名称以及导入依赖的类
package com.github.maqicode.unreporter
import scala.tools.nsc.reporters.{ConsoleReporter, StoreReporter}
import scala.tools.nsc.Settings
import scala.reflect.internal.Reporter
import scala.reflect.internal.util.Position
import scala.collection.mutable
class Unreporter(settings: Settings) extends StoreReporter {
val delegate = new ConsoleReporter(settings)
val suppressions = new mutable.LinkedHashSet[Position]
def suppress(position: Position) = suppressions += position
def unsuppressed: Set[Info] = (infos filter (info => !suppressions(info.pos))).to[Set]
override def finish(): Unit = unsuppressed foreach forward
def forward(info: Info) = info.severity match {
case INFO => delegate.echo(info.pos, info.msg)
case WARNING => delegate.warning(info.pos, info.msg)
case ERROR => delegate.error(info.pos, info.msg)
case _ => ()
}
override def count(severity: Severity): Int = unsuppressed.count(_.severity == severity)
}
object Unreporter {
//def apply(settings: Settings) = new Unreporter(new ConsoleReporter(settings))
}