1- package scala .tasty
2- package reflect
1+ package dotty .tools .dotc .quoted .printers
32
4- class ExtractorsPrinter [R <: Reflection & Singleton ](val reflect : R ) extends Printer [R ] {
5- import reflect ._
3+ import scala .quoted ._
64
7- def showTree (tree : Tree ): String =
8- new Buffer ().visitTree(tree).result()
5+ object Extractors {
96
10- def showType ( tpe : TypeRepr ): String =
11- new Buffer ().visitType(tpe ).result()
7+ def showTree ( using QuoteContext )( tree : qctx.reflect. Tree ): String =
8+ new ExtractorsPrinter [qctx. type ] ().visitTree(tree ).result()
129
13- def showConstant ( const : Constant ): String =
14- new Buffer ().visitConstant(const ).result()
10+ def showType ( using QuoteContext )( tpe : qctx.reflect. TypeRepr ): String =
11+ new ExtractorsPrinter [qctx. type ] ().visitType(tpe ).result()
1512
16- def showSymbol ( symbol : Symbol ): String =
17- new Buffer ().visitSymbol(symbol ).result()
13+ def showConstant ( using QuoteContext )( const : qctx.reflect. Constant ): String =
14+ new ExtractorsPrinter [qctx. type ] ().visitConstant(const ).result()
1815
19- def showFlags (flags : Flags ): String = {
16+ def showSymbol (using QuoteContext )(symbol : qctx.reflect.Symbol ): String =
17+ new ExtractorsPrinter [qctx.type ]().visitSymbol(symbol).result()
18+
19+ def showFlags (using QuoteContext )(flags : qctx.reflect.Flags ): String = {
20+ import qctx .reflect ._
2021 val flagList = List .newBuilder[String ]
2122 if (flags.is(Flags .Abstract )) flagList += " Flags.Abstract"
2223 if (flags.is(Flags .Artifact )) flagList += " Flags.Artifact"
@@ -55,13 +56,14 @@ class ExtractorsPrinter[R <: Reflection & Singleton](val reflect: R) extends Pri
5556 flagList.result().mkString(" | " )
5657 }
5758
58- private class Buffer { self =>
59+ private class ExtractorsPrinter [QCtx <: QuoteContext & Singleton ](using val qctx : QCtx ) { self =>
60+ import qctx .reflect ._
5961
6062 private val sb : StringBuilder = new StringBuilder
6163
6264 def result (): String = sb.result()
6365
64- def visitTree (x : Tree ): Buffer = x match {
66+ def visitTree (x : Tree ): this . type = x match {
6567 case Ident (name) =>
6668 this += " Ident(\" " += name += " \" )"
6769 case Select (qualifier, name) =>
@@ -164,7 +166,7 @@ class ExtractorsPrinter[R <: Reflection & Singleton](val reflect: R) extends Pri
164166 this += " Alternative(" ++= patterns += " )"
165167 }
166168
167- def visitConstant (x : Constant ): Buffer = x match {
169+ def visitConstant (x : Constant ): this . type = x match {
168170 case Constant .Unit () => this += " Constant.Unit()"
169171 case Constant .Null () => this += " Constant.Null()"
170172 case Constant .Boolean (value) => this += " Constant.Boolean(" += value += " )"
@@ -181,7 +183,7 @@ class ExtractorsPrinter[R <: Reflection & Singleton](val reflect: R) extends Pri
181183 visitType(value) += " )"
182184 }
183185
184- def visitType (x : TypeRepr ): Buffer = x match {
186+ def visitType (x : TypeRepr ): this . type = x match {
185187 case ConstantType (value) =>
186188 this += " ConstantType(" += value += " )"
187189 case TermRef (qual, name) =>
@@ -225,71 +227,71 @@ class ExtractorsPrinter[R <: Reflection & Singleton](val reflect: R) extends Pri
225227 this += " NoPrefix()"
226228 }
227229
228- def visitSignature (sig : Signature ): Buffer = {
230+ def visitSignature (sig : Signature ): this . type = {
229231 val Signature (params, res) = sig
230232 this += " Signature(" ++= params.map(_.toString) += " , " += res += " )"
231233 }
232234
233- def visitImportSelector (sel : ImportSelector ): Buffer = sel match {
235+ def visitImportSelector (sel : ImportSelector ): this . type = sel match {
234236 case SimpleSelector (id) => this += " SimpleSelector(" += id += " )"
235237 case RenameSelector (id1, id2) => this += " RenameSelector(" += id1 += " , " += id2 += " )"
236238 case OmitSelector (id) => this += " OmitSelector(" += id += " )"
237239 }
238240
239- def visitSymbol (x : Symbol ): Buffer =
241+ def visitSymbol (x : Symbol ): this . type =
240242 if x.isPackageDef then this += " IsPackageDefSymbol(<" += x.fullName += " >)"
241243 else if x.isClassDef then this += " IsClassDefSymbol(<" += x.fullName += " >)"
242244 else if x.isDefDef then this += " IsDefDefSymbol(<" += x.fullName += " >)"
243245 else if x.isValDef then this += " IsValDefSymbol(<" += x.fullName += " >)"
244246 else if x.isTypeDef then this += " IsTypeDefSymbol(<" += x.fullName += " >)"
245247 else { assert(x.isNoSymbol); this += " NoSymbol()" }
246248
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 }
249+ def += (x : Boolean ): this . type = { sb.append(x); this }
250+ def += (x : Byte ): this . type = { sb.append(x); this }
251+ def += (x : Short ): this . type = { sb.append(x); this }
252+ def += (x : Int ): this . type = { sb.append(x); this }
253+ def += (x : Long ): this . type = { sb.append(x); this }
254+ def += (x : Float ): this . type = { sb.append(x); this }
255+ def += (x : Double ): this . type = { sb.append(x); this }
256+ def += (x : Char ): this . type = { sb.append(x); this }
257+ def += (x : String ): this . type = { sb.append(x); this }
256258
257- def ++= (xs : List [String ]): Buffer = visitList[String ](xs, += )
259+ def ++= (xs : List [String ]): this . type = visitList[String ](xs, += )
258260
259- private implicit class StringOps (buff : Buffer ) {
260- def += (x : Option [String ]): Buffer = { visitOption(x, y => buff += " \" " += y += " \" " ); buff }
261+ private implicit class StringOps (buff : self. type ) {
262+ def += (x : Option [String ]): self. type = { visitOption(x, y => buff += " \" " += y += " \" " ); buff }
261263 }
262264
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 }
265+ private implicit class TreeOps (buff : self. type ) {
266+ def += (x : Tree ): self. type = { visitTree(x); buff }
267+ def += (x : Option [Tree ]): self. type = { visitOption(x, visitTree); buff }
268+ def ++= (x : List [Tree ]): self. type = { visitList(x, visitTree); buff }
269+ def +++= (x : List [List [Tree ]]): self. type = { visitList(x, ++= ); buff }
268270 }
269271
270- private implicit class ConstantOps (buff : Buffer ) {
271- def += (x : Constant ): Buffer = { visitConstant(x); buff }
272+ private implicit class ConstantOps (buff : self. type ) {
273+ def += (x : Constant ): self. type = { visitConstant(x); buff }
272274 }
273275
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 }
276+ private implicit class TypeOps (buff : self. type ) {
277+ def += (x : TypeRepr ): self. type = { visitType(x); buff }
278+ def += (x : Option [TypeRepr ]): self. type = { visitOption(x, visitType); buff }
279+ def ++= (x : List [TypeRepr ]): self. type = { visitList(x, visitType); buff }
278280 }
279281
280- private implicit class SignatureOps (buff : Buffer ) {
281- def += (x : Option [Signature ]): Buffer = { visitOption(x, visitSignature); buff }
282+ private implicit class SignatureOps (buff : self. type ) {
283+ def += (x : Option [Signature ]): self. type = { visitOption(x, visitSignature); buff }
282284 }
283285
284- private implicit class ImportSelectorOps (buff : Buffer ) {
285- def ++= (x : List [ImportSelector ]): Buffer = { visitList(x, visitImportSelector); buff }
286+ private implicit class ImportSelectorOps (buff : self. type ) {
287+ def ++= (x : List [ImportSelector ]): self. type = { visitList(x, visitImportSelector); buff }
286288 }
287289
288- private implicit class SymbolOps (buff : Buffer ) {
289- def += (x : Symbol ): Buffer = { visitSymbol(x); buff }
290+ private implicit class SymbolOps (buff : self. type ) {
291+ def += (x : Symbol ): self. type = { visitSymbol(x); buff }
290292 }
291293
292- private def visitOption [U ](opt : Option [U ], visit : U => Buffer ): Buffer = opt match {
294+ private def visitOption [U ](opt : Option [U ], visit : U => this . type ): this . type = opt match {
293295 case Some (x) =>
294296 this += " Some("
295297 visit(x)
@@ -298,7 +300,7 @@ class ExtractorsPrinter[R <: Reflection & Singleton](val reflect: R) extends Pri
298300 this += " None"
299301 }
300302
301- private def visitList [U ](list : List [U ], visit : U => Buffer ): Buffer = list match {
303+ private def visitList [U ](list : List [U ], visit : U => this . type ): this . type = list match {
302304 case x0 :: xs =>
303305 this += " List("
304306 visit(x0)
0 commit comments