summaryrefslogtreecommitdiff
path: root/src/compiler/scala/reflect/macros/runtime/Settings.scala
blob: e9d9a17b8180547f34621abd803e0b18abf1e5af (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package scala.reflect.macros
package runtime

trait Settings {
  self: Context =>

  def settings: List[String] = {
    val us = universe.settings
    import us._
    userSetSettings collectFirst { case x: MultiStringSetting if x.name == XmacroSettings.name => x.value } getOrElse Nil
  }

  def compilerSettings: List[String] = universe.settings.recreateArgs

  def setCompilerSettings(options: String): this.type =
    // SI-5925: doesn't work with arguments that contains whitespaces
    setCompilerSettings(options.split(" ").toList)

  def setCompilerSettings(options: List[String]): this.type = {
    val settings = new scala.tools.nsc.Settings(_ => ())
    settings.copyInto(universe.settings)
    this
  }

  def withCompilerSettings[T](options: String)(op: => T): T =
    // SI-5925: doesn't work with arguments that contains whitespaces
    withCompilerSettings(options.split(" ").toList)(op)

  def withCompilerSettings[T](options: List[String])(op: => T): T = {
    val old = options
    setCompilerSettings(options)
    try op
    finally setCompilerSettings(old)
  }
}