@@ -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 )
1615-
1616- def showShort : String =
1617- SourceCode .showType(using QuotesImpl .this )(self)(SyntaxHighlight .plain, fullNames = false )
16181600
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
@@ -2197,14 +2178,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
21972178 given ConstantMethods : ConstantMethods with
21982179 extension (self : Constant ):
21992180 def value : Any = self.value
2200- def showExtractors : String =
2201- Extractors .showConstant(using QuotesImpl .this )(self)
2202- def show : String =
2203- SourceCode .showConstant(using QuotesImpl .this )(self)(SyntaxHighlight .plain, fullNames = true )
2204- def showShort : String =
2205- SourceCode .showConstant(using QuotesImpl .this )(self)(SyntaxHighlight .plain, fullNames = false )
2206- def showAnsiColored : String =
2207- SourceCode .showConstant(using QuotesImpl .this )(self)(SyntaxHighlight .ANSI , fullNames = true )
2181+ def show : String = Extractors .showConstant(using QuotesImpl .this )(self)
22082182 end extension
22092183 end ConstantMethods
22102184
@@ -2426,12 +2400,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
24262400 def companionModule : Symbol = self.denot.companionModule
24272401 def children : List [Symbol ] = self.denot.children
24282402
2429- def showExtractors : String =
2430- Extractors .showSymbol(using QuotesImpl .this )(self)
2431- def show : String =
2432- SourceCode .showSymbol(using QuotesImpl .this )(self)(SyntaxHighlight .plain)
2433- def showAnsiColored : String =
2434- SourceCode .showSymbol(using QuotesImpl .this )(self)(SyntaxHighlight .ANSI )
2403+ def show (using printer : Printer [Symbol ]): String = printer.show(self)
24352404
24362405 end extension
24372406
@@ -2570,12 +2539,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
25702539 def is (that : Flags ): Boolean = self.isAllOf(that)
25712540 def | (that : Flags ): Flags = dotc.core.Flags .or(self, that) // TODO: Replace with dotc.core.Flags.|(self)(that) once extension names have stabilized
25722541 def & (that : Flags ): Flags = dotc.core.Flags .and(self, that)// TODO: Replace with dotc.core.Flags.&(self)(that) once extension names have stabilized
2573- def showExtractors : String =
2574- Extractors .showFlags(using QuotesImpl .this )(self)
2575- def show : String =
2576- SourceCode .showFlags(using QuotesImpl .this )(self)(SyntaxHighlight .plain)
2577- def showAnsiColored : String =
2578- SourceCode .showFlags(using QuotesImpl .this )(self)(SyntaxHighlight .ANSI )
2542+ def show : String = Extractors .showFlags(using QuotesImpl .this )(self)
25792543 end extension
25802544 end FlagsMethods
25812545
@@ -2693,18 +2657,53 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
26932657 |
26942658 |
26952659 |The code of the definition of ${t.symbol} is
2696- | ${TreeMethods .show(t)}
2660+ | ${Printer . TreeCode .show(t)}
26972661 |
26982662 |which was found in the code
2699- | ${TreeMethods .show(tree)}
2663+ | ${Printer . TreeCode .show(tree)}
27002664 |
27012665 |which has the AST representation
2702- | ${TreeMethods .showExtractors (tree)}
2666+ | ${Printer . TreeStructure .show (tree)}
27032667 |
27042668 | """ .stripMargin)
27052669 case _ => traverseChildren(t)
27062670 }.traverse(tree)
27072671
2672+ object Printer extends PrinterModule :
2673+
2674+ lazy val TreeCode : Printer [Tree ] = new Printer [Tree ]:
2675+ def show (tree : Tree ): String =
2676+ SourceCode .showTree(using QuotesImpl .this )(tree)(SyntaxHighlight .plain, fullNames = true )
2677+
2678+ lazy val TreeShortCode : Printer [Tree ] = new Printer [Tree ]:
2679+ def show (tree : Tree ): String =
2680+ SourceCode .showTree(using QuotesImpl .this )(tree)(SyntaxHighlight .plain, fullNames = false )
2681+
2682+ lazy val TreeAnsiCode : Printer [Tree ] = new Printer [Tree ]:
2683+ def show (tree : Tree ): String =
2684+ SourceCode .showTree(using QuotesImpl .this )(tree)(SyntaxHighlight .ANSI , fullNames = true )
2685+
2686+ lazy val TreeStructure : Printer [Tree ] = new Printer [Tree ]:
2687+ def show (tree : Tree ): String =
2688+ Extractors .showTree(using QuotesImpl .this )(tree)
2689+
2690+ lazy val TypeReprCode : Printer [TypeRepr ] = new Printer [TypeRepr ]:
2691+ def show (tpe : TypeRepr ): String =
2692+ SourceCode .showType(using QuotesImpl .this )(tpe)(SyntaxHighlight .plain, fullNames = true )
2693+
2694+ lazy val TypeReprShortCode : Printer [TypeRepr ] = new Printer [TypeRepr ]:
2695+ def show (tpe : TypeRepr ): String =
2696+ SourceCode .showType(using QuotesImpl .this )(tpe)(SyntaxHighlight .plain, fullNames = false )
2697+
2698+ lazy val TypeReprAnsiCode : Printer [TypeRepr ] = new Printer [TypeRepr ]:
2699+ def show (tpe : TypeRepr ): String =
2700+ SourceCode .showType(using QuotesImpl .this )(tpe)(SyntaxHighlight .ANSI , fullNames = true )
2701+
2702+ lazy val TypeReprStructure : Printer [TypeRepr ] = new Printer [TypeRepr ]:
2703+ def show (tpe : TypeRepr ): String =
2704+ Extractors .showType(using QuotesImpl .this )(tpe)
2705+
2706+ end Printer
27082707 end reflect
27092708
27102709 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