Skip to content

Commit f5b826f

Browse files
committed
Try to fix paths in TastyInspector
1 parent dbc1186 commit f5b826f

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

scala3doc/test/dotty/dokka/tasty/comments/CommentExpanderTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class CommentExpanderTests {
4242

4343
def processCompilationUnit(using quoted.Quotes)(root: quotes.reflect.Tree): Unit = ()
4444

45-
override def postProcess(using quoted.Quotes): Unit =
45+
override def postProcess(using quoted.Quotes)(): Unit =
4646
check()
4747

4848
Inspector().inspectTastyFiles(TestUtils.listOurClasses())

tasty-inspector/src/scala/tasty/inspector/TastyInspector.scala

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,22 @@ import java.io.File.pathSeparator
2020
trait TastyInspector:
2121
self =>
2222

23+
trait TastyVisitor(using val quotes: Quotes):
24+
def processCompilationUnit(root: quotes.reflect.Tree): Unit
25+
def postProcess(): Unit = ()
26+
27+
protected def tastyVisitor(using q: Quotes): TastyVisitor = new {
28+
def processCompilationUnit(root: quotes.reflect.Tree): Unit =
29+
TastyInspector.this.processCompilationUnit(root)
30+
override def postProcess(): Unit =
31+
TastyInspector.this.postProcess()
32+
}
33+
2334
/** Process a TASTy file using TASTy reflect */
2435
protected def processCompilationUnit(using Quotes)(root: quotes.reflect.Tree): Unit
2536

2637
/** Called after all compilation units are processed */
27-
protected def postProcess(using Quotes): Unit = ()
38+
protected def postProcess(using Quotes)(): Unit = ()
2839

2940
/** Load and process TASTy files using TASTy reflect
3041
*
@@ -71,22 +82,27 @@ trait TastyInspector:
7182

7283

7384
private def inspectorDriver() =
85+
var visitor: TastyVisitor = null
7486
class InspectorDriver extends Driver:
75-
override protected def newCompiler(implicit ctx: Context): Compiler = new TastyFromClass
87+
override protected def newCompiler(implicit ctx: Context): Compiler =
88+
new TastyFromClass
7689

7790
class TastyInspectorPhase extends Phase:
7891
override def phaseName: String = "tastyInspector"
7992

93+
override def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] =
94+
visitor = tastyVisitor(using QuotesImpl())
95+
super.runOn(units)
96+
8097
override def run(implicit ctx: Context): Unit =
81-
val qctx = QuotesImpl()
82-
self.processCompilationUnit(using qctx)(ctx.compilationUnit.tpdTree.asInstanceOf[qctx.reflect.Tree])
98+
val v = visitor
99+
v.processCompilationUnit(ctx.compilationUnit.tpdTree.asInstanceOf[v.quotes.reflect.Tree])
83100

84101
class TastyInspectorFinishPhase extends Phase:
85102
override def phaseName: String = "tastyInspectorFinish"
86103

87104
override def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] =
88-
val qctx = QuotesImpl()
89-
self.postProcess(using qctx)
105+
visitor.postProcess()
90106
units
91107

92108
override def run(implicit ctx: Context): Unit = unsupported("run")

0 commit comments

Comments
 (0)