Skip to content

Commit 535a7e3

Browse files
committed
wip
1 parent c591f2b commit 535a7e3

File tree

5 files changed

+96
-80
lines changed

5 files changed

+96
-80
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ object ReflectionImpl {
1818
val syntaxHighlight =
1919
if (ctx.settings.color.value == "always") SyntaxHighlight.ANSI
2020
else SyntaxHighlight.plain
21-
new refl.SourceCodePrinter(syntaxHighlight).showTree(reflTree)(given reflCtx)
21+
val printers = new scala.tasty.reflect.Printers(refl)
22+
new printers.SourceCodePrinter(syntaxHighlight).showTree(reflTree)(given reflCtx)
2223
}
2324
}
2425

library/src/scala/tasty/Reflection.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Reflection(private[scala] val internal: CompilerInterface)
1414
with ImportSelectorOps
1515
with QuotedOps
1616
with PositionOps
17-
with Printers
17+
with PrinterOps
1818
with ReportingOps
1919
with RootPosition
2020
with SignatureOps
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package scala.tasty
2+
package reflect
3+
4+
import scala.quoted.show.SyntaxHighlight
5+
6+
trait PrinterOps extends Core { self: Reflection =>
7+
8+
/** Adds `show` as an extension method of a `Tree` */
9+
implicit class TreeShowDeco(tree: Tree) {
10+
/** Shows the tree as extractors */
11+
def showExtractors(given ctx: Context): String =
12+
val printers = new Printers(self)
13+
new printers.ExtractorsPrinter().showTree(tree)
14+
15+
/** Shows the tree as fully typed source code */
16+
def show(given ctx: Context): String = show(SyntaxHighlight.plain)
17+
18+
/** Shows the tree as fully typed source code */
19+
def show(syntaxHighlight: SyntaxHighlight)(given ctx: Context): String =
20+
val printers = new Printers(self)
21+
new printers.SourceCodePrinter(syntaxHighlight).showTree(tree)
22+
23+
}
24+
25+
/** Adds `show` as an extension method of a `TypeOrBounds` */
26+
implicit class TypeOrBoundsShowDeco(tpe: TypeOrBounds) {
27+
/** Shows the tree as extractors */
28+
def showExtractors(given ctx: Context): String =
29+
val printers = new Printers(self)
30+
new printers.ExtractorsPrinter().showTypeOrBounds(tpe)
31+
32+
/** Shows the tree as fully typed source code */
33+
def show(given ctx: Context): String = show(SyntaxHighlight.plain)
34+
35+
/** Shows the tree as fully typed source code */
36+
def show(syntaxHighlight: SyntaxHighlight)(given ctx: Context): String =
37+
val printers = new Printers(self)
38+
new printers.SourceCodePrinter(syntaxHighlight).showTypeOrBounds(tpe)
39+
}
40+
41+
/** Adds `show` as an extension method of a `Constant` */
42+
implicit class ConstantShowDeco(const: Constant) {
43+
/** Shows the tree as extractors */
44+
def showExtractors(given ctx: Context): String =
45+
val printers = new Printers(self)
46+
new printers.ExtractorsPrinter().showConstant(const)
47+
48+
/** Shows the tree as fully typed source code */
49+
def show(given ctx: Context): String = show(SyntaxHighlight.plain)
50+
51+
/** Shows the tree as fully typed source code */
52+
def show(syntaxHighlight: SyntaxHighlight)(given ctx: Context): String =
53+
val printers = new Printers(self)
54+
new printers.SourceCodePrinter(syntaxHighlight).showConstant(const)
55+
}
56+
57+
/** Adds `show` as an extension method of a `Symbol` */
58+
implicit class SymbolShowDeco(symbol: Symbol) {
59+
/** Shows the tree as extractors */
60+
def showExtractors(given ctx: Context): String =
61+
val printers = new Printers(self)
62+
new printers.ExtractorsPrinter().showSymbol(symbol)
63+
64+
/** Shows the tree as fully typed source code */
65+
def show(given ctx: Context): String = show(SyntaxHighlight.plain)
66+
67+
/** Shows the tree as fully typed source code */
68+
def show(syntaxHighlight: SyntaxHighlight)(given ctx: Context): String =
69+
val printers = new Printers(self)
70+
new printers.SourceCodePrinter(syntaxHighlight).showSymbol(symbol)
71+
}
72+
73+
/** Adds `show` as an extension method of a `Flags` */
74+
implicit class FlagsShowDeco(flags: Flags) {
75+
/** Shows the tree as extractors */
76+
def showExtractors(given ctx: Context): String =
77+
val printers = new Printers(self)
78+
new printers.ExtractorsPrinter().showFlags(flags)
79+
80+
/** Shows the tree as fully typed source code */
81+
def show(given ctx: Context): String = show(SyntaxHighlight.plain)
82+
83+
/** Shows the tree as fully typed source code */
84+
def show(syntaxHighlight: SyntaxHighlight)(given ctx: Context): String =
85+
val printers = new Printers(self)
86+
new printers.SourceCodePrinter(syntaxHighlight).showFlags(flags)
87+
}
88+
89+
90+
}

library/src/scala/tasty/reflect/Printers.scala

Lines changed: 2 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -4,84 +4,9 @@ package reflect
44
import scala.annotation.switch
55
import scala.quoted.show.SyntaxHighlight
66

7-
trait Printers
8-
extends Core
9-
with ConstantOps
10-
with FlagsOps
11-
with IdOps
12-
with ImportSelectorOps
13-
with PositionOps
14-
with SignatureOps
15-
with StandardDefinitions
16-
with SymbolOps
17-
with TreeOps
18-
with TypeOrBoundsOps {
19-
20-
/** Adds `show` as an extension method of a `Tree` */
21-
implicit class TreeShowDeco(tree: Tree) {
22-
/** Shows the tree as extractors */
23-
def showExtractors(given ctx: Context): String = new ExtractorsPrinter().showTree(tree)
24-
25-
/** Shows the tree as fully typed source code */
26-
def show(given ctx: Context): String = show(SyntaxHighlight.plain)
27-
28-
/** Shows the tree as fully typed source code */
29-
def show(syntaxHighlight: SyntaxHighlight)(given ctx: Context): String =
30-
new SourceCodePrinter(syntaxHighlight).showTree(tree)
31-
}
32-
33-
/** Adds `show` as an extension method of a `TypeOrBounds` */
34-
implicit class TypeOrBoundsShowDeco(tpe: TypeOrBounds) {
35-
/** Shows the tree as extractors */
36-
def showExtractors(given ctx: Context): String = new ExtractorsPrinter().showTypeOrBounds(tpe)
37-
38-
/** Shows the tree as fully typed source code */
39-
def show(given ctx: Context): String = show(SyntaxHighlight.plain)
40-
41-
/** Shows the tree as fully typed source code */
42-
def show(syntaxHighlight: SyntaxHighlight)(given ctx: Context): String =
43-
new SourceCodePrinter(syntaxHighlight).showTypeOrBounds(tpe)
44-
}
45-
46-
/** Adds `show` as an extension method of a `Constant` */
47-
implicit class ConstantShowDeco(const: Constant) {
48-
/** Shows the tree as extractors */
49-
def showExtractors(given ctx: Context): String = new ExtractorsPrinter().showConstant(const)
50-
51-
/** Shows the tree as fully typed source code */
52-
def show(given ctx: Context): String = show(SyntaxHighlight.plain)
53-
54-
/** Shows the tree as fully typed source code */
55-
def show(syntaxHighlight: SyntaxHighlight)(given ctx: Context): String =
56-
new SourceCodePrinter(syntaxHighlight).showConstant(const)
57-
}
58-
59-
/** Adds `show` as an extension method of a `Symbol` */
60-
implicit class SymbolShowDeco(symbol: Symbol) {
61-
/** Shows the tree as extractors */
62-
def showExtractors(given ctx: Context): String = new ExtractorsPrinter().showSymbol(symbol)
63-
64-
/** Shows the tree as fully typed source code */
65-
def show(given ctx: Context): String = show(SyntaxHighlight.plain)
66-
67-
/** Shows the tree as fully typed source code */
68-
def show(syntaxHighlight: SyntaxHighlight)(given ctx: Context): String =
69-
new SourceCodePrinter(syntaxHighlight).showSymbol(symbol)
70-
}
71-
72-
/** Adds `show` as an extension method of a `Flags` */
73-
implicit class FlagsShowDeco(flags: Flags) {
74-
/** Shows the tree as extractors */
75-
def showExtractors(given ctx: Context): String = new ExtractorsPrinter().showFlags(flags)
76-
77-
/** Shows the tree as fully typed source code */
78-
def show(given ctx: Context): String = show(SyntaxHighlight.plain)
79-
80-
/** Shows the tree as fully typed source code */
81-
def show(syntaxHighlight: SyntaxHighlight)(given ctx: Context): String =
82-
new SourceCodePrinter(syntaxHighlight).showFlags(flags)
83-
}
7+
class Printers[R <: Reflection & Singleton](val tasty: R) {
848

9+
import tasty.{_, given}
8510

8611
abstract class Printer {
8712

library/src/scala/tasty/reflect/QuotedOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package scala.tasty.reflect
22

33
/** Extension methods on scala.quoted.{Expr|Type} to convert to scala.tasty.Tasty objects */
4-
trait QuotedOps extends Core { self: Printers =>
4+
trait QuotedOps extends Core {
55

66
implicit class QuotedExprAPI[T](expr: scala.quoted.Expr[T]) {
77
/** View this expression `quoted.Expr[T]` as a `Term` */

0 commit comments

Comments
 (0)