How to find the name of the enclosing source file in Scala 2.11
问题 At compile time, how to retrieve the name of the current source file (where the code is written) in scala 2.11? 回答1: In the REPL, the name is console, but this shows that a position knows its source. scala> import scala.language.experimental.macros import scala.language.experimental.macros scala> import scala.reflect.macros.whitebox.Context import scala.reflect.macros.whitebox.Context scala> def f(c: Context): c.Tree = { import c._,universe._ ; Literal(Constant(c.enclosingPosition.source.file