Skip to content

Commit 4b5c497

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

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
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 & 11 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
*
@@ -72,26 +83,26 @@ trait TastyInspector:
7283

7384
private def inspectorDriver() =
7485
class InspectorDriver extends Driver:
75-
override protected def newCompiler(implicit ctx: Context): Compiler = new TastyFromClass
86+
override protected def newCompiler(implicit ctx: Context): Compiler =
87+
val visitor = tastyVisitor(using QuotesImpl())
88+
new TastyFromClass(visitor)
7689

77-
class TastyInspectorPhase extends Phase:
90+
class TastyInspectorPhase(visitor: TastyVisitor) extends Phase:
7891
override def phaseName: String = "tastyInspector"
7992

8093
override def run(implicit ctx: Context): Unit =
81-
val qctx = QuotesImpl()
82-
self.processCompilationUnit(using qctx)(ctx.compilationUnit.tpdTree.asInstanceOf[qctx.reflect.Tree])
94+
visitor.processCompilationUnit(ctx.compilationUnit.tpdTree.asInstanceOf[visitor.quotes.reflect.Tree])
8395

84-
class TastyInspectorFinishPhase extends Phase:
96+
class TastyInspectorFinishPhase(visitor: TastyVisitor) extends Phase:
8597
override def phaseName: String = "tastyInspectorFinish"
8698

8799
override def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] =
88-
val qctx = QuotesImpl()
89-
self.postProcess(using qctx)
100+
visitor.postProcess()
90101
units
91102

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

94-
class TastyFromClass extends TASTYCompiler:
105+
class TastyFromClass(visitor: TastyVisitor) extends TASTYCompiler:
95106

96107
override protected def frontendPhases: List[List[Phase]] =
97108
List(new ReadTasty) :: // Load classes from tasty
@@ -102,8 +113,8 @@ trait TastyInspector:
102113
override protected def transformPhases: List[List[Phase]] = Nil
103114

104115
override protected def backendPhases: List[List[Phase]] =
105-
List(new TastyInspectorPhase) :: // Perform a callback for each compilation unit
106-
List(new TastyInspectorFinishPhase) :: // Perform a final callback
116+
List(new TastyInspectorPhase(visitor)) :: // Perform a callback for each compilation unit
117+
List(new TastyInspectorFinishPhase(visitor)) :: // Perform a final callback
107118
Nil
108119

109120
override def newRun(implicit ctx: Context): Run =

0 commit comments

Comments
 (0)