Skip to content

Commit 5643de4

Browse files
author
Tobias Bordenca
committed
added withColor param to Show's methods, pass scala setting for it in decompiler
1 parent b5d9ef3 commit 5643de4

File tree

4 files changed

+27
-26
lines changed

4 files changed

+27
-26
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ class DecompilationPrinter extends Phase {
3636

3737
private def printToOutput(out: PrintStream)(implicit ctx: Context): Unit = {
3838
val unit = ctx.compilationUnit
39+
val useColors = ctx.settings.color.value == "always"
3940
if (ctx.settings.printTasty.value) {
4041
new TastyPrinter(unit.pickled.head._2).printContents()
4142
} else {
4243
out.println(s"/** Decompiled from $unit */")
43-
out.println(new TastyImpl(ctx).showSourceCode.showTree(unit.tpdTree)(ctx))
44+
out.println(new TastyImpl(ctx).showSourceCode.showTree(unit.tpdTree, useColors)(ctx))
4445
}
4546
}
4647
}

library/src/scala/tasty/util/Show.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import scala.tasty.Tasty
44

55
abstract class Show[T <: Tasty with Singleton](val tasty: T) {
66

7-
def showTree(tree: tasty.Tree)(implicit ctx: tasty.Context): String
7+
def showTree(tree: tasty.Tree, withColors: Boolean = false)(implicit ctx: tasty.Context): String
88

9-
def showCaseDef(caseDef: tasty.CaseDef)(implicit ctx: tasty.Context): String
9+
def showCaseDef(caseDef: tasty.CaseDef, withColors: Boolean = false)(implicit ctx: tasty.Context): String
1010

11-
def showPattern(pattern: tasty.Pattern)(implicit ctx: tasty.Context): String
11+
def showPattern(pattern: tasty.Pattern, withColors: Boolean = false)(implicit ctx: tasty.Context): String
1212

13-
def showTypeOrBoundsTree(tpt: tasty.TypeOrBoundsTree)(implicit ctx: tasty.Context): String
13+
def showTypeOrBoundsTree(tpt: tasty.TypeOrBoundsTree, withColors: Boolean = false)(implicit ctx: tasty.Context): String
1414

15-
def showTypeOrBounds(tpe: tasty.TypeOrBounds)(implicit ctx: tasty.Context): String
15+
def showTypeOrBounds(tpe: tasty.TypeOrBounds, withColors: Boolean = false)(implicit ctx: tasty.Context): String
1616

17-
def showConstant(const: tasty.Constant)(implicit ctx: tasty.Context): String
17+
def showConstant(const: tasty.Constant, withColors: Boolean = false)(implicit ctx: tasty.Context): String
1818

1919
def showSymbol(symbol: tasty.Symbol)(implicit ctx: tasty.Context): String
2020

library/src/scala/tasty/util/ShowExtractors.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@ import scala.tasty.Tasty
55
class ShowExtractors[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty0) {
66
import tasty.{rootContext => _, _}
77

8-
def showTree(tree: Tree)(implicit ctx: Context): String =
8+
def showTree(tree: Tree, withColors: Boolean = false)(implicit ctx: Context): String =
99
new Buffer().visitTree(tree).result()
1010

11-
def showCaseDef(caseDef: CaseDef)(implicit ctx: Context): String =
11+
def showCaseDef(caseDef: CaseDef, withColors: Boolean = false)(implicit ctx: Context): String =
1212
new Buffer().visitCaseDef(caseDef).result()
1313

14-
def showPattern(pattern: tasty.Pattern)(implicit ctx: tasty.Context): String =
14+
def showPattern(pattern: tasty.Pattern, withColors: Boolean = false)(implicit ctx: tasty.Context): String =
1515
new Buffer().visitPattern(pattern).result()
1616

17-
def showTypeOrBoundsTree(tpt: TypeOrBoundsTree)(implicit ctx: Context): String =
17+
def showTypeOrBoundsTree(tpt: TypeOrBoundsTree, withColors: Boolean = false)(implicit ctx: Context): String =
1818
new Buffer().visitTypeTree(tpt).result()
1919

20-
def showTypeOrBounds(tpe: TypeOrBounds)(implicit ctx: Context): String =
20+
def showTypeOrBounds(tpe: TypeOrBounds, withColors: Boolean = false)(implicit ctx: Context): String =
2121
new Buffer().visitType(tpe).result()
2222

23-
def showConstant(const: Constant)(implicit ctx: Context): String =
23+
def showConstant(const: Constant, withColors: Boolean = false)(implicit ctx: Context): String =
2424
new Buffer().visitConstant(const).result()
2525

2626
def showSymbol(symbol: Symbol)(implicit ctx: Context): String =

library/src/scala/tasty/util/ShowSourceCode.scala

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@ import scala.annotation.switch
66
class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty0) {
77
import tasty.{rootContext => _, _}
88

9-
def showTree(tree: Tree)(implicit ctx: Context): String =
10-
(new Buffer).printTree(tree).result()
9+
def showTree(tree: Tree, withColors: Boolean = false)(implicit ctx: Context): String =
10+
(new Buffer(withColors)).printTree(tree).result()
1111

12-
def showCaseDef(caseDef: CaseDef)(implicit ctx: Context): String =
13-
(new Buffer).printCaseDef(caseDef).result()
12+
def showCaseDef(caseDef: CaseDef, withColors: Boolean = false)(implicit ctx: Context): String =
13+
(new Buffer(withColors)).printCaseDef(caseDef).result()
1414

15-
def showPattern(pattern: Pattern)(implicit ctx: Context): String =
16-
(new Buffer).printPattern(pattern).result()
15+
def showPattern(pattern: Pattern, withColors: Boolean = false)(implicit ctx: Context): String =
16+
(new Buffer(withColors)).printPattern(pattern).result()
1717

18-
def showTypeOrBoundsTree(tpt: TypeOrBoundsTree)(implicit ctx: Context): String =
19-
(new Buffer).printTypeOrBoundsTree(tpt).result()
18+
def showTypeOrBoundsTree(tpt: TypeOrBoundsTree, withColors: Boolean = false)(implicit ctx: Context): String =
19+
(new Buffer(withColors)).printTypeOrBoundsTree(tpt).result()
2020

21-
def showTypeOrBounds(tpe: TypeOrBounds)(implicit ctx: Context): String =
22-
(new Buffer).printTypeOrBound(tpe).result()
21+
def showTypeOrBounds(tpe: TypeOrBounds, withColors: Boolean = false)(implicit ctx: Context): String =
22+
(new Buffer(withColors)).printTypeOrBound(tpe).result()
2323

24-
def showConstant(const: Constant)(implicit ctx: Context): String =
25-
(new Buffer).printConstant(const).result()
24+
def showConstant(const: Constant, withColors: Boolean = false)(implicit ctx: Context): String =
25+
(new Buffer(withColors)).printConstant(const).result()
2626

2727
def showSymbol(symbol: Symbol)(implicit ctx: Context): String =
2828
symbol.fullName
2929

30-
private class Buffer(implicit ctx: Context) {
30+
private class Buffer(withColors: Boolean)(implicit ctx: Context) {
3131

3232
private[this] val sb: StringBuilder = new StringBuilder
3333

0 commit comments

Comments
 (0)