Skip to content

Commit 404d4ab

Browse files
committed
Remove Printers abstraction
1 parent 8b2706f commit 404d4ab

File tree

7 files changed

+29
-122
lines changed

7 files changed

+29
-122
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import dotty.tools.dotc.quoted.QuoteUtils._
1414
import dotty.tools.dotc.core.Decorators._
1515

1616
import scala.quoted.QuoteContext
17-
import scala.quoted.reflect.printers.{ExtractorsPrinter, SourceCodePrinter, SyntaxHighlight}
17+
import scala.quoted.reflect.printers.{Extractors, SourceCode, SyntaxHighlight}
1818

1919
import scala.internal.quoted.PickledQuote
2020
import scala.tasty.reflect._
@@ -65,11 +65,11 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
6565
def pos: Position = self.sourcePos
6666
def symbol: Symbol = self.symbol
6767
def showExtractors: String =
68-
new ExtractorsPrinter().showTree(using QuoteContextImpl.this)(self)
68+
Extractors.showTree(using QuoteContextImpl.this)(self)
6969
def show: String =
7070
self.showWith(SyntaxHighlight.plain)
7171
def showWith(syntaxHighlight: SyntaxHighlight): String =
72-
new SourceCodePrinter(syntaxHighlight).showTree(using QuoteContextImpl.this)(self)
72+
SourceCode.showTree(using QuoteContextImpl.this)(self)(syntaxHighlight)
7373
def isExpr: Boolean =
7474
self match
7575
case TermTypeTest(self) =>
@@ -1589,13 +1589,13 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
15891589
object TypeMethodsImpl extends TypeMethods:
15901590
extension (self: TypeRepr):
15911591
def showExtractors: String =
1592-
new ExtractorsPrinter().showType(using QuoteContextImpl.this)(self)
1592+
Extractors.showType(using QuoteContextImpl.this)(self)
15931593

15941594
def show: String =
15951595
self.showWith(SyntaxHighlight.plain)
15961596

15971597
def showWith(syntaxHighlight: SyntaxHighlight): String =
1598-
new SourceCodePrinter(syntaxHighlight).showType(using QuoteContextImpl.this)(self)
1598+
SourceCode.showType(using QuoteContextImpl.this)(self)(syntaxHighlight)
15991599

16001600
def seal: scala.quoted.Type[_] =
16011601
new scala.internal.quoted.Type(Inferred(self), QuoteContextImpl.this.hashCode)
@@ -2172,11 +2172,11 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
21722172
extension (self: Constant):
21732173
def value: Any = self.value
21742174
def showExtractors: String =
2175-
new ExtractorsPrinter().showConstant(using QuoteContextImpl.this)(self)
2175+
Extractors.showConstant(using QuoteContextImpl.this)(self)
21762176
def show: String =
21772177
self.showWith(SyntaxHighlight.plain)
21782178
def showWith(syntaxHighlight: SyntaxHighlight): String =
2179-
new SourceCodePrinter(syntaxHighlight).showConstant(using QuoteContextImpl.this)(self)
2179+
SourceCode.showConstant(using QuoteContextImpl.this)(self)(syntaxHighlight)
21802180
end extension
21812181
end ConstantMethodsImpl
21822182

@@ -2395,11 +2395,11 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
23952395
def children: List[Symbol] = self.denot.children
23962396

23972397
def showExtractors: String =
2398-
new ExtractorsPrinter().showSymbol(using QuoteContextImpl.this)(self)
2398+
Extractors.showSymbol(using QuoteContextImpl.this)(self)
23992399
def show: String =
24002400
self.showWith(SyntaxHighlight.plain)
24012401
def showWith(syntaxHighlight: SyntaxHighlight): String =
2402-
new SourceCodePrinter(syntaxHighlight).showSymbol(using QuoteContextImpl.this)(self)
2402+
SourceCode.showSymbol(using QuoteContextImpl.this)(self)(syntaxHighlight)
24032403

24042404
end extension
24052405

@@ -2531,11 +2531,11 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
25312531
def |(that: Flags): Flags = dotc.core.Flags.extension_|(self)(that)
25322532
def &(that: Flags): Flags = dotc.core.Flags.extension_&(self)(that)
25332533
def showExtractors: String =
2534-
new ExtractorsPrinter().showFlags(using QuoteContextImpl.this)(self)
2534+
Extractors.showFlags(using QuoteContextImpl.this)(self)
25352535
def show: String =
25362536
self.showWith(SyntaxHighlight.plain)
25372537
def showWith(syntaxHighlight: SyntaxHighlight): String =
2538-
new SourceCodePrinter(syntaxHighlight).showFlags(using QuoteContextImpl.this)(self)
2538+
SourceCode.showFlags(using QuoteContextImpl.this)(self)(syntaxHighlight)
25392539
end extension
25402540
end FlagsMethodsImpl
25412541

library/src/scala/quoted/reflect/printers/ExtractorsPrinter.scala renamed to library/src/scala/quoted/reflect/printers/Extractors.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
package scala.quoted
22
package reflect.printers
33

4-
class ExtractorsPrinter extends Printer {
4+
object Extractors {
55

66
def showTree(using QuoteContext)(tree: qctx.reflect.Tree): String =
7-
new Buffer[qctx.type]().visitTree(tree).result()
7+
new ExtractorsPrinter[qctx.type]().visitTree(tree).result()
88

99
def showType(using QuoteContext)(tpe: qctx.reflect.TypeRepr): String =
10-
new Buffer[qctx.type]().visitType(tpe).result()
10+
new ExtractorsPrinter[qctx.type]().visitType(tpe).result()
1111

1212
def showConstant(using QuoteContext)(const: qctx.reflect.Constant): String =
13-
new Buffer[qctx.type]().visitConstant(const).result()
13+
new ExtractorsPrinter[qctx.type]().visitConstant(const).result()
1414

1515
def showSymbol(using QuoteContext)(symbol: qctx.reflect.Symbol): String =
16-
new Buffer[qctx.type]().visitSymbol(symbol).result()
16+
new ExtractorsPrinter[qctx.type]().visitSymbol(symbol).result()
1717

1818
def showFlags(using QuoteContext)(flags: qctx.reflect.Flags): String = {
1919
import qctx.reflect._
@@ -55,7 +55,7 @@ class ExtractorsPrinter extends Printer {
5555
flagList.result().mkString(" | ")
5656
}
5757

58-
private class Buffer[QCtx <: QuoteContext & Singleton](using val qctx: QCtx) { self =>
58+
private class ExtractorsPrinter[QCtx <: QuoteContext & Singleton](using val qctx: QCtx) { self =>
5959
import qctx.reflect._
6060

6161
private val sb: StringBuilder = new StringBuilder

library/src/scala/quoted/reflect/printers/Printer.scala

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

library/src/scala/quoted/reflect/printers/SourceCodePrinter.scala renamed to library/src/scala/quoted/reflect/printers/SourceCode.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,21 @@ package reflect.printers
44
import scala.annotation.switch
55

66
/** Printer for fully elaborated representation of the source code */
7-
class SourceCodePrinter(syntaxHighlight: SyntaxHighlight) extends Printer {
8-
import syntaxHighlight._
7+
object SourceCode {
98

10-
def showTree(using QuoteContext)(tree: qctx.reflect.Tree): String =
11-
(new Buffer[qctx.type]).printTree(tree).result()
9+
def showTree(using QuoteContext)(tree: qctx.reflect.Tree)(syntaxHighlight: SyntaxHighlight): String =
10+
new SourceCodePrinter[qctx.type](syntaxHighlight).printTree(tree).result()
1211

13-
def showType(using QuoteContext)(tpe: qctx.reflect.TypeRepr): String =
14-
(new Buffer[qctx.type]).printType(tpe)(using None).result()
12+
def showType(using QuoteContext)(tpe: qctx.reflect.TypeRepr)(syntaxHighlight: SyntaxHighlight): String =
13+
new SourceCodePrinter[qctx.type](syntaxHighlight).printType(tpe)(using None).result()
1514

16-
def showConstant(using QuoteContext)(const: qctx.reflect.Constant): String =
17-
(new Buffer[qctx.type]).printConstant(const).result()
15+
def showConstant(using QuoteContext)(const: qctx.reflect.Constant)(syntaxHighlight: SyntaxHighlight): String =
16+
new SourceCodePrinter[qctx.type](syntaxHighlight).printConstant(const).result()
1817

19-
def showSymbol(using QuoteContext)(symbol: qctx.reflect.Symbol): String =
18+
def showSymbol(using QuoteContext)(symbol: qctx.reflect.Symbol)(syntaxHighlight: SyntaxHighlight): String =
2019
symbol.fullName
2120

22-
def showFlags(using QuoteContext)(flags: qctx.reflect.Flags): String = {
21+
def showFlags(using QuoteContext)(flags: qctx.reflect.Flags)(syntaxHighlight: SyntaxHighlight): String = {
2322
import qctx.reflect._
2423
val flagList = List.newBuilder[String]
2524
if (flags.is(Flags.Abstract)) flagList += "abstract"
@@ -59,7 +58,8 @@ class SourceCodePrinter(syntaxHighlight: SyntaxHighlight) extends Printer {
5958
flagList.result().mkString("/*", " ", "*/")
6059
}
6160

62-
private class Buffer[QCtx <: QuoteContext & Singleton](using val qctx: QCtx) {
61+
private class SourceCodePrinter[QCtx <: QuoteContext & Singleton](syntaxHighlight: SyntaxHighlight)(using val qctx: QCtx) {
62+
import syntaxHighlight._
6363
import qctx.reflect._
6464

6565
private[this] val sb: StringBuilder = new StringBuilder

tests/run-macros/tasty-custom-show/quoted_1.scala

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

tests/run-macros/tasty-custom-show/quoted_2.scala

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

tests/run-staging/liftables.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ object Test {
1717
println(Expr("string").show)
1818
println()
1919
println(Expr(classOf[String]).show)
20-
println(Expr(summon[reflect.ClassTag[String]]).show)
20+
println(Expr(summon[scala.reflect.ClassTag[String]]).show)
2121
println()
2222
println(Expr(Array("a")).show)
2323
println(Expr(Array(true)).show)

0 commit comments

Comments
 (0)