本文整理汇总了Scala中scala.tools.nsc.Settings类的典型用法代码示例。如果您正苦于以下问题:Scala Settings类的具体用法?Scala Settings怎么用?Scala Settings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Settings类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: ScalaInterpreter
//设置package包名称以及导入依赖的类
package com.outr.uberterm.interpreter
import scala.reflect.ClassTag
import scala.reflect.runtime.{universe => ru}
import scala.tools.nsc.Settings
import scala.tools.nsc.interpreter.{IMain, NamedParam}
class ScalaInterpreter {
private val returnValue = new ThreadLocal[Any]
private val settings = new Settings()
settings.usejavacp.value = true
settings.deprecation.value = true
settings.embeddedDefaults[ScalaInterpreter]
private val i = new IMain(settings)
i.bind[ThreadLocal[Any]]("returnValue", returnValue)
object eval {
def apply(code: String): Any = {
returnValue.remove()
i.interpret(
s"""
|try {
| returnValue.asInstanceOf[ThreadLocal[Any]].set($code)
|} catch {
| case t: Throwable => returnValue.asInstanceOf[ThreadLocal[Any]].set(t)
|}
""".stripMargin)
returnValue.get() match {
case t: Throwable => throw t
case v => v
}
}
def typed[T](code: String): T = apply(code).asInstanceOf[T]
}
def bind(name: String, value: Any): Unit = i.bind(NamedParam.clazz(name, value))
// def bind[T: ru.TypeTag : ClassTag](name: String, value: T): Unit = i.bind(name, value)
}
开发者ID:outr,项目名称:uberterm,代码行数:39,代码来源:ScalaInterpreter.scala
示例2: 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
示例3: Holder
//设置package包名称以及导入依赖的类
package foo.bar
class Holder { var value: Any = _ }
import scala.tools.nsc.{Interpreter, Settings}
class Foo {
val settings = new Settings()
settings.classpath.value = sbt.FileUtilities.classLocationFile[Holder].getAbsolutePath
val inter = new Interpreter(settings)
def eval(code: String): Any = {
val h = new Holder
inter.bind("$r_", h.getClass.getName, h)
val r = inter.interpret("$r_.value = " + code)
h.value
}
}
object Test
{
def main(args: Array[String])
{
val foo = new Foo
foo.eval("3")
}
}
开发者ID:TomasPleml,项目名称:simple-build-tool,代码行数:28,代码来源:Foo.scala
示例4: Interpreter
//设置package包名称以及导入依赖的类
package com.outr.pmc.repl
import com.outr.pmc.Project
import scala.tools.nsc.Settings
import scala.tools.nsc.interpreter.ILoop
class Interpreter(project: Project) {
val repl = new ILoop {
override def prompt: String = "pmc> "
override def createInterpreter(): Unit = {
super.createInterpreter()
intp.beQuietDuring {
project.init(intp)
}
}
}
repl.process(new Settings {
usejavacp.value = true
deprecation.value = true
})
}
开发者ID:outr,项目名称:pmc,代码行数:25,代码来源:Interpreter.scala
示例5: ScalacCompiler
//设置package包名称以及导入依赖的类
package com.outr.pmc.build.compile
import java.io.File
import com.outr.pmc
import com.outr.pmc.build.compile
import scala.tools.nsc.{Global, Settings}
class ScalacCompiler(implicit val project: pmc.Project) extends compile.Compiler {
def exec(dependencies: => List[File] = jarDependencies.get,
outputDirectory: => File = this.outputDirectory.get): Unit = {
val s = new Settings()
s.bootclasspath.append(dependencies.map(_.getAbsolutePath).mkString(":"))
val out = outputDirectory
out.mkdirs()
s.outdir.value = out.getAbsolutePath
val g = new Global(s)
val run = new g.Run
val sourceFiles = Compiler.findInputFiles(inputDirectories.get).map(_.getAbsolutePath)
logger.info(s"Compiling ${sourceFiles.length} files (${sourceFiles.mkString(", ")}).")
run.compile(sourceFiles)
}
override protected def run(): Unit = exec()
}
开发者ID:outr,项目名称:pmc,代码行数:27,代码来源:ScalacCompiler.scala
注:本文中的scala.tools.nsc.Settings类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论