@@ -433,7 +433,7 @@ trait Printers
433
433
(new Buffer ).printPattern(pattern).result()
434
434
435
435
def showTypeOrBounds (tpe : TypeOrBounds )(implicit ctx : Context ): String =
436
- (new Buffer ).printTypeOrBound(tpe).result()
436
+ (new Buffer ).printTypeOrBound(tpe)( None ) .result()
437
437
438
438
def showConstant (const : Constant )(implicit ctx : Context ): String =
439
439
(new Buffer ).printConstant(const).result()
@@ -516,7 +516,7 @@ trait Printers
516
516
def lineBreak (): String = " \n " + (" " * indent)
517
517
def doubleLineBreak (): String = " \n\n " + (" " * indent)
518
518
519
- def printTree (tree : Tree ): Buffer = tree match {
519
+ def printTree (tree : Tree )( implicit elideThis : Option [ Symbol ] = None ) : Buffer = tree match {
520
520
case PackageObject (body)=>
521
521
printTree(body) // Print package object
522
522
@@ -582,19 +582,19 @@ trait Printers
582
582
583
583
def printParent (parent : Tree /* Term | TypeTree */ , needEmptyParens : Boolean = false ): Unit = parent match {
584
584
case IsTypeTree (parent) =>
585
- printTypeTree(parent)
585
+ printTypeTree(parent)( Some (cdef.symbol))
586
586
case IsTerm (Term .TypeApply (fun, targs)) =>
587
587
printParent(fun)
588
588
case IsTerm (Term .Apply (fun@ Term .Apply (_,_), args)) =>
589
589
printParent(fun, true )
590
590
if (! args.isEmpty || needEmptyParens)
591
- inParens(printTrees(args, " , " ))
591
+ inParens(printTrees(args, " , " )( Some (cdef.symbol)) )
592
592
case IsTerm (Term .Apply (fun, args)) =>
593
593
printParent(fun)
594
594
if (! args.isEmpty || needEmptyParens)
595
- inParens(printTrees(args, " , " ))
595
+ inParens(printTrees(args, " , " )( Some (cdef.symbol)) )
596
596
case IsTerm (Term .Select (Term .IsNew (newTree), _)) =>
597
- printType(newTree.tpe)
597
+ printType(newTree.tpe)( Some (cdef.symbol))
598
598
case IsTerm (parent) =>
599
599
throw new MatchError (parent.show)
600
600
}
@@ -646,7 +646,7 @@ trait Printers
646
646
indented {
647
647
val name1 = if (name == " _" ) " this" else name
648
648
this += " " += highlightValDef(name1, color) += " : "
649
- printTypeTree(tpt)
649
+ printTypeTree(tpt)( Some (cdef.symbol))
650
650
this += " =>"
651
651
}
652
652
}
@@ -971,7 +971,7 @@ trait Printers
971
971
(flatStats.result(), flatExpr)
972
972
}
973
973
974
- def printFlatBlock (stats : List [Statement ], expr : Term ): Buffer = {
974
+ def printFlatBlock (stats : List [Statement ], expr : Term )( implicit elideThis : Option [ Symbol ]) : Buffer = {
975
975
val (stats1, expr1) = flatBlock(stats, expr)
976
976
// Remove Term.Lambda nodes, lambdas are printed by their definition
977
977
val stats2 = stats1.filter { case Term .Lambda (_, _) => false ; case _ => true }
@@ -992,7 +992,7 @@ trait Printers
992
992
}
993
993
}
994
994
995
- def printStats (stats : List [Tree ], expr : Tree ): Unit = {
995
+ def printStats (stats : List [Tree ], expr : Tree )( implicit elideThis : Option [ Symbol ]) : Unit = {
996
996
def printSeparator (next : Tree ): Unit = {
997
997
// Avoid accidental application of opening `{` on next line with a double break
998
998
def rec (next : Tree ): Unit = next match {
@@ -1039,13 +1039,13 @@ trait Printers
1039
1039
this
1040
1040
}
1041
1041
1042
- def printTrees (trees : List [Tree ], sep : String ): Buffer =
1043
- printList(trees, sep, printTree)
1042
+ def printTrees (trees : List [Tree ], sep : String )( implicit elideThis : Option [ Symbol ]) : Buffer =
1043
+ printList(trees, sep, ( t : Tree ) => printTree(t) )
1044
1044
1045
- def printTypeTrees (trees : List [TypeTree ], sep : String ): Buffer =
1046
- printList(trees, sep, printTypeTree)
1045
+ def printTypeTrees (trees : List [TypeTree ], sep : String )( implicit elideThis : Option [ Symbol ] = None ) : Buffer =
1046
+ printList(trees, sep, ( t : TypeTree ) => printTypeTree(t) )
1047
1047
1048
- def printTypes (trees : List [Type ], sep : String ): Buffer = {
1048
+ def printTypes (trees : List [Type ], sep : String )( implicit elideThis : Option [ Symbol ]) : Buffer = {
1049
1049
def printSeparated (list : List [Type ]): Unit = list match {
1050
1050
case Nil =>
1051
1051
case x :: Nil => printType(x)
@@ -1111,7 +1111,7 @@ trait Printers
1111
1111
this
1112
1112
}
1113
1113
1114
- def printTypesOrBounds (types : List [TypeOrBounds ], sep : String ): Buffer = {
1114
+ def printTypesOrBounds (types : List [TypeOrBounds ], sep : String )( implicit elideThis : Option [ Symbol ]) : Buffer = {
1115
1115
def printSeparated (list : List [TypeOrBounds ]): Unit = list match {
1116
1116
case Nil =>
1117
1117
case x :: Nil => printTypeOrBound(x)
@@ -1124,7 +1124,7 @@ trait Printers
1124
1124
this
1125
1125
}
1126
1126
1127
- def printTargsDefs (targs : List [(TypeDef , TypeDef )], isDef: Boolean = true ): Unit = {
1127
+ def printTargsDefs (targs : List [(TypeDef , TypeDef )], isDef: Boolean = true )( implicit elideThis : Option [ Symbol ]) : Unit = {
1128
1128
if (! targs.isEmpty) {
1129
1129
def printSeparated (list : List [(TypeDef , TypeDef )]): Unit = list match {
1130
1130
case Nil =>
@@ -1139,7 +1139,7 @@ trait Printers
1139
1139
}
1140
1140
}
1141
1141
1142
- def printTargDef (arg : (TypeDef , TypeDef ), isMember : Boolean = false , isDef: Boolean = true ): Buffer = {
1142
+ def printTargDef (arg : (TypeDef , TypeDef ), isMember : Boolean = false , isDef: Boolean = true )( implicit elideThis : Option [ Symbol ]) : Buffer = {
1143
1143
val (argDef, argCons) = arg
1144
1144
1145
1145
if (isDef) {
@@ -1189,7 +1189,7 @@ trait Printers
1189
1189
}
1190
1190
}
1191
1191
1192
- def printArgsDefs (args : List [ValDef ]): Unit = inParens {
1192
+ def printArgsDefs (args : List [ValDef ])( implicit elideThis : Option [ Symbol ]) : Unit = inParens {
1193
1193
args match {
1194
1194
case Nil =>
1195
1195
case arg :: _ =>
@@ -1209,7 +1209,7 @@ trait Printers
1209
1209
printSeparated(args)
1210
1210
}
1211
1211
1212
- def printAnnotations (trees : List [Term ]): Buffer = {
1212
+ def printAnnotations (trees : List [Term ])( implicit elideThis : Option [ Symbol ]) : Buffer = {
1213
1213
def printSeparated (list : List [Term ]): Unit = list match {
1214
1214
case Nil =>
1215
1215
case x :: Nil => printAnnotation(x)
@@ -1222,7 +1222,7 @@ trait Printers
1222
1222
this
1223
1223
}
1224
1224
1225
- def printParamDef (arg : ValDef ): Unit = {
1225
+ def printParamDef (arg : ValDef )( implicit elideThis : Option [ Symbol ]) : Unit = {
1226
1226
val name = arg.name
1227
1227
arg.symbol.owner match {
1228
1228
case IsDefSymbol (sym) if sym.name == " <init>" =>
@@ -1260,7 +1260,7 @@ trait Printers
1260
1260
indented {
1261
1261
caseDef.rhs match {
1262
1262
case Term .Block (stats, expr) =>
1263
- printStats(stats, expr)
1263
+ printStats(stats, expr)( None )
1264
1264
case body =>
1265
1265
this += lineBreak()
1266
1266
printTree(body)
@@ -1334,7 +1334,7 @@ trait Printers
1334
1334
this += highlightLiteral(" '" + v.name, color)
1335
1335
}
1336
1336
1337
- def printTypeOrBoundsTree (tpt : Tree /* TypeTree | TypeBoundsTree */ ): Buffer = tpt match {
1337
+ def printTypeOrBoundsTree (tpt : Tree )( implicit elideThis : Option [ Symbol ] = None ): Buffer = tpt match {
1338
1338
case TypeBoundsTree (lo, hi) =>
1339
1339
this += " _ >: "
1340
1340
printTypeTree(lo)
@@ -1346,7 +1346,15 @@ trait Printers
1346
1346
printTypeTree(tpt)
1347
1347
}
1348
1348
1349
- def printTypeTree (tree : TypeTree ): Buffer = tree match {
1349
+ /** Print type tree
1350
+ *
1351
+ * @param elideThis Shoud printing elide `C.this` for the given class `C`?
1352
+ * None means no eliding.
1353
+ *
1354
+ * Self type annotation and types in parent list should elide current class
1355
+ * prefix `C.this` to avoid type checking errors.
1356
+ */
1357
+ def printTypeTree (tree : TypeTree )(implicit elideThis : Option [Symbol ] = None ): Buffer = tree match {
1350
1358
case TypeTree .Inferred () =>
1351
1359
// TODO try to move this logic into `printType`
1352
1360
def printTypeAndAnnots (tpe : Type ): Buffer = tpe match {
@@ -1432,7 +1440,7 @@ trait Printers
1432
1440
1433
1441
}
1434
1442
1435
- def printTypeOrBound (tpe : TypeOrBounds ): Buffer = tpe match {
1443
+ def printTypeOrBound (tpe : TypeOrBounds )( implicit elideThis : Option [ Symbol ]) : Buffer = tpe match {
1436
1444
case tpe@ TypeBounds (lo, hi) =>
1437
1445
this += " _ >: "
1438
1446
printType(lo)
@@ -1441,7 +1449,15 @@ trait Printers
1441
1449
case IsType (tpe) => printType(tpe)
1442
1450
}
1443
1451
1444
- def printType (tpe : Type ): Buffer = tpe match {
1452
+ /** Print type
1453
+ *
1454
+ * @param elideThis Shoud printing elide `C.this` for the given class `C`?
1455
+ * None means no eliding.
1456
+ *
1457
+ * Self type annotation and types in parent list should elide current class
1458
+ * prefix `C.this` to avoid type checking errors.
1459
+ */
1460
+ def printType (tpe : Type )(implicit elideThis : Option [Symbol ] = None ): Buffer = tpe match {
1445
1461
case Type .ConstantType (const) =>
1446
1462
printConstant(const)
1447
1463
@@ -1458,6 +1474,8 @@ trait Printers
1458
1474
case IsType (prefix @ Type .SymRef (IsClassSymbol (_), _)) =>
1459
1475
printType(prefix)
1460
1476
this += " #"
1477
+ case IsType (Type .ThisType (Type .SymRef (cdef, _)))
1478
+ if elideThis.nonEmpty && cdef == elideThis.get =>
1461
1479
case IsType (prefix) =>
1462
1480
printType(prefix)
1463
1481
this += " ."
@@ -1590,7 +1608,7 @@ trait Printers
1590
1608
case PackageDef (name, _) => this += highlightTypeDef(name, color)
1591
1609
}
1592
1610
1593
- def printAnnotation (annot : Term ): Buffer = {
1611
+ def printAnnotation (annot : Term )( implicit elideThis : Option [ Symbol ]) : Buffer = {
1594
1612
val Annotation (ref, args) = annot
1595
1613
this += " @"
1596
1614
printTypeTree(ref)
@@ -1600,7 +1618,7 @@ trait Printers
1600
1618
inParens(printTrees(args, " , " ))
1601
1619
}
1602
1620
1603
- def printDefAnnotations (definition : Definition ): Buffer = {
1621
+ def printDefAnnotations (definition : Definition )( implicit elideThis : Option [ Symbol ]) : Buffer = {
1604
1622
val annots = definition.symbol.annots.filter {
1605
1623
case Annotation (annot, _) =>
1606
1624
annot.tpe match {
@@ -1615,7 +1633,7 @@ trait Printers
1615
1633
else this
1616
1634
}
1617
1635
1618
- def printRefinement (tpe : Type ): Buffer = {
1636
+ def printRefinement (tpe : Type )( implicit elideThis : Option [ Symbol ]) : Buffer = {
1619
1637
def printMethodicType (tp : TypeOrBounds ): Unit = tp match {
1620
1638
case tp @ Type .MethodType (paramNames, params, res) =>
1621
1639
inParens(printMethodicTypeParams(paramNames, params))
@@ -1655,7 +1673,7 @@ trait Printers
1655
1673
this += lineBreak() += " }"
1656
1674
}
1657
1675
1658
- def printMethodicTypeParams (paramNames : List [String ], params : List [TypeOrBounds ]): Unit = {
1676
+ def printMethodicTypeParams (paramNames : List [String ], params : List [TypeOrBounds ])( implicit elideThis : Option [ Symbol ]) : Unit = {
1659
1677
def printInfo (info : TypeOrBounds ) = info match {
1660
1678
case IsTypeBounds (info) => printBounds(info)
1661
1679
case IsType (info) =>
@@ -1676,7 +1694,7 @@ trait Printers
1676
1694
printSeparated(paramNames.zip(params))
1677
1695
}
1678
1696
1679
- def printBoundsTree (bounds : TypeBoundsTree ): Buffer = {
1697
+ def printBoundsTree (bounds : TypeBoundsTree )( implicit elideThis : Option [ Symbol ]) : Buffer = {
1680
1698
bounds.low match {
1681
1699
case TypeTree .Inferred () =>
1682
1700
case low =>
@@ -1691,7 +1709,7 @@ trait Printers
1691
1709
}
1692
1710
}
1693
1711
1694
- def printBounds (bounds : TypeBounds ): Buffer = {
1712
+ def printBounds (bounds : TypeBounds )( implicit elideThis : Option [ Symbol ]) : Buffer = {
1695
1713
this += " >: "
1696
1714
printType(bounds.low)
1697
1715
this += " <: "
0 commit comments