From f5b826f95a18862089cf2f53df0258caa8ac3dd6 Mon Sep 17 00:00:00 2001 From: Aleksander Boruch-Gruszecki Date: Sun, 13 Dec 2020 21:25:18 +0100 Subject: [PATCH] Try to fix paths in TastyInspector --- .../tasty/comments/CommentExpanderTests.scala | 2 +- .../tasty/inspector/TastyInspector.scala | 28 +++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/scala3doc/test/dotty/dokka/tasty/comments/CommentExpanderTests.scala b/scala3doc/test/dotty/dokka/tasty/comments/CommentExpanderTests.scala index d86b3e743c1f..fabb5dca8960 100644 --- a/scala3doc/test/dotty/dokka/tasty/comments/CommentExpanderTests.scala +++ b/scala3doc/test/dotty/dokka/tasty/comments/CommentExpanderTests.scala @@ -42,7 +42,7 @@ class CommentExpanderTests { def processCompilationUnit(using quoted.Quotes)(root: quotes.reflect.Tree): Unit = () - override def postProcess(using quoted.Quotes): Unit = + override def postProcess(using quoted.Quotes)(): Unit = check() Inspector().inspectTastyFiles(TestUtils.listOurClasses()) diff --git a/tasty-inspector/src/scala/tasty/inspector/TastyInspector.scala b/tasty-inspector/src/scala/tasty/inspector/TastyInspector.scala index c6f11e76d177..1abf6c3222c0 100644 --- a/tasty-inspector/src/scala/tasty/inspector/TastyInspector.scala +++ b/tasty-inspector/src/scala/tasty/inspector/TastyInspector.scala @@ -20,11 +20,22 @@ import java.io.File.pathSeparator trait TastyInspector: self => + trait TastyVisitor(using val quotes: Quotes): + def processCompilationUnit(root: quotes.reflect.Tree): Unit + def postProcess(): Unit = () + + protected def tastyVisitor(using q: Quotes): TastyVisitor = new { + def processCompilationUnit(root: quotes.reflect.Tree): Unit = + TastyInspector.this.processCompilationUnit(root) + override def postProcess(): Unit = + TastyInspector.this.postProcess() + } + /** Process a TASTy file using TASTy reflect */ protected def processCompilationUnit(using Quotes)(root: quotes.reflect.Tree): Unit /** Called after all compilation units are processed */ - protected def postProcess(using Quotes): Unit = () + protected def postProcess(using Quotes)(): Unit = () /** Load and process TASTy files using TASTy reflect * @@ -71,22 +82,27 @@ trait TastyInspector: private def inspectorDriver() = + var visitor: TastyVisitor = null class InspectorDriver extends Driver: - override protected def newCompiler(implicit ctx: Context): Compiler = new TastyFromClass + override protected def newCompiler(implicit ctx: Context): Compiler = + new TastyFromClass class TastyInspectorPhase extends Phase: override def phaseName: String = "tastyInspector" + override def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] = + visitor = tastyVisitor(using QuotesImpl()) + super.runOn(units) + override def run(implicit ctx: Context): Unit = - val qctx = QuotesImpl() - self.processCompilationUnit(using qctx)(ctx.compilationUnit.tpdTree.asInstanceOf[qctx.reflect.Tree]) + val v = visitor + v.processCompilationUnit(ctx.compilationUnit.tpdTree.asInstanceOf[v.quotes.reflect.Tree]) class TastyInspectorFinishPhase extends Phase: override def phaseName: String = "tastyInspectorFinish" override def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] = - val qctx = QuotesImpl() - self.postProcess(using qctx) + visitor.postProcess() units override def run(implicit ctx: Context): Unit = unsupported("run")