@@ -29,10 +29,10 @@ object QuotesImpl {
2929 new QuotesImpl
3030
3131 def showDecompiledTree (tree : tpd.Tree )(using Context ): String =
32- import qctx .reflect .TreeMethods .{ showAnsiColored , show }
32+ import qctx .reflect .Printer .{ TreeCode , TreeAnsiCode }
3333 val qctx : QuotesImpl = new QuotesImpl (using MacroExpansion .context(tree))
34- if ctx.settings.color.value == " always" then showAnsiColored (tree)
35- else show(tree)
34+ if ctx.settings.color.value == " always" then TreeAnsiCode .show (tree)
35+ else TreeCode . show(tree)
3636
3737 // TODO Explore more fine grained scope ids.
3838 // This id can only differentiate scope extrusion from one compiler instance to another.
@@ -48,10 +48,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
4848
4949 extension [T ](self : scala.quoted.Expr [T ]):
5050 def show : String =
51- reflect.TreeMethods .show(reflect.Term .of(self))
52-
53- def showAnsiColored : String =
54- reflect.TreeMethods .showAnsiColored(reflect.Term .of(self))
51+ reflect.Printer .TreeCode .show(reflect.Term .of(self))
5552
5653 def matches (that : scala.quoted.Expr [Any ]): Boolean =
5754 treeMatch(reflect.Term .of(self), reflect.Term .of(that)).nonEmpty
@@ -70,8 +67,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
7067 else
7168 throw Exception (
7269 s """ Expr cast exception: ${self.show}
73- |of type: ${reflect.TypeReprMethods .show(reflect.Term .of(self).tpe)}
74- |did not conform to type: ${reflect.TypeReprMethods .show(reflect.TypeRepr .of[X ])}
70+ |of type: ${reflect.Printer . TypeReprCode .show(reflect.Term .of(self).tpe)}
71+ |did not conform to type: ${reflect.Printer . TypeReprCode .show(reflect.TypeRepr .of[X ])}
7572 | """ .stripMargin
7673 )
7774 }
@@ -89,14 +86,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
8986 extension (self : Tree ):
9087 def pos : Position = self.sourcePos
9188 def symbol : Symbol = self.symbol
92- def showExtractors : String =
93- Extractors .showTree(using QuotesImpl .this )(self)
94- def show : String =
95- SourceCode .showTree(using QuotesImpl .this )(self)(SyntaxHighlight .plain, fullNames = true )
96- def showShort : String =
97- SourceCode .showTree(using QuotesImpl .this )(self)(SyntaxHighlight .plain, fullNames = false )
98- def showAnsiColored : String =
99- SourceCode .showTree(using QuotesImpl .this )(self)(SyntaxHighlight .ANSI , fullNames = true )
89+ def show (using printer : Printer [Tree ]): String = printer.show(self)
10090 def isExpr : Boolean =
10191 self match
10292 case TermTypeTest (self) =>
@@ -1607,17 +1597,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
16071597
16081598 given TypeReprMethods : TypeReprMethods with
16091599 extension (self : TypeRepr ):
1610- def showExtractors : String =
1611- Extractors .showType(using QuotesImpl .this )(self)
1612-
1613- def show : String =
1614- SourceCode .showType(using QuotesImpl .this )(self)(SyntaxHighlight .plain, fullNames = true )
16151600
1616- def showShort : String =
1617- SourceCode .showType(using QuotesImpl .this )(self)(SyntaxHighlight .plain, fullNames = false )
1618-
1619- def showAnsiColored : String =
1620- SourceCode .showType(using QuotesImpl .this )(self)(SyntaxHighlight .ANSI , fullNames = true )
1601+ def show (using printer : Printer [TypeRepr ]): String = printer.show(self)
16211602
16221603 def seal : scala.quoted.Type [_] = self.asType
16231604
@@ -2175,14 +2156,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
21752156 given ConstantMethods : ConstantMethods with
21762157 extension (self : Constant ):
21772158 def value : Any = self.value
2178- def showExtractors : String =
2179- Extractors .showConstant(using QuotesImpl .this )(self)
2180- def show : String =
2181- SourceCode .showConstant(using QuotesImpl .this )(self)(SyntaxHighlight .plain, fullNames = true )
2182- def showShort : String =
2183- SourceCode .showConstant(using QuotesImpl .this )(self)(SyntaxHighlight .plain, fullNames = false )
2184- def showAnsiColored : String =
2185- SourceCode .showConstant(using QuotesImpl .this )(self)(SyntaxHighlight .ANSI , fullNames = true )
2159+ def show (using printer : Printer [Constant ]): String = printer.show(self)
21862160 end extension
21872161 end ConstantMethods
21882162
@@ -2404,12 +2378,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
24042378 def companionModule : Symbol = self.denot.companionModule
24052379 def children : List [Symbol ] = self.denot.children
24062380
2407- def showExtractors : String =
2408- Extractors .showSymbol(using QuotesImpl .this )(self)
2409- def show : String =
2410- SourceCode .showSymbol(using QuotesImpl .this )(self)(SyntaxHighlight .plain)
2411- def showAnsiColored : String =
2412- SourceCode .showSymbol(using QuotesImpl .this )(self)(SyntaxHighlight .ANSI )
2381+ def show (using printer : Printer [Symbol ]): String = printer.show(self)
24132382
24142383 end extension
24152384
@@ -2548,12 +2517,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
25482517 def is (that : Flags ): Boolean = self.isAllOf(that)
25492518 def | (that : Flags ): Flags = dotc.core.Flags .or(self, that) // TODO: Replace with dotc.core.Flags.|(self)(that) once extension names have stabilized
25502519 def & (that : Flags ): Flags = dotc.core.Flags .and(self, that)// TODO: Replace with dotc.core.Flags.&(self)(that) once extension names have stabilized
2551- def showExtractors : String =
2552- Extractors .showFlags(using QuotesImpl .this )(self)
2553- def show : String =
2554- SourceCode .showFlags(using QuotesImpl .this )(self)(SyntaxHighlight .plain)
2555- def showAnsiColored : String =
2556- SourceCode .showFlags(using QuotesImpl .this )(self)(SyntaxHighlight .ANSI )
2520+ def show (using printer : Printer [Flags ]): String = printer.show(self)
25572521 end extension
25582522 end FlagsMethods
25592523
@@ -2684,18 +2648,69 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
26842648 |
26852649 |
26862650 |The code of the definition of ${t.symbol} is
2687- | ${TreeMethods .show(t)}
2651+ | ${Printer . TreeCode .show(t)}
26882652 |
26892653 |which was found in the code
2690- | ${TreeMethods .show(tree)}
2654+ | ${Printer . TreeCode .show(tree)}
26912655 |
26922656 |which has the AST representation
2693- | ${TreeMethods .showExtractors (tree)}
2657+ | ${Printer . TreeStructure .show (tree)}
26942658 |
26952659 | """ .stripMargin)
26962660 case _ => traverseChildren(t)
26972661 }.traverse(tree)
26982662
2663+ object Printer extends PrinterModule :
2664+
2665+ lazy val TreeCode : Printer [Tree ] = new Printer [Tree ]:
2666+ def show (tree : Tree ): String =
2667+ SourceCode .showTree(using QuotesImpl .this )(tree)(SyntaxHighlight .plain, fullNames = true )
2668+
2669+ lazy val TreeShortCode : Printer [Tree ] = new Printer [Tree ]:
2670+ def show (tree : Tree ): String =
2671+ SourceCode .showTree(using QuotesImpl .this )(tree)(SyntaxHighlight .plain, fullNames = false )
2672+
2673+ lazy val TreeAnsiCode : Printer [Tree ] = new Printer [Tree ]:
2674+ def show (tree : Tree ): String =
2675+ SourceCode .showTree(using QuotesImpl .this )(tree)(SyntaxHighlight .ANSI , fullNames = true )
2676+
2677+ lazy val TreeStructure : Printer [Tree ] = new Printer [Tree ]:
2678+ def show (tree : Tree ): String =
2679+ Extractors .showTree(using QuotesImpl .this )(tree)
2680+
2681+ lazy val TypeReprCode : Printer [TypeRepr ] = new Printer [TypeRepr ]:
2682+ def show (tpe : TypeRepr ): String =
2683+ SourceCode .showType(using QuotesImpl .this )(tpe)(SyntaxHighlight .plain, fullNames = true )
2684+
2685+ lazy val TypeReprShortCode : Printer [TypeRepr ] = new Printer [TypeRepr ]:
2686+ def show (tpe : TypeRepr ): String =
2687+ SourceCode .showType(using QuotesImpl .this )(tpe)(SyntaxHighlight .plain, fullNames = false )
2688+
2689+ lazy val TypeReprAnsiCode : Printer [TypeRepr ] = new Printer [TypeRepr ]:
2690+ def show (tpe : TypeRepr ): String =
2691+ SourceCode .showType(using QuotesImpl .this )(tpe)(SyntaxHighlight .ANSI , fullNames = true )
2692+
2693+ lazy val TypeReprStructure : Printer [TypeRepr ] = new Printer [TypeRepr ]:
2694+ def show (tpe : TypeRepr ): String =
2695+ Extractors .showType(using QuotesImpl .this )(tpe)
2696+
2697+ lazy val ConstantCode : Printer [Constant ] = new Printer [Constant ]:
2698+ def show (const : Constant ): String =
2699+ SourceCode .showConstant(using QuotesImpl .this )(const)(SyntaxHighlight .plain, fullNames = true )
2700+
2701+ lazy val ConstantAnsiCode : Printer [Constant ] = new Printer [Constant ]:
2702+ def show (const : Constant ): String =
2703+ SourceCode .showConstant(using QuotesImpl .this )(const)(SyntaxHighlight .ANSI , fullNames = true )
2704+
2705+ lazy val ConstantCase : Printer [Constant ] = new Printer [Constant ]:
2706+ def show (const : Constant ): String =
2707+ Extractors .showConstant(using QuotesImpl .this )(const)
2708+
2709+ lazy val FlagsCombination : Printer [Flags ] = new Printer [Flags ]:
2710+ def show (flags : Flags ): String =
2711+ Extractors .showFlags(using QuotesImpl .this )(flags)
2712+
2713+ end Printer
26992714 end reflect
27002715
27012716 def unpickleExpr [T ](pickled : String | List [String ], typeHole : (Int , Seq [Any ]) => scala.quoted.Type [? ], termHole : (Int , Seq [Any ], scala.quoted.Quotes ) => scala.quoted.Expr [? ]): scala.quoted.Expr [T ] =
0 commit comments