11package scala .tasty
22package reflect
33
4- class ExtractorsPrinter [R <: Reflection & Singleton ](val reflect : R ) extends Printer [R ] {
5- import reflect ._
4+ import scala .quoted ._
65
7- def showTree (tree : Tree ): String =
8- new Buffer ().visitTree(tree).result()
6+ class ExtractorsPrinter extends Printer {
97
10- def showType ( tpe : TypeRepr ): String =
11- new Buffer ().visitType(tpe ).result()
8+ def showTree ( using QuoteContext )( tree : qctx.reflect. Tree ): String =
9+ new Buffer [qctx. type ] ().visitTree(tree ).result()
1210
13- def showConstant ( const : Constant ): String =
14- new Buffer ().visitConstant(const ).result()
11+ def showType ( using QuoteContext )( tpe : qctx.reflect. TypeRepr ): String =
12+ new Buffer [qctx. type ] ().visitType(tpe ).result()
1513
16- def showSymbol ( symbol : Symbol ): String =
17- new Buffer ().visitSymbol(symbol ).result()
14+ def showConstant ( using QuoteContext )( const : qctx.reflect. Constant ): String =
15+ new Buffer [qctx. type ] ().visitConstant(const ).result()
1816
19- def showFlags (flags : Flags ): String = {
17+ def showSymbol (using QuoteContext )(symbol : qctx.reflect.Symbol ): String =
18+ new Buffer [qctx.type ]().visitSymbol(symbol).result()
19+
20+ def showFlags (using QuoteContext )(flags : qctx.reflect.Flags ): String = {
21+ import qctx .reflect ._
2022 val flagList = List .newBuilder[String ]
2123 if (flags.is(Flags .Abstract )) flagList += " Flags.Abstract"
2224 if (flags.is(Flags .Artifact )) flagList += " Flags.Artifact"
@@ -55,13 +57,14 @@ class ExtractorsPrinter[R <: Reflection & Singleton](val reflect: R) extends Pri
5557 flagList.result().mkString(" | " )
5658 }
5759
58- private class Buffer { self =>
60+ private class Buffer [QCtx <: QuoteContext & Singleton ](using val qctx : QCtx ) { self =>
61+ import qctx .reflect ._
5962
6063 private val sb : StringBuilder = new StringBuilder
6164
6265 def result (): String = sb.result()
6366
64- def visitTree (x : Tree ): Buffer = x match {
67+ def visitTree (x : Tree ): this . type = x match {
6568 case Ident (name) =>
6669 this += " Ident(\" " += name += " \" )"
6770 case Select (qualifier, name) =>
@@ -164,7 +167,7 @@ class ExtractorsPrinter[R <: Reflection & Singleton](val reflect: R) extends Pri
164167 this += " Alternative(" ++= patterns += " )"
165168 }
166169
167- def visitConstant (x : Constant ): Buffer = x match {
170+ def visitConstant (x : Constant ): this . type = x match {
168171 case Constant .Unit () => this += " Constant.Unit()"
169172 case Constant .Null () => this += " Constant.Null()"
170173 case Constant .Boolean (value) => this += " Constant.Boolean(" += value += " )"
@@ -181,7 +184,7 @@ class ExtractorsPrinter[R <: Reflection & Singleton](val reflect: R) extends Pri
181184 visitType(value) += " )"
182185 }
183186
184- def visitType (x : TypeRepr ): Buffer = x match {
187+ def visitType (x : TypeRepr ): this . type = x match {
185188 case ConstantType (value) =>
186189 this += " ConstantType(" += value += " )"
187190 case TermRef (qual, name) =>
@@ -225,71 +228,71 @@ class ExtractorsPrinter[R <: Reflection & Singleton](val reflect: R) extends Pri
225228 this += " NoPrefix()"
226229 }
227230
228- def visitSignature (sig : Signature ): Buffer = {
231+ def visitSignature (sig : Signature ): this . type = {
229232 val Signature (params, res) = sig
230233 this += " Signature(" ++= params.map(_.toString) += " , " += res += " )"
231234 }
232235
233- def visitImportSelector (sel : ImportSelector ): Buffer = sel match {
236+ def visitImportSelector (sel : ImportSelector ): this . type = sel match {
234237 case SimpleSelector (id) => this += " SimpleSelector(" += id += " )"
235238 case RenameSelector (id1, id2) => this += " RenameSelector(" += id1 += " , " += id2 += " )"
236239 case OmitSelector (id) => this += " OmitSelector(" += id += " )"
237240 }
238241
239- def visitSymbol (x : Symbol ): Buffer =
242+ def visitSymbol (x : Symbol ): this . type =
240243 if x.isPackageDef then this += " IsPackageDefSymbol(<" += x.fullName += " >)"
241244 else if x.isClassDef then this += " IsClassDefSymbol(<" += x.fullName += " >)"
242245 else if x.isDefDef then this += " IsDefDefSymbol(<" += x.fullName += " >)"
243246 else if x.isValDef then this += " IsValDefSymbol(<" += x.fullName += " >)"
244247 else if x.isTypeDef then this += " IsTypeDefSymbol(<" += x.fullName += " >)"
245248 else { assert(x.isNoSymbol); this += " NoSymbol()" }
246249
247- def += (x : Boolean ): Buffer = { sb.append(x); this }
248- def += (x : Byte ): Buffer = { sb.append(x); this }
249- def += (x : Short ): Buffer = { sb.append(x); this }
250- def += (x : Int ): Buffer = { sb.append(x); this }
251- def += (x : Long ): Buffer = { sb.append(x); this }
252- def += (x : Float ): Buffer = { sb.append(x); this }
253- def += (x : Double ): Buffer = { sb.append(x); this }
254- def += (x : Char ): Buffer = { sb.append(x); this }
255- def += (x : String ): Buffer = { sb.append(x); this }
250+ def += (x : Boolean ): this . type = { sb.append(x); this }
251+ def += (x : Byte ): this . type = { sb.append(x); this }
252+ def += (x : Short ): this . type = { sb.append(x); this }
253+ def += (x : Int ): this . type = { sb.append(x); this }
254+ def += (x : Long ): this . type = { sb.append(x); this }
255+ def += (x : Float ): this . type = { sb.append(x); this }
256+ def += (x : Double ): this . type = { sb.append(x); this }
257+ def += (x : Char ): this . type = { sb.append(x); this }
258+ def += (x : String ): this . type = { sb.append(x); this }
256259
257- def ++= (xs : List [String ]): Buffer = visitList[String ](xs, += )
260+ def ++= (xs : List [String ]): this . type = visitList[String ](xs, += )
258261
259- private implicit class StringOps (buff : Buffer ) {
260- def += (x : Option [String ]): Buffer = { visitOption(x, y => buff += " \" " += y += " \" " ); buff }
262+ private implicit class StringOps (buff : self. type ) {
263+ def += (x : Option [String ]): self. type = { visitOption(x, y => buff += " \" " += y += " \" " ); buff }
261264 }
262265
263- private implicit class TreeOps (buff : Buffer ) {
264- def += (x : Tree ): Buffer = { visitTree(x); buff }
265- def += (x : Option [Tree ]): Buffer = { visitOption(x, visitTree); buff }
266- def ++= (x : List [Tree ]): Buffer = { visitList(x, visitTree); buff }
267- def +++= (x : List [List [Tree ]]): Buffer = { visitList(x, ++= ); buff }
266+ private implicit class TreeOps (buff : self. type ) {
267+ def += (x : Tree ): self. type = { visitTree(x); buff }
268+ def += (x : Option [Tree ]): self. type = { visitOption(x, visitTree); buff }
269+ def ++= (x : List [Tree ]): self. type = { visitList(x, visitTree); buff }
270+ def +++= (x : List [List [Tree ]]): self. type = { visitList(x, ++= ); buff }
268271 }
269272
270- private implicit class ConstantOps (buff : Buffer ) {
271- def += (x : Constant ): Buffer = { visitConstant(x); buff }
273+ private implicit class ConstantOps (buff : self. type ) {
274+ def += (x : Constant ): self. type = { visitConstant(x); buff }
272275 }
273276
274- private implicit class TypeOps (buff : Buffer ) {
275- def += (x : TypeRepr ): Buffer = { visitType(x); buff }
276- def += (x : Option [TypeRepr ]): Buffer = { visitOption(x, visitType); buff }
277- def ++= (x : List [TypeRepr ]): Buffer = { visitList(x, visitType); buff }
277+ private implicit class TypeOps (buff : self. type ) {
278+ def += (x : TypeRepr ): self. type = { visitType(x); buff }
279+ def += (x : Option [TypeRepr ]): self. type = { visitOption(x, visitType); buff }
280+ def ++= (x : List [TypeRepr ]): self. type = { visitList(x, visitType); buff }
278281 }
279282
280- private implicit class SignatureOps (buff : Buffer ) {
281- def += (x : Option [Signature ]): Buffer = { visitOption(x, visitSignature); buff }
283+ private implicit class SignatureOps (buff : self. type ) {
284+ def += (x : Option [Signature ]): self. type = { visitOption(x, visitSignature); buff }
282285 }
283286
284- private implicit class ImportSelectorOps (buff : Buffer ) {
285- def ++= (x : List [ImportSelector ]): Buffer = { visitList(x, visitImportSelector); buff }
287+ private implicit class ImportSelectorOps (buff : self. type ) {
288+ def ++= (x : List [ImportSelector ]): self. type = { visitList(x, visitImportSelector); buff }
286289 }
287290
288- private implicit class SymbolOps (buff : Buffer ) {
289- def += (x : Symbol ): Buffer = { visitSymbol(x); buff }
291+ private implicit class SymbolOps (buff : self. type ) {
292+ def += (x : Symbol ): self. type = { visitSymbol(x); buff }
290293 }
291294
292- private def visitOption [U ](opt : Option [U ], visit : U => Buffer ): Buffer = opt match {
295+ private def visitOption [U ](opt : Option [U ], visit : U => this . type ): this . type = opt match {
293296 case Some (x) =>
294297 this += " Some("
295298 visit(x)
@@ -298,7 +301,7 @@ class ExtractorsPrinter[R <: Reflection & Singleton](val reflect: R) extends Pri
298301 this += " None"
299302 }
300303
301- private def visitList [U ](list : List [U ], visit : U => Buffer ): Buffer = list match {
304+ private def visitList [U ](list : List [U ], visit : U => this . type ): this . type = list match {
302305 case x0 :: xs =>
303306 this += " List("
304307 visit(x0)
0 commit comments