1
1
package scala .tasty
2
2
package reflect
3
3
4
- class ExtractorsPrinter [R <: Reflection & Singleton ](val reflect : R ) extends Printer [R ] {
5
- import reflect ._
4
+ import scala .quoted ._
6
5
7
- def showTree (tree : Tree ): String =
8
- new Buffer ().visitTree(tree).result()
6
+ class ExtractorsPrinter extends Printer {
9
7
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()
12
10
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()
15
13
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()
18
16
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 ._
20
22
val flagList = List .newBuilder[String ]
21
23
if (flags.is(Flags .Abstract )) flagList += " Flags.Abstract"
22
24
if (flags.is(Flags .Artifact )) flagList += " Flags.Artifact"
@@ -55,13 +57,14 @@ class ExtractorsPrinter[R <: Reflection & Singleton](val reflect: R) extends Pri
55
57
flagList.result().mkString(" | " )
56
58
}
57
59
58
- private class Buffer { self =>
60
+ private class Buffer [QCtx <: QuoteContext & Singleton ](using val qctx : QCtx ) { self =>
61
+ import qctx .reflect ._
59
62
60
63
private val sb : StringBuilder = new StringBuilder
61
64
62
65
def result (): String = sb.result()
63
66
64
- def visitTree (x : Tree ): Buffer = x match {
67
+ def visitTree (x : Tree ): this . type = x match {
65
68
case Ident (name) =>
66
69
this += " Ident(\" " += name += " \" )"
67
70
case Select (qualifier, name) =>
@@ -164,7 +167,7 @@ class ExtractorsPrinter[R <: Reflection & Singleton](val reflect: R) extends Pri
164
167
this += " Alternative(" ++= patterns += " )"
165
168
}
166
169
167
- def visitConstant (x : Constant ): Buffer = x match {
170
+ def visitConstant (x : Constant ): this . type = x match {
168
171
case Constant .Unit () => this += " Constant.Unit()"
169
172
case Constant .Null () => this += " Constant.Null()"
170
173
case Constant .Boolean (value) => this += " Constant.Boolean(" += value += " )"
@@ -181,7 +184,7 @@ class ExtractorsPrinter[R <: Reflection & Singleton](val reflect: R) extends Pri
181
184
visitType(value) += " )"
182
185
}
183
186
184
- def visitType (x : TypeRepr ): Buffer = x match {
187
+ def visitType (x : TypeRepr ): this . type = x match {
185
188
case ConstantType (value) =>
186
189
this += " ConstantType(" += value += " )"
187
190
case TermRef (qual, name) =>
@@ -225,71 +228,71 @@ class ExtractorsPrinter[R <: Reflection & Singleton](val reflect: R) extends Pri
225
228
this += " NoPrefix()"
226
229
}
227
230
228
- def visitSignature (sig : Signature ): Buffer = {
231
+ def visitSignature (sig : Signature ): this . type = {
229
232
val Signature (params, res) = sig
230
233
this += " Signature(" ++= params.map(_.toString) += " , " += res += " )"
231
234
}
232
235
233
- def visitImportSelector (sel : ImportSelector ): Buffer = sel match {
236
+ def visitImportSelector (sel : ImportSelector ): this . type = sel match {
234
237
case SimpleSelector (id) => this += " SimpleSelector(" += id += " )"
235
238
case RenameSelector (id1, id2) => this += " RenameSelector(" += id1 += " , " += id2 += " )"
236
239
case OmitSelector (id) => this += " OmitSelector(" += id += " )"
237
240
}
238
241
239
- def visitSymbol (x : Symbol ): Buffer =
242
+ def visitSymbol (x : Symbol ): this . type =
240
243
if x.isPackageDef then this += " IsPackageDefSymbol(<" += x.fullName += " >)"
241
244
else if x.isClassDef then this += " IsClassDefSymbol(<" += x.fullName += " >)"
242
245
else if x.isDefDef then this += " IsDefDefSymbol(<" += x.fullName += " >)"
243
246
else if x.isValDef then this += " IsValDefSymbol(<" += x.fullName += " >)"
244
247
else if x.isTypeDef then this += " IsTypeDefSymbol(<" += x.fullName += " >)"
245
248
else { assert(x.isNoSymbol); this += " NoSymbol()" }
246
249
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 }
256
259
257
- def ++= (xs : List [String ]): Buffer = visitList[String ](xs, += )
260
+ def ++= (xs : List [String ]): this . type = visitList[String ](xs, += )
258
261
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 }
261
264
}
262
265
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 }
268
271
}
269
272
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 }
272
275
}
273
276
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 }
278
281
}
279
282
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 }
282
285
}
283
286
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 }
286
289
}
287
290
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 }
290
293
}
291
294
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 {
293
296
case Some (x) =>
294
297
this += " Some("
295
298
visit(x)
@@ -298,7 +301,7 @@ class ExtractorsPrinter[R <: Reflection & Singleton](val reflect: R) extends Pri
298
301
this += " None"
299
302
}
300
303
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 {
302
305
case x0 :: xs =>
303
306
this += " List("
304
307
visit(x0)
0 commit comments