@@ -20,7 +20,7 @@ guarantees and may fail at macro expansion time, hence additional explicit
2020checks must be done.
2121
2222To provide reflection capabilities in macros we need to add an implicit
23- parameter of type ` scala.tasty.Reflection ` and import it in the scope where it
23+ parameter of type ` scala.quoted.QuoteContext ` and import ` tasty._ ` from it in the scope where it
2424is used.
2525
2626``` scala
@@ -29,23 +29,23 @@ import scala.tasty._
2929
3030inline def natConst (x : => Int ): Int = $ {natConstImpl(' {x})}
3131
32- def natConstImpl (x : Expr [Int ])( implicit reflection : Reflection ): Expr [Int ] = {
33- import reflection ._
32+ def natConstImpl (x : Expr [Int ]) given ( qctx : QuoteContext ): Expr [Int ] = {
33+ import qctx . tasty ._
3434 ...
3535}
3636```
3737
3838### Sealing and Unsealing
3939
40- ` import reflection ._ ` will provide an ` unseal ` extension method on ` quoted.Expr `
41- and ` quoted.Type ` which returns a ` reflection .Term` that represents the tree of
42- the expression and ` reflection .TypeTree` that represents the tree of the type
40+ ` import qctx.tasty ._ ` will provide an ` unseal ` extension method on ` quoted.Expr `
41+ and ` quoted.Type ` which returns a ` qctx.tasty .Term` that represents the tree of
42+ the expression and ` qctx.tasty .TypeTree` that represents the tree of the type
4343respectively. It will also import all extractors and methods on TASTy Reflect
4444trees. For example the ` Literal(_) ` extractor used below.
4545
4646``` scala
47- def natConstImpl (x : Expr [Int ])( implicit reflection : Reflection ): Expr [Int ] = {
48- import reflection ._
47+ def natConstImpl (x : Expr [Int ]) given ( qctx : QuoteContext ): Expr [Int ] = {
48+ import qctx . tasty ._
4949 val xTree : Term = x.unseal
5050 xTree match {
5151 case Term .Literal (Constant .Int (n)) =>
@@ -58,10 +58,10 @@ def natConstImpl(x: Expr[Int])(implicit reflection: Reflection): Expr[Int] = {
5858}
5959```
6060
61- To easily know which extractors are needed, the ` reflection .Term.show` method
61+ To easily know which extractors are needed, the ` qctx.tasty .Term.show` method
6262returns the string representation of the extractors.
6363
64- The method ` reflection .Term.seal[T]` provides a way to go back to a
64+ The method ` qctx.tasty .Term.seal[T]` provides a way to go back to a
6565` quoted.Expr[Any] ` . Note that the type is ` Expr[Any] ` . Consequently, the type
6666must be set explicitly with a checked ` cast ` call. If the type does not conform
6767to it an exception will be thrown. In the code above, we could have replaced
@@ -77,8 +77,8 @@ operation expression passed while calling the `macro` below.
7777``` scala
7878inline def macro (param : => Boolean ): Unit = $ { macroImpl(' param ) }
7979
80- def macroImpl (param : Expr [Boolean ])( implicit refl : Reflection ): Expr [Unit ] = {
81- import refl ._
80+ def macroImpl (param : Expr [Boolean ]) given ( qctx : QuoteContext ): Expr [Unit ] = {
81+ import qctx . tasty ._
8282 import util ._
8383
8484 param.unseal.underlyingArgument match {
@@ -99,8 +99,8 @@ such as the start line, the end line or even the source code at the expansion
9999point.
100100
101101``` scala
102- def macroImpl ()(reflect : Reflection ): Expr [Unit ] = {
103- import reflect .{ Position => _ , _ }
102+ def macroImpl ()(qctx : QuoteContext ): Expr [Unit ] = {
103+ import qctx . tasty . _
104104 val pos = rootPosition
105105
106106 val path = pos.sourceFile.jpath.toString
0 commit comments