libraryDependencies += "org.scala-lang" %% "scala3-tasty-inspector" % scalaVersion.value
TASTy files contain the full typed tree of a class including source positions and documentation. This is ideal for tools that analyze or extract semantic information from the code. To avoid the hassle of working directly with the TASTy file we provide the
TastyInspector which loads the contents and exposes it through the TASTy reflect API.
To inspect the trees of a TASTy file a consumer can be defined in the following way.
import scala.quoted._ import scala.tasty.inspector._ class MyInspector extends TastyInspector: protected def processCompilationUnit(using Quotes)(tree: quotes.reflect.Tree): Unit = import quotes.reflect._ // Do something with the tree
Then the consumer can be instantiated with the following code to get the tree of the
object Test: def main(args: Array[String]): Unit = new MyInspector().inspectTastyFiles("foo/Bar.tasty")
Note that if we need to run the main (in the example below defined in an object called
Test) after compilation we need to make the compiler available to the runtime:
scalac -d out Test.scala scala -with-compiler -classpath out Test
Using sbt version
sbt new scala/scala3-tasty-inspector.g8
in the folder where you want to clone the template.