@@ -8,19 +8,19 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
8
8
import tasty .{_ , given }
9
9
import syntaxHighlight ._
10
10
11
- def showTree (tree : Tree )(given ctx : Context ): String =
11
+ def showTree (tree : Tree )(using ctx : Context ): String =
12
12
(new Buffer ).printTree(tree).result()
13
13
14
- def showTypeOrBounds (tpe : TypeOrBounds )(given ctx : Context ): String =
14
+ def showTypeOrBounds (tpe : TypeOrBounds )(using ctx : Context ): String =
15
15
(new Buffer ).printTypeOrBound(tpe)(given None ).result()
16
16
17
- def showConstant (const : Constant )(given ctx : Context ): String =
17
+ def showConstant (const : Constant )(using ctx : Context ): String =
18
18
(new Buffer ).printConstant(const).result()
19
19
20
- def showSymbol (symbol : Symbol )(given ctx : Context ): String =
20
+ def showSymbol (symbol : Symbol )(using ctx : Context ): String =
21
21
symbol.fullName
22
22
23
- def showFlags (flags : Flags )(given ctx : Context ): String = {
23
+ def showFlags (flags : Flags )(using ctx : Context ): String = {
24
24
val flagList = List .newBuilder[String ]
25
25
if (flags.is(Flags .Private )) flagList += " private"
26
26
if (flags.is(Flags .Protected )) flagList += " protected"
@@ -58,7 +58,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
58
58
flagList.result().mkString(" /*" , " " , " */" )
59
59
}
60
60
61
- private class Buffer (given ctx : Context ) {
61
+ private class Buffer (using ctx : Context ) {
62
62
63
63
private [this ] val sb : StringBuilder = new StringBuilder
64
64
@@ -95,7 +95,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
95
95
def lineBreak (): String = " \n " + (" " * indent)
96
96
def doubleLineBreak (): String = " \n\n " + (" " * indent)
97
97
98
- def printTree (tree : Tree )(given elideThis : Option [Symbol ] = None ): Buffer = tree match {
98
+ def printTree (tree : Tree )(using elideThis : Option [Symbol ] = None ): Buffer = tree match {
99
99
case PackageObject (body)=>
100
100
printTree(body) // Print package object
101
101
@@ -570,7 +570,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
570
570
(flatStats.result(), flatExpr)
571
571
}
572
572
573
- def printFlatBlock (stats : List [Statement ], expr : Term )(given elideThis : Option [Symbol ]): Buffer = {
573
+ def printFlatBlock (stats : List [Statement ], expr : Term )(using elideThis : Option [Symbol ]): Buffer = {
574
574
val (stats1, expr1) = flatBlock(stats, expr)
575
575
val stats2 = stats1.filter {
576
576
case tree : TypeDef => ! tree.symbol.annots.exists(_.symbol.owner == ctx.requiredClass(" scala.internal.Quoted.quoteTypeTag" ))
@@ -587,7 +587,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
587
587
}
588
588
}
589
589
590
- def printStats (stats : List [Tree ], expr : Tree )(given eliseThis : Option [Symbol ]): Unit = {
590
+ def printStats (stats : List [Tree ], expr : Tree )(using eliseThis : Option [Symbol ]): Unit = {
591
591
def printSeparator (next : Tree ): Unit = {
592
592
// Avoid accidental application of opening `{` on next line with a double break
593
593
def rec (next : Tree ): Unit = next match {
@@ -635,13 +635,13 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
635
635
this
636
636
}
637
637
638
- def printTrees (trees : List [Tree ], sep : String )(given elideThis : Option [Symbol ]): Buffer =
638
+ def printTrees (trees : List [Tree ], sep : String )(using elideThis : Option [Symbol ]): Buffer =
639
639
printList(trees, sep, (t : Tree ) => printTree(t))
640
640
641
- def printTypeTrees (trees : List [TypeTree ], sep : String )(given elideThis : Option [Symbol ] = None ): Buffer =
641
+ def printTypeTrees (trees : List [TypeTree ], sep : String )(using elideThis : Option [Symbol ] = None ): Buffer =
642
642
printList(trees, sep, (t : TypeTree ) => printTypeTree(t))
643
643
644
- def printTypes (trees : List [Type ], sep : String )(given elideThis : Option [Symbol ]): Buffer = {
644
+ def printTypes (trees : List [Type ], sep : String )(using elideThis : Option [Symbol ]): Buffer = {
645
645
def printSeparated (list : List [Type ]): Unit = list match {
646
646
case Nil =>
647
647
case x :: Nil => printType(x)
@@ -707,7 +707,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
707
707
this
708
708
}
709
709
710
- def printTypesOrBounds (types : List [TypeOrBounds ], sep : String )(given elideThis : Option [Symbol ]): Buffer = {
710
+ def printTypesOrBounds (types : List [TypeOrBounds ], sep : String )(using elideThis : Option [Symbol ]): Buffer = {
711
711
def printSeparated (list : List [TypeOrBounds ]): Unit = list match {
712
712
case Nil =>
713
713
case x :: Nil => printTypeOrBound(x)
@@ -720,7 +720,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
720
720
this
721
721
}
722
722
723
- def printTargsDefs (targs : List [(TypeDef , TypeDef )], isDef: Boolean = true )(given elideThis : Option [Symbol ]): Unit = {
723
+ def printTargsDefs (targs : List [(TypeDef , TypeDef )], isDef: Boolean = true )(using elideThis : Option [Symbol ]): Unit = {
724
724
if (! targs.isEmpty) {
725
725
def printSeparated (list : List [(TypeDef , TypeDef )]): Unit = list match {
726
726
case Nil =>
@@ -735,7 +735,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
735
735
}
736
736
}
737
737
738
- def printTargDef (arg : (TypeDef , TypeDef ), isMember : Boolean = false , isDef: Boolean = true )(given elideThis : Option [Symbol ]): Buffer = {
738
+ def printTargDef (arg : (TypeDef , TypeDef ), isMember : Boolean = false , isDef: Boolean = true )(using elideThis : Option [Symbol ]): Buffer = {
739
739
val (argDef, argCons) = arg
740
740
741
741
if (isDef) {
@@ -785,7 +785,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
785
785
}
786
786
}
787
787
788
- def printArgsDefs (args : List [ValDef ])(given elideThis : Option [Symbol ]): Unit = {
788
+ def printArgsDefs (args : List [ValDef ])(using elideThis : Option [Symbol ]): Unit = {
789
789
val argFlags = args match {
790
790
case Nil => Flags .EmptyFlags
791
791
case arg :: _ => arg.symbol.flags
@@ -811,7 +811,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
811
811
}
812
812
}
813
813
814
- def printAnnotations (trees : List [Term ])(given elideThis : Option [Symbol ]): Buffer = {
814
+ def printAnnotations (trees : List [Term ])(using elideThis : Option [Symbol ]): Buffer = {
815
815
def printSeparated (list : List [Term ]): Unit = list match {
816
816
case Nil =>
817
817
case x :: Nil => printAnnotation(x)
@@ -824,7 +824,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
824
824
this
825
825
}
826
826
827
- def printParamDef (arg : ValDef )(given elideThis : Option [Symbol ]): Unit = {
827
+ def printParamDef (arg : ValDef )(using elideThis : Option [Symbol ]): Unit = {
828
828
val name = arg.name
829
829
val sym = arg.symbol.owner
830
830
if sym.isDefDef && sym.name == " <init>" then
@@ -943,7 +943,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
943
943
inSquare(printType(v))
944
944
}
945
945
946
- def printTypeOrBoundsTree (tpt : Tree )(given elideThis : Option [Symbol ] = None ): Buffer = tpt match {
946
+ def printTypeOrBoundsTree (tpt : Tree )(using elideThis : Option [Symbol ] = None ): Buffer = tpt match {
947
947
case TypeBoundsTree (lo, hi) =>
948
948
this += " _ >: "
949
949
printTypeTree(lo)
@@ -963,7 +963,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
963
963
* Self type annotation and types in parent list should elide current class
964
964
* prefix `C.this` to avoid type checking errors.
965
965
*/
966
- def printTypeTree (tree : TypeTree )(given elideThis : Option [Symbol ] = None ): Buffer = tree match {
966
+ def printTypeTree (tree : TypeTree )(using elideThis : Option [Symbol ] = None ): Buffer = tree match {
967
967
case Inferred () =>
968
968
// TODO try to move this logic into `printType`
969
969
def printTypeAndAnnots (tpe : Type ): Buffer = tpe match {
@@ -1049,7 +1049,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
1049
1049
1050
1050
}
1051
1051
1052
- def printTypeOrBound (tpe : TypeOrBounds )(given elideThis : Option [Symbol ]): Buffer = tpe match {
1052
+ def printTypeOrBound (tpe : TypeOrBounds )(using elideThis : Option [Symbol ]): Buffer = tpe match {
1053
1053
case tpe@ TypeBounds (lo, hi) =>
1054
1054
this += " _ >: "
1055
1055
printType(lo)
@@ -1066,7 +1066,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
1066
1066
* Self type annotation and types in parent list should elide current class
1067
1067
* prefix `C.this` to avoid type checking errors.
1068
1068
*/
1069
- def printType (tpe : Type )(given elideThis : Option [Symbol ] = None ): Buffer = tpe match {
1069
+ def printType (tpe : Type )(using elideThis : Option [Symbol ] = None ): Buffer = tpe match {
1070
1070
case ConstantType (const) =>
1071
1071
printConstant(const)
1072
1072
@@ -1226,7 +1226,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
1226
1226
case PackageDef (name, _) => this += highlightTypeDef(name)
1227
1227
}
1228
1228
1229
- def printAnnotation (annot : Term )(given elideThis : Option [Symbol ]): Buffer = {
1229
+ def printAnnotation (annot : Term )(using elideThis : Option [Symbol ]): Buffer = {
1230
1230
val Annotation (ref, args) = annot
1231
1231
if (annot.symbol.maybeOwner == ctx.requiredClass(" scala.internal.quoted.showName" )) this
1232
1232
else {
@@ -1239,7 +1239,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
1239
1239
}
1240
1240
}
1241
1241
1242
- def printDefAnnotations (definition : Definition )(given elideThis : Option [Symbol ]): Buffer = {
1242
+ def printDefAnnotations (definition : Definition )(using elideThis : Option [Symbol ]): Buffer = {
1243
1243
val annots = definition.symbol.annots.filter {
1244
1244
case Annotation (annot, _) =>
1245
1245
val sym = annot.tpe.typeSymbol
@@ -1252,7 +1252,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
1252
1252
else this
1253
1253
}
1254
1254
1255
- def printRefinement (tpe : Type )(given elideThis : Option [Symbol ]): Buffer = {
1255
+ def printRefinement (tpe : Type )(using elideThis : Option [Symbol ]): Buffer = {
1256
1256
def printMethodicType (tp : TypeOrBounds ): Unit = tp match {
1257
1257
case tp @ MethodType (paramNames, params, res) =>
1258
1258
inParens(printMethodicTypeParams(paramNames, params))
@@ -1292,7 +1292,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
1292
1292
this += lineBreak() += " }"
1293
1293
}
1294
1294
1295
- def printMethodicTypeParams (paramNames : List [String ], params : List [TypeOrBounds ])(given elideThis : Option [Symbol ]): Unit = {
1295
+ def printMethodicTypeParams (paramNames : List [String ], params : List [TypeOrBounds ])(using elideThis : Option [Symbol ]): Unit = {
1296
1296
def printInfo (info : TypeOrBounds ) = info match {
1297
1297
case info : TypeBounds => printBounds(info)
1298
1298
case info : Type =>
@@ -1313,7 +1313,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
1313
1313
printSeparated(paramNames.zip(params))
1314
1314
}
1315
1315
1316
- def printBoundsTree (bounds : TypeBoundsTree )(given elideThis : Option [Symbol ]): Buffer = {
1316
+ def printBoundsTree (bounds : TypeBoundsTree )(using elideThis : Option [Symbol ]): Buffer = {
1317
1317
bounds.low match {
1318
1318
case Inferred () =>
1319
1319
case low =>
@@ -1328,7 +1328,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
1328
1328
}
1329
1329
}
1330
1330
1331
- def printBounds (bounds : TypeBounds )(given elideThis : Option [Symbol ]): Buffer = {
1331
+ def printBounds (bounds : TypeBounds )(using elideThis : Option [Symbol ]): Buffer = {
1332
1332
this += " >: "
1333
1333
printType(bounds.low)
1334
1334
this += " <: "
@@ -1400,7 +1400,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
1400
1400
private def escapedString (str : String ): String = str flatMap escapedChar
1401
1401
}
1402
1402
1403
- private def splicedName (sym : Symbol )(given ctx : Context ): Option [String ] = {
1403
+ private def splicedName (sym : Symbol )(using ctx : Context ): Option [String ] = {
1404
1404
sym.annots.find(_.symbol.owner == ctx.requiredClass(" scala.internal.quoted.showName" )).flatMap {
1405
1405
case Apply (_, Literal (Constant (c : String )) :: Nil ) => Some (c)
1406
1406
case Apply (_, Inlined (_, _, Literal (Constant (c : String ))) :: Nil ) => Some (c)
@@ -1409,7 +1409,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
1409
1409
}
1410
1410
1411
1411
private object SpecialOp {
1412
- def unapply (arg : Tree )(given ctx : Context ): Option [(String , List [Term ])] = arg match {
1412
+ def unapply (arg : Tree )(using ctx : Context ): Option [(String , List [Term ])] = arg match {
1413
1413
case arg @ Apply (fn, args) =>
1414
1414
fn.tpe match {
1415
1415
case tpe @ TermRef (ThisType (TypeRef (_, name)), name2) if name == " <special-ops>" =>
@@ -1421,7 +1421,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
1421
1421
}
1422
1422
1423
1423
private object Annotation {
1424
- def unapply (arg : Tree )(given ctx : Context ): Option [(TypeTree , List [Term ])] = arg match {
1424
+ def unapply (arg : Tree )(using ctx : Context ): Option [(TypeTree , List [Term ])] = arg match {
1425
1425
case New (annot) => Some ((annot, Nil ))
1426
1426
case Apply (Select (New (annot), " <init>" ), args) => Some ((annot, args))
1427
1427
case Apply (TypeApply (Select (New (annot), " <init>" ), targs), args) => Some ((annot, args))
@@ -1433,14 +1433,14 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
1433
1433
private object Types {
1434
1434
1435
1435
object Sequence {
1436
- def unapply (tpe : Type )(given ctx : Context ): Option [Type ] = tpe match {
1436
+ def unapply (tpe : Type )(using ctx : Context ): Option [Type ] = tpe match {
1437
1437
case AppliedType (seq, (tp : Type ) :: Nil ) if seq.typeSymbol == ctx.requiredClass(" scala.collection.Seq" ) => Some (tp)
1438
1438
case _ => None
1439
1439
}
1440
1440
}
1441
1441
1442
1442
object Repeated {
1443
- def unapply (tpe : Type )(given ctx : Context ): Option [Type ] = tpe match {
1443
+ def unapply (tpe : Type )(using ctx : Context ): Option [Type ] = tpe match {
1444
1444
case AppliedType (rep, (tp : Type ) :: Nil ) if rep.typeSymbol == ctx.requiredClass(" scala.<repeated>" ) => Some (tp)
1445
1445
case _ => None
1446
1446
}
@@ -1449,7 +1449,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
1449
1449
}
1450
1450
1451
1451
object PackageObject {
1452
- def unapply (tree : Tree )(given ctx : Context ): Option [Tree ] = tree match {
1452
+ def unapply (tree : Tree )(using ctx : Context ): Option [Tree ] = tree match {
1453
1453
case PackageClause (_, ValDef (" package" , _, _) :: body :: Nil ) => Some (body)
1454
1454
case _ => None
1455
1455
}
0 commit comments