Skip to content

Commit 72c3635

Browse files
committed
Use QuoteContext in TastyInspector
* Align API with other metaprogramming APIs * Allow use of extractors from `scala.quoted` and quoted pattern * Enable use of `Reflection.typeOf`
1 parent a036b70 commit 72c3635

File tree

12 files changed

+50
-53
lines changed

12 files changed

+50
-53
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package scala.tasty.inspector
22

3-
import scala.tasty.Reflection
3+
import scala.quoted._
44

55
import dotty.tools.dotc.Compiler
66
import dotty.tools.dotc.Driver
@@ -18,7 +18,7 @@ trait TastyInspector:
1818
self =>
1919

2020
/** Process a TASTy file using TASTy reflect */
21-
protected def processCompilationUnit(reflect: Reflection)(root: reflect.Tree): Unit
21+
protected def processCompilationUnit(using QuoteContext)(root: qctx.tasty.Tree): Unit
2222

2323
/** Load and process TASTy files using TASTy reflect
2424
*
@@ -58,7 +58,7 @@ trait TastyInspector:
5858

5959
override def run(implicit ctx: Context): Unit =
6060
val qctx = QuoteContextImpl()
61-
self.processCompilationUnit(qctx.tasty)(ctx.compilationUnit.tpdTree.asInstanceOf[qctx.tasty.Tree])
61+
self.processCompilationUnit(using qctx)(ctx.compilationUnit.tpdTree.asInstanceOf[qctx.tasty.Tree])
6262

6363
end TastyInspectorPhase
6464

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package dotty.tastydoc
22

3-
import scala.tasty.Reflection
3+
import scala.quoted._
44
import scala.tasty.inspector.TastyInspector
55

66
import dotty.tastydoc.representations._
@@ -11,9 +11,7 @@ import dotty.tastydoc.representations._
1111
*/
1212
class TastydocInspector(mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends TastyInspector {
1313

14-
protected def processCompilationUnit(reflect: Reflection)(root: reflect.Tree): Unit = {
15-
import reflect._
16-
17-
representations.convertToRepresentation(reflect)(root, None)(using mutablePackagesMap)
14+
protected def processCompilationUnit(using QuoteContext)(root: qctx.tasty.Tree): Unit = {
15+
representations.convertToRepresentation(qctx.tasty)(root, None)(using mutablePackagesMap)
1816
}
1917
}

tastydoc/src/dotty/tastydoc/representations.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import scala.annotation.tailrec
55
import dotty.tastydoc.comment.Comment
66
import dotty.tastydoc.references._
77

8+
// TODO pass QuoteContext around insead of Reflection
9+
810
object representations extends TastyExtractor {
911

1012
trait Representation {

tests/run-custom-args/tasty-inspector/i8163.scala

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.tasty.Reflection
1+
import scala.quoted._
22
import scala.tasty.inspector._
33

44
opaque type PhoneNumber = String
@@ -16,16 +16,15 @@ object Test {
1616

1717
class TestInspector() extends TastyInspector:
1818

19-
protected def processCompilationUnit(reflect: Reflection)(root: reflect.Tree): Unit =
20-
import reflect._
21-
inspectClass(reflect)(root)
19+
protected def processCompilationUnit(using QuoteContext)(root: qctx.tasty.Tree): Unit =
20+
inspectClass(root)
2221

23-
private def inspectClass(reflect: Reflection)(tree: reflect.Tree): Unit =
24-
import reflect.{given _, _}
22+
private def inspectClass(using QuoteContext)(tree: qctx.tasty.Tree): Unit =
23+
import qctx.tasty._
2524
tree match {
26-
case t: reflect.PackageClause =>
27-
t.stats.map( m => inspectClass(reflect)(m) )
28-
case t: reflect.ClassDef if !t.name.endsWith("$") =>
25+
case t: PackageClause =>
26+
t.stats.map( m => inspectClass(m) )
27+
case t: ClassDef if !t.name.endsWith("$") =>
2928
val interestingVals = t.body.collect {
3029
case v: ValDef => v
3130
}

tests/run-custom-args/tasty-inspector/i8215.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.tasty.Reflection
1+
import scala.quoted._
22
import scala.tasty.inspector._
33

44
case class I8215(id: String)
@@ -35,7 +35,7 @@ class TestInspector_NonTasty() extends TastyInspector:
3535
var isScala2: Boolean = false
3636
var className: String = ""
3737

38-
protected def processCompilationUnit(reflect: Reflection)(root: reflect.Tree): Unit =
39-
isJava = reflect.Source.isJavaCompilationUnit
40-
isScala2 = reflect.Source.isScala2CompilationUnit
41-
className = reflect.Source.compilationUnitClassname
38+
protected def processCompilationUnit(using QuoteContext)(root: qctx.tasty.Tree): Unit =
39+
isJava = qctx.tasty.Source.isJavaCompilationUnit
40+
isScala2 = qctx.tasty.Source.isScala2CompilationUnit
41+
className = qctx.tasty.Source.compilationUnitClassname

tests/run-custom-args/tasty-inspector/i8364.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import scala.tasty._
1+
import scala.quoted._
22
import scala.tasty.inspector._
33

44
@main def Test = {
55
val inspector = new TastyInspector {
6-
def processCompilationUnit(reflect: Reflection)(tree: reflect.Tree): Unit = {
7-
import reflect.{_, given _}
6+
protected def processCompilationUnit(using QuoteContext)(tree: qctx.tasty.Tree): Unit = {
87
println(tree.show)
98
}
109
}

tests/run-custom-args/tasty-inspector/i8389.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import scala.tasty._
1+
import scala.quoted._
22
import scala.tasty.inspector._
33

44
@main def Test = {
55
// in dotty-example-project
66
val inspector = new TastyInspector {
7-
def processCompilationUnit(reflect: Reflection)(tree: reflect.Tree): Unit = {
8-
import reflect.{_, given _}
7+
protected def processCompilationUnit(using QuoteContext)(tree: qctx.tasty.Tree): Unit = {
98
println(tree.show)
109
}
1110
}

tests/run-custom-args/tasty-inspector/i8460.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.tasty.Reflection
1+
import scala.quoted._
22
import scala.tasty.inspector._
33

44
// Ambiguous member names
@@ -32,16 +32,16 @@ class TestInspector_Children() extends TastyInspector:
3232

3333
var kids: List[String] = Nil
3434

35-
protected def processCompilationUnit(reflect: Reflection)(root: reflect.Tree): Unit =
36-
import reflect._
37-
inspectClass(reflect)(root)
35+
protected def processCompilationUnit(using QuoteContext)(root: qctx.tasty.Tree): Unit =
36+
import qctx.tasty._
37+
inspectClass(root)
3838

39-
private def inspectClass(reflect: Reflection)(tree: reflect.Tree): Unit =
40-
import reflect.{given _, _}
39+
private def inspectClass(using QuoteContext)(tree: qctx.tasty.Tree): Unit =
40+
import qctx.tasty._
4141
tree match {
42-
case t: reflect.PackageClause =>
43-
t.stats.map( m => inspectClass(reflect)(m) )
44-
case t: reflect.ClassDef =>
42+
case t: PackageClause =>
43+
t.stats.map( m => inspectClass(m) )
44+
case t: ClassDef =>
4545
kids = t.symbol.children.map(_.fullName)
4646

4747
case x =>

tests/run-custom-args/tasty-inspector/i8558.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.tasty.Reflection
1+
import scala.quoted._
22
import scala.tasty.inspector._
33

44
object Test {
@@ -17,6 +17,6 @@ class TestInspector_NonTasty() extends TastyInspector:
1717
var isAlreadyLoaded: Boolean = false
1818
var className: String = ""
1919

20-
protected def processCompilationUnit(reflect: Reflection)(root: reflect.Tree): Unit =
21-
isAlreadyLoaded = reflect.Source.isAlreadyLoadedCompilationUnit
22-
className = reflect.Source.compilationUnitClassname
20+
protected def processCompilationUnit(using QuoteContext)(root: qctx.tasty.Tree): Unit =
21+
isAlreadyLoaded = qctx.tasty.Source.isAlreadyLoadedCompilationUnit
22+
className = qctx.tasty.Source.compilationUnitClassname

tests/run-custom-args/tasty-inspector/tasty-comment-inspector/Test.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.tasty.Reflection
1+
import scala.quoted._
22
import scala.tasty.inspector._
33

44
object Test {
@@ -9,8 +9,8 @@ object Test {
99

1010
class CommentInspector extends TastyInspector {
1111

12-
def processCompilationUnit(reflect: Reflection)(root: reflect.Tree): Unit = {
13-
import reflect.{_, given _}
12+
protected def processCompilationUnit(using QuoteContext)(root: qctx.tasty.Tree): Unit = {
13+
import qctx.tasty._
1414
object Traverser extends TreeTraverser {
1515

1616
override def traverseTree(tree: Tree)(implicit ctx: Context): Unit = tree match {
@@ -25,7 +25,7 @@ class CommentInspector extends TastyInspector {
2525
}
2626

2727
}
28-
Traverser.traverseTree(root)(reflect.rootContext)
28+
Traverser.traverseTree(root)
2929
}
3030

3131
}

tests/run-custom-args/tasty-inspector/tasty-inspector/Test.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.tasty.Reflection
1+
import scala.quoted._
22
import scala.tasty.inspector._
33

44
object Test {
@@ -9,8 +9,8 @@ object Test {
99

1010
class DBInspector extends TastyInspector {
1111

12-
protected def processCompilationUnit(reflect: Reflection)(root: reflect.Tree): Unit = {
13-
import reflect.{_, given _}
12+
protected def processCompilationUnit(using QuoteContext)(root: qctx.tasty.Tree): Unit = {
13+
import qctx.tasty._
1414
object Traverser extends TreeTraverser {
1515

1616
override def traverseTree(tree: Tree)(implicit ctx: Context): Unit = tree match {
@@ -22,7 +22,7 @@ class DBInspector extends TastyInspector {
2222
}
2323

2424
}
25-
Traverser.traverseTree(root)(reflect.rootContext)
25+
Traverser.traverseTree(root)
2626
}
2727

2828
}

tests/run-custom-args/tasty-interpreter/interpreter/TastyInterpreter.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package scala.tasty.interpreter
22

3-
import scala.tasty.Reflection
3+
import scala.quoted._
44
import scala.tasty.inspector.TastyInspector
55

66
class TastyInterpreter extends TastyInspector {
77

8-
protected def processCompilationUnit(reflect: Reflection)(root: reflect.Tree): Unit = {
9-
import reflect.{_, given _}
8+
protected def processCompilationUnit(using QuoteContext)(root: qctx.tasty.Tree): Unit = {
9+
import qctx.tasty._
1010
object Traverser extends TreeTraverser {
1111

1212
override def traverseTree(tree: Tree)(implicit ctx: Context): Unit = tree match {
@@ -20,6 +20,6 @@ class TastyInterpreter extends TastyInspector {
2020
super.traverseTree(tree)
2121
}
2222
}
23-
Traverser.traverseTree(root)(reflect.rootContext)
23+
Traverser.traverseTree(root)
2424
}
2525
}

0 commit comments

Comments
 (0)