File tree 6 files changed +21
-3
lines changed
compiler/src/dotty/tools/dotc/tastyreflect
tests/run/tasty-custom-show
6 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -438,6 +438,10 @@ object TastyImpl extends scala.tasty.Tasty {
438
438
439
439
def caseDefClassTag : ClassTag [CaseDef ] = implicitly[ClassTag [CaseDef ]]
440
440
441
+ def CaseDefDeco (caseDef : CaseDef ): AbstractCaseDef = new AbstractCaseDef {
442
+ def show (implicit ctx : Context , s : Show [TastyImpl .this .type ]): String = s.showCaseDef(caseDef)
443
+ }
444
+
441
445
object CaseDef extends CaseDefExtractor {
442
446
def unapply (x : CaseDef ): Option [(Pattern , Option [Term ], Term )] = x match {
443
447
case x : tpd.CaseDef @ unchecked =>
Original file line number Diff line number Diff line change @@ -310,6 +310,11 @@ abstract class Tasty { tasty =>
310
310
311
311
implicit def caseDefClassTag : ClassTag [CaseDef ]
312
312
313
+ trait AbstractCaseDef {
314
+ def show (implicit ctx : Context , s : Show [tasty.type ]): String
315
+ }
316
+ implicit def CaseDefDeco (caseDef : CaseDef ): AbstractCaseDef
317
+
313
318
val CaseDef : CaseDefExtractor
314
319
abstract class CaseDefExtractor {
315
320
def unapply (x : CaseDef ): Option [(Pattern , Option [Term ], Term )]
Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ abstract class Show[T <: Tasty with Singleton](val tasty: T) {
6
6
7
7
def showTree (tree : tasty.Tree )(implicit ctx : tasty.Context ): String
8
8
9
+ def showCaseDef (caseDef : tasty.CaseDef )(implicit ctx : tasty.Context ): String
10
+
9
11
def showTypeOrBoundsTree (tpt : tasty.TypeOrBoundsTree )(implicit ctx : tasty.Context ): String
10
12
11
13
def showTypeOrBounds (tpe : tasty.TypeOrBounds )(implicit ctx : tasty.Context ): String
Original file line number Diff line number Diff line change @@ -8,6 +8,9 @@ class ShowExtractors[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
8
8
def showTree (tree : Tree )(implicit ctx : Context ): String =
9
9
new Buffer ().visitTree(tree).result()
10
10
11
+ def showCaseDef (caseDef : CaseDef )(implicit ctx : Context ): String =
12
+ new Buffer ().visitCaseDef(caseDef).result()
13
+
11
14
def showTypeOrBoundsTree (tpt : TypeOrBoundsTree )(implicit ctx : Context ): String =
12
15
new Buffer ().visitTypeTree(tpt).result()
13
16
Original file line number Diff line number Diff line change @@ -7,6 +7,9 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
7
7
def showTree (tree : Tree )(implicit ctx : Context ): String =
8
8
(new Buffer ).printTree(tree).result()
9
9
10
+ def showCaseDef (caseDef : CaseDef )(implicit ctx : Context ): String =
11
+ (new Buffer ).printCaseDef(caseDef).result()
12
+
10
13
def showTypeOrBoundsTree (tpt : TypeOrBoundsTree )(implicit ctx : Context ): String =
11
14
(new Buffer ).printTypeOrBoundsTree(tpt).result()
12
15
@@ -351,9 +354,9 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
351
354
def printCases (cases : List [CaseDef ], sep : String ): Buffer = {
352
355
def printSeparated (list : List [CaseDef ]): Unit = list match {
353
356
case Nil =>
354
- case x :: Nil => printCase (x)
357
+ case x :: Nil => printCaseDef (x)
355
358
case x :: xs =>
356
- printCase (x)
359
+ printCaseDef (x)
357
360
this += sep
358
361
printSeparated(xs)
359
362
}
@@ -468,7 +471,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
468
471
printTypeTree(tpt)
469
472
}
470
473
471
- def printCase (caseDef : CaseDef ): Buffer = {
474
+ def printCaseDef (caseDef : CaseDef ): Buffer = {
472
475
val CaseDef (pat, guard, body) = caseDef
473
476
this += " case "
474
477
printPattern(pat)
Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ object Macros {
48
48
class DummyShow [T <: Tasty with Singleton ](tasty0 : T ) extends Show [T ](tasty0) {
49
49
import tasty ._
50
50
def showTree (tree : Tree )(implicit ctx : Context ): String = " Tree"
51
+ def showCaseDef (caseDef : CaseDef )(implicit ctx : Context ): String = " CaseDef"
51
52
def showTypeOrBoundsTree (tpt : TypeOrBoundsTree )(implicit ctx : Context ): String = " TypeOrBoundsTree"
52
53
def showTypeOrBounds (tpe : TypeOrBounds )(implicit ctx : Context ): String = " TypeOrBounds"
53
54
def showConstant (const : Constant )(implicit ctx : Context ): String = " Constant"
You can’t perform that action at this time.
0 commit comments