Skip to content

Commit b0ce6d7

Browse files
committed
Remove ReflectionImpl
1 parent 8f80cfa commit b0ce6d7

File tree

6 files changed

+51
-75
lines changed

6 files changed

+51
-75
lines changed

compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class DecompilationPrinter extends Phase {
4343
} else {
4444
val unitFile = unit.source.toString.replace("\\", "/").replace(".class", ".tasty")
4545
out.println(s"/** Decompiled from $unitFile */")
46-
out.println(ReflectionImpl(ctx).showSourceCode.showTree(unit.tpdTree)(ctx))
46+
val refl = ReflectionImpl(ctx)
47+
out.println(new refl.SourceCodePrinter().showTree(unit.tpdTree)(ctx))
4748
}
4849
}
4950
}

compiler/src/dotty/tools/dotc/decompiler/IDEDecompilerDriver.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class IDEDecompilerDriver(val settings: List[String]) extends dotc.Driver {
3535
run.printSummary()
3636
val unit = ctx.run.units.head
3737

38-
val decompiled = ReflectionImpl(ctx).showSourceCode.showTree(unit.tpdTree)
38+
val refl = ReflectionImpl(ctx)
39+
val decompiled = new refl.SourceCodePrinter().showTree(unit.tpdTree)
3940
val tree = new TastyHTMLPrinter(unit.pickled.head._2).printContents()
4041

4142
reporter.removeBufferedMessages.foreach(message => System.err.println(message))

compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class QuoteDriver extends Driver {
4747
val tree1 =
4848
if (ctx.settings.YshowRawQuoteTrees.value) tree
4949
else (new TreeCleaner).transform(tree)
50-
ReflectionImpl(ctx).showSourceCode.showTree(tree1)
50+
val refl = ReflectionImpl(ctx)
51+
new refl.SourceCodePrinter().showTree(tree1)
5152
}
5253
withTree(expr, show, settings)
5354
}

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

Lines changed: 0 additions & 57 deletions
This file was deleted.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ class ReflectionImpl private (ctx: Contexts.Context, pos: SourcePosition)
77
extends scala.tasty.Reflection
88
with CoreImpl
99
with ContextOpsImpl
10-
with PrintersImpl
1110
with SymbolOpsImpl
1211
with TreeOpsImpl
1312
with TypeOrBoundsTreesOpsImpl

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

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,67 @@ trait Printers
2424
with TypeOrBoundsOps {
2525

2626
/** Adds `show` as an extension method of a `Tree` */
27-
implicit def TreeShowDeco(tree: Tree): ShowAPI
27+
implicit class TreeShowDeco(tree: Tree) {
28+
/** Shows the tree as extractors */
29+
def show(implicit ctx: Context): String = new ExtractorsPrinter().showTree(tree)
30+
/** Shows the tree as source code */
31+
def showCode(implicit ctx: Context): String = new SourceCodePrinter().showTree(tree)
32+
}
2833

2934
/** Adds `show` as an extension method of a `TypeOrBoundsTree` */
30-
implicit def TypeOrBoundsTreeShowDeco(tpt: TypeOrBoundsTree): ShowAPI
35+
implicit class TypeOrBoundsTreeShowDeco(tpt: TypeOrBoundsTree) {
36+
/** Shows the tree as extractors */
37+
def show(implicit ctx: Context): String = new ExtractorsPrinter().showTypeOrBoundsTree(tpt)
38+
/** Shows the tree as source code */
39+
def showCode(implicit ctx: Context): String = new SourceCodePrinter().showTypeOrBoundsTree(tpt)
40+
}
3141

3242
/** Adds `show` as an extension method of a `TypeOrBounds` */
33-
implicit def TypeOrBoundsShowDeco(tpt: TypeOrBounds): ShowAPI
43+
implicit class TypeOrBoundsShowDeco(tpe: TypeOrBounds) {
44+
/** Shows the tree as extractors */
45+
def show(implicit ctx: Context): String = new ExtractorsPrinter().showTypeOrBounds(tpe)
46+
/** Shows the tree as source code */
47+
def showCode(implicit ctx: Context): String = new SourceCodePrinter().showTypeOrBounds(tpe)
48+
}
3449

3550
/** Adds `show` as an extension method of a `CaseDef` */
36-
implicit def CaseDefShowDeco(caseDef: CaseDef): ShowAPI
51+
implicit class CaseDefShowDeco(caseDef: CaseDef) {
52+
/** Shows the tree as extractors */
53+
def show(implicit ctx: Context): String = new ExtractorsPrinter().showCaseDef(caseDef)
54+
/** Shows the tree as source code */
55+
def showCode(implicit ctx: Context): String = new SourceCodePrinter().showCaseDef(caseDef)
56+
}
3757

3858
/** Adds `show` as an extension method of a `Pattern` */
39-
implicit def PatternShowDeco(pattern: Pattern): ShowAPI
59+
implicit class PatternShowDeco(pattern: Pattern) {
60+
/** Shows the tree as extractors */
61+
def show(implicit ctx: Context): String = new ExtractorsPrinter().showPattern(pattern)
62+
/** Shows the tree as source code */
63+
def showCode(implicit ctx: Context): String = new SourceCodePrinter().showPattern(pattern)
64+
}
4065

4166
/** Adds `show` as an extension method of a `Constant` */
42-
implicit def ConstantShowDeco(const: Constant): ShowAPI
67+
implicit class ConstantShowDeco(const: Constant) {
68+
/** Shows the tree as extractors */
69+
def show(implicit ctx: Context): String = new ExtractorsPrinter().showConstant(const)
70+
/** Shows the tree as source code */
71+
def showCode(implicit ctx: Context): String = new SourceCodePrinter().showConstant(const)
72+
}
4373

4474
/** Adds `show` as an extension method of a `Symbol` */
45-
implicit def SymbolShowDeco(symbol: Symbol): ShowAPI
75+
implicit class SymbolShowDeco(symbol: Symbol) {
76+
/** Shows the tree as extractors */
77+
def show(implicit ctx: Context): String = new ExtractorsPrinter().showSymbol(symbol)
78+
/** Shows the tree as source code */
79+
def showCode(implicit ctx: Context): String = new SourceCodePrinter().showSymbol(symbol)
80+
}
4681

4782
/** Adds `show` as an extension method of a `Flags` */
48-
implicit def FlagsShowDeco(flags: Flags): ShowAPI
49-
50-
/** Define `show` as method */
51-
trait ShowAPI {
83+
implicit class FlagsShowDeco(flags: Flags) {
5284
/** Shows the tree as extractors */
53-
def show(implicit ctx: Context): String
54-
85+
def show(implicit ctx: Context): String = new ExtractorsPrinter().showFlags(flags)
5586
/** Shows the tree as source code */
56-
def showCode(implicit ctx: Context): String
87+
def showCode(implicit ctx: Context): String = new SourceCodePrinter().showFlags(flags)
5788
}
5889

5990
abstract class Printer {

0 commit comments

Comments
 (0)