File tree Expand file tree Collapse file tree 5 files changed +31
-0
lines changed
compiler/src/dotty/tools/dotc/tastyreflect Expand file tree Collapse file tree 5 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,12 @@ object TastyImpl extends scala.tasty.Tasty {
41
41
42
42
def ContextDeco (ctx : Context ): AbstractContext = new AbstractContext {
43
43
def owner : Definition = FromSymbol .definition(ctx.owner)(ctx)
44
+
45
+ def source : String = {
46
+ val thisPath = java.nio.file.Paths .get(" " ).toAbsolutePath
47
+ val path = ctx.compilationUnit.source.file.jpath.toAbsolutePath
48
+ thisPath.relativize(path).toString
49
+ }
44
50
}
45
51
46
52
// ===== Id =======================================================
Original file line number Diff line number Diff line change @@ -31,6 +31,9 @@ abstract class Tasty { tasty =>
31
31
32
32
trait AbstractContext {
33
33
def owner : Definition
34
+
35
+ /** Returns the source file being compiled. The path is relative to the current working directory. */
36
+ def source : String
34
37
}
35
38
implicit def ContextDeco (ctx : Context ): AbstractContext
36
39
Original file line number Diff line number Diff line change
1
+ tests/run/tasty-getfile/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.toExpr
13
+ }
14
+
15
+ }
You can’t perform that action at this time.
0 commit comments