当前位置: 首页>>代码示例>>Scala>>正文


Scala Position类代码示例

本文整理汇总了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()
  }

} 
开发者ID:lmd1993,项目名称:bigsiftParallel,代码行数:41,代码来源:SparkReplReporter.scala

示例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)
    }
  }
} 
开发者ID:cornerman,项目名称:macroni,代码行数:50,代码来源:Compiler.scala

示例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))
} 
开发者ID:maqicode,项目名称:unplugged,代码行数:30,代码来源:unreporter.scala


注:本文中的scala.reflect.internal.util.Position类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。