Skip to content

Commit 4299f03

Browse files
committed
Rename tasty.Show to tasty.Printer
Aslo add `showCode` on Tree, TypeTree, ...
1 parent af59515 commit 4299f03

File tree

8 files changed

+34
-36
lines changed

8 files changed

+34
-36
lines changed
Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,53 @@
11
package dotty.tools.dotc.tastyreflect
22

3-
import scala.tasty.util.{Show, ShowExtractors, ShowSourceCode}
3+
import scala.tasty.util.{Printer, ExtractorsPrinter, SourceCodePrinter}
44

5-
trait PrintersImpl extends scala.tasty.reflect.Printers with scala.tasty.reflect.ReflectionCore { tasty: ReflectionImpl =>
5+
trait PrintersImpl extends scala.tasty.reflect.Printers with scala.tasty.reflect.ReflectionCore { reflect: ReflectionImpl =>
66

7-
def showExtractors: Show[tasty.type] = new ShowExtractors[tasty.type](this)
7+
def showExtractors: Printer[reflect.type] = new ExtractorsPrinter[reflect.type](this)
88

9-
def showSourceCode: Show[tasty.type] = new ShowSourceCode[tasty.type](this)
9+
def showSourceCode: Printer[reflect.type] = new SourceCodePrinter[reflect.type](this)
1010

1111
/** Adds `show` as an extension method of a `Tree` */
1212
def TreeShowDeco(tree: Tree): ShowAPI = new ShowAPI {
13-
def show(implicit ctx: Context, s: Show[tasty.type]): String = s.showTree(tree)
13+
def show(implicit ctx: Context): String = showExtractors.showTree(tree)
14+
def showCode(implicit ctx: Context): String = showSourceCode.showTree(tree)
1415
}
1516

1617
/** Adds `show` as an extension method of a `TypeOrBoundsTree` */
1718
def TypeOrBoundsTreeShowDeco(tpt: TypeOrBoundsTree): ShowAPI = new ShowAPI {
18-
def show(implicit ctx: Context, s: Show[tasty.type]): String = s.showTypeOrBoundsTree(tpt)
19+
def show(implicit ctx: Context): String = showExtractors.showTypeOrBoundsTree(tpt)
20+
def showCode(implicit ctx: Context): String = showSourceCode.showTypeOrBoundsTree(tpt)
1921
}
2022

2123
/** Adds `show` as an extension method of a `TypeOrBounds` */
2224
def TypeOrBoundsShowDeco(tpe: TypeOrBounds): ShowAPI = new ShowAPI {
23-
def show(implicit ctx: Context, s: Show[tasty.type]): String = s.showTypeOrBounds(tpe)
25+
def show(implicit ctx: Context): String = showExtractors.showTypeOrBounds(tpe)
26+
def showCode(implicit ctx: Context): String = showSourceCode.showTypeOrBounds(tpe)
2427
}
2528

2629
/** Adds `show` as an extension method of a `CaseDef` */
2730
def CaseDefShowDeco(caseDef: CaseDef): ShowAPI = new ShowAPI {
28-
def show(implicit ctx: Context, s: Show[tasty.type]): String = s.showCaseDef(caseDef)
31+
def show(implicit ctx: Context): String = showExtractors.showCaseDef(caseDef)
32+
def showCode(implicit ctx: Context): String = showSourceCode.showCaseDef(caseDef)
2933
}
3034

3135
/** Adds `show` as an extension method of a `Pattern` */
3236
def PatternShowDeco(pattern: Pattern): ShowAPI = new ShowAPI {
33-
def show(implicit ctx: Context, s: Show[tasty.type]): String = s.showPattern(pattern)
37+
def show(implicit ctx: Context): String = showExtractors.showPattern(pattern)
38+
def showCode(implicit ctx: Context): String = showSourceCode.showPattern(pattern)
3439
}
3540

3641
/** Adds `show` as an extension method of a `Constant` */
3742
def ConstantShowDeco(const: Constant): ShowAPI = new ShowAPI {
38-
def show(implicit ctx: Context, s: Show[tasty.type]): String = s.showConstant(const)
43+
def show(implicit ctx: Context): String = showExtractors.showConstant(const)
44+
def showCode(implicit ctx: Context): String = showSourceCode.showConstant(const)
3945
}
4046

4147
/** Adds `show` as an extension method of a `Symbol` */
4248
def SymbolShowDeco(symbol: Symbol): ShowAPI = new ShowAPI {
43-
def show(implicit ctx: Context, s: Show[tasty.type]): String = s.showSymbol(symbol)
49+
def show(implicit ctx: Context): String = showExtractors.showSymbol(symbol)
50+
def showCode(implicit ctx: Context): String = showSourceCode.showSymbol(symbol)
4451
}
4552

4653
}

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

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
package scala.tasty
22
package reflect
33

4-
import scala.tasty.util.Show
5-
6-
trait Printers { reflect: Reflection =>
7-
// TASTy 🎂 needed to for the path dependency `tasty.type` to make sure the
8-
// implicit printers of different instances of Tasty are not used.
9-
10-
/** Printer that prints the tree as extractors (enabled by default) */
11-
implicit def showExtractors: Show[reflect.type]
12-
13-
/** Printer that prints the tree as source code */
14-
def showSourceCode: Show[reflect.type]
4+
trait Printers extends ReflectionCore {
155

166
/** Adds `show` as an extension method of a `Tree` */
177
implicit def TreeShowDeco(tree: Tree): ShowAPI
@@ -36,10 +26,11 @@ trait Printers { reflect: Reflection =>
3626

3727
/** Define `show` as method */
3828
trait ShowAPI {
39-
/** Shows the string representation based on an implicit instance of `Show[tasty.type]`
40-
* See: `showExtractors` and `showSourceCode`
41-
*/
42-
def show(implicit ctx: Context, s: Show[reflect.type]): String
29+
/** Shows the tree as extractors */
30+
def show(implicit ctx: Context): String
31+
32+
/** Shows the tree as source code */
33+
def showCode(implicit ctx: Context): String
4334
}
4435

4536
}

library/src/scala/tasty/util/ShowExtractors.scala renamed to library/src/scala/tasty/util/ExtractorsPrinter.scala

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

33
import scala.tasty.Reflection
44

5-
class ShowExtractors[R <: Reflection with Singleton](reclect0: R) extends Show[R](reclect0) {
5+
class ExtractorsPrinter[R <: Reflection with Singleton](reclect0: R) extends Printer[R](reclect0) {
66
import reflect.{rootContext => _, _}
77

88
def showTree(tree: Tree)(implicit ctx: Context): String =

library/src/scala/tasty/util/Show.scala renamed to library/src/scala/tasty/util/Printer.scala

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

33
import scala.tasty.Reflection
44

5-
abstract class Show[R <: Reflection with Singleton](val reflect: R) {
5+
abstract class Printer[R <: Reflection with Singleton](val reflect: R) {
66

77
def showTree(tree: reflect.Tree)(implicit ctx: reflect.Context): String
88

library/src/scala/tasty/util/ShowSourceCode.scala renamed to library/src/scala/tasty/util/SourceCodePrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package util
44
import scala.annotation.switch
55
import scala.tasty.util.SyntaxHighlightUtils._
66

7-
class ShowSourceCode[R <: Reflection with Singleton](reflect0: R) extends Show[R](reflect0) {
7+
class SourceCodePrinter[R <: Reflection with Singleton](reflect0: R) extends Printer[R](reflect0) {
88
import reflect.{rootContext => _, _}
99

1010
private[this] val color: Boolean = {

tests/run-separate-compilation/tasty-custom-show/quoted_1.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import scala.quoted._
22

33
import scala.tasty.Reflection
4-
import scala.tasty.util.{TreeTraverser, Show}
4+
import scala.tasty.util.{TreeTraverser, Printer}
55

66
object Macros {
77

@@ -16,17 +16,17 @@ object Macros {
1616
val output = new TreeTraverser(reflect) {
1717
override def traverseTree(tree: Tree)(implicit ctx: Context): Unit = {
1818
// Use custom Show[_] here
19-
implicit val printer = new DummyShow(reflect)
19+
val printer = new DummyShow(reflect)
2020
tree match {
2121
case IsDefinition(tree @ DefDef(name, _, _, _, _)) =>
2222
buff.append(name)
2323
buff.append("\n")
24-
buff.append(tree.show)
24+
buff.append(printer.showTree(tree))
2525
buff.append("\n\n")
2626
case IsDefinition(tree @ ValDef(name, _, _)) =>
2727
buff.append(name)
2828
buff.append("\n")
29-
buff.append(tree.show)
29+
buff.append(printer.showTree(tree))
3030
buff.append("\n\n")
3131
case _ =>
3232
}
@@ -41,7 +41,7 @@ object Macros {
4141

4242
}
4343

44-
class DummyShow[R <: Reflection with Singleton](reflect0: R) extends Show[R](reflect0) {
44+
class DummyShow[R <: Reflection with Singleton](reflect0: R) extends Printer[R](reflect0) {
4545
import reflect._
4646
def showTree(tree: Tree)(implicit ctx: Context): String = "Tree"
4747
def showCaseDef(caseDef: CaseDef)(implicit ctx: Context): String = "CaseDef"

tests/run-separate-compilation/xml-interpolation-1/XmlQuote_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ object XmlQuote {
2222
// for debugging purpose
2323
def pp(tree: Tree): Unit = {
2424
println(tree.show)
25-
println(reflect.showSourceCode.showTree(tree))
25+
println(tree.showCode)
2626
}
2727

2828
def liftListOfAny(lst: List[Term]): Expr[List[Any]] = lst match {

tests/run-separate-compilation/xml-interpolation-2/XmlQuote_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ object XmlQuote {
2121
// for debugging purpose
2222
def pp(tree: Tree): Unit = {
2323
println(tree.show)
24-
println(reflect.showSourceCode.showTree(tree))
24+
println(tree.showCode)
2525
}
2626

2727
def isSCOpsConversion(tree: Term) =

0 commit comments

Comments
 (0)