File tree Expand file tree Collapse file tree 5 files changed +27
-0
lines changed
compiler/src/dotty/tools/dotc/tastyreflect Expand file tree Collapse file tree 5 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,8 @@ object TastyImpl extends scala.tasty.Tasty {
4141
4242 def ContextDeco (ctx : Context ): ContextAPI = new ContextAPI {
4343 def owner : Definition = FromSymbol .definition(ctx.owner)(ctx)
44+
45+ def source : java.nio.file.Path = ctx.compilationUnit.source.file.jpath
4446 }
4547
4648 // ===== Id =======================================================
Original file line number Diff line number Diff line change @@ -31,6 +31,9 @@ abstract class Tasty { tasty =>
3131
3232 trait ContextAPI {
3333 def owner : Definition
34+
35+ /** Returns the source file being compiled. The path is relative to the current working directory. */
36+ def source : java.nio.file.Path
3437 }
3538 implicit def ContextDeco (ctx : Context ): ContextAPI
3639
Original file line number Diff line number Diff line change 1+ App_2.scala
Original file line number Diff line number Diff line change 1+
2+ object Test {
3+ def main (args : Array [String ]): Unit = {
4+ println(SourceFiles .getThisFile)
5+ }
6+ }
Original file line number Diff line number Diff line change 1+ import scala .quoted ._
2+
3+ import scala .tasty .Universe
4+
5+ object SourceFiles {
6+
7+ implicit inline def getThisFile : String =
8+ ~ getThisFileImpl(Universe .compilationUniverse) // FIXME infer Universe.compilationUniverse within top level ~
9+
10+ private def getThisFileImpl (implicit u : Universe ): Expr [String ] = {
11+ import u .tasty ._
12+ u.context.source.getFileName.toString.toExpr
13+ }
14+
15+ }
You can’t perform that action at this time.
0 commit comments