@@ -586,8 +586,9 @@ trait Printers
586
586
else if (flags.is(Flags .Abstract )) this += highlightKeyword(" abstract class " , color) += highlightTypeDef(name, color)
587
587
else this += highlightKeyword(" class " , color) += highlightTypeDef(name, color)
588
588
589
+ val typeParams = stats.collect { case IsTypeDef (targ) => targ }.filter(_.symbol.isTypeParam).zip(targs)
589
590
if (! flags.is(Flags .Object )) {
590
- printTargsDefs(targs )
591
+ printTargsDefs(typeParams )
591
592
val it = argss.iterator
592
593
while (it.hasNext)
593
594
printArgsDefs(it.next())
@@ -601,15 +602,20 @@ trait Printers
601
602
if (parents1.nonEmpty)
602
603
this += highlightKeyword(" extends " , color)
603
604
604
- def printParent (parent : TermOrTypeTree ): Unit = parent match {
605
+ def printParent (parent : TermOrTypeTree , needEmptyParens : Boolean = false ): Unit = parent match {
605
606
case IsTypeTree (parent) =>
606
607
printTypeTree(parent)
607
608
case IsTerm (Term .TypeApply (fun, targs)) =>
608
609
printParent(fun)
609
610
inSquare(printTypeOrBoundsTrees(targs, " , " ))
611
+ case IsTerm (Term .Apply (fun@ Term .Apply (_,_), args)) =>
612
+ printParent(fun, true )
613
+ if (! args.isEmpty || needEmptyParens)
614
+ inParens(printTrees(args, " , " ))
610
615
case IsTerm (Term .Apply (fun, args)) =>
611
616
printParent(fun)
612
- inParens(printTrees(args, " , " ))
617
+ if (! args.isEmpty || needEmptyParens)
618
+ inParens(printTrees(args, " , " ))
613
619
case IsTerm (Term .Select (Term .New (tpt), _)) =>
614
620
printTypeTree(tpt)
615
621
case IsTerm (parent) =>
@@ -682,7 +688,7 @@ trait Printers
682
688
case IsTypeDef (tdef @ TypeDef (name, rhs)) =>
683
689
printDefAnnotations(tdef)
684
690
this += highlightKeyword(" type " , color)
685
- printTargDef(tdef, isMember = true )
691
+ printTargDef(( tdef, tdef) , isMember = true )
686
692
687
693
case IsValDef (vdef @ ValDef (name, tpt, rhs)) =>
688
694
printDefAnnotations(vdef)
@@ -743,7 +749,7 @@ trait Printers
743
749
printProtectedOrPrivate(ddef)
744
750
745
751
this += highlightKeyword(" def " , color) += highlightValDef((if (isConstructor) " this" else name), color)
746
- printTargsDefs(targs)
752
+ printTargsDefs(targs.zip(targs) )
747
753
val it = argss.iterator
748
754
while (it.hasNext)
749
755
printArgsDefs(it.next())
@@ -1105,13 +1111,13 @@ trait Printers
1105
1111
this
1106
1112
}
1107
1113
1108
- def printTargsDefs (targs : List [TypeDef ] ): Unit = {
1114
+ def printTargsDefs (targs : List [( TypeDef , TypeDef )], isDef : Boolean = true ): Unit = {
1109
1115
if (! targs.isEmpty) {
1110
- def printSeparated (list : List [TypeDef ]): Unit = list match {
1116
+ def printSeparated (list : List [( TypeDef , TypeDef ) ]): Unit = list match {
1111
1117
case Nil =>
1112
- case x :: Nil => printTargDef(x)
1118
+ case x :: Nil => printTargDef(x, isDef = isDef )
1113
1119
case x :: xs =>
1114
- printTargDef(x)
1120
+ printTargDef(x, isDef = isDef )
1115
1121
this += " , "
1116
1122
printSeparated(xs)
1117
1123
}
@@ -1120,9 +1126,19 @@ trait Printers
1120
1126
}
1121
1127
}
1122
1128
1123
- def printTargDef (arg : TypeDef , isMember : Boolean = false ): Buffer = {
1124
- this += arg.name
1125
- arg.rhs match {
1129
+ def printTargDef (arg : (TypeDef , TypeDef ), isMember : Boolean = false , isDef: Boolean = true ): Buffer = {
1130
+ val (argDef, argCons) = arg
1131
+
1132
+ if (isDef) {
1133
+ if (argDef.symbol.flags.is(Flags .Covariant )) {
1134
+ this += highlightValDef(" +" , color)
1135
+ } else if (argDef.symbol.flags.is(Flags .Contravariant )) {
1136
+ this += highlightValDef(" -" , color)
1137
+ }
1138
+ }
1139
+
1140
+ this += argCons.name
1141
+ argCons.rhs match {
1126
1142
case IsTypeBoundsTree (rhs) => printBoundsTree(rhs)
1127
1143
case rhs @ WildcardTypeTree () =>
1128
1144
printTypeOrBound(rhs.tpe)
@@ -1393,7 +1409,7 @@ trait Printers
1393
1409
printTypeTree(result)
1394
1410
1395
1411
case TypeTree .LambdaTypeTree (tparams, body) =>
1396
- printTargsDefs(tparams)
1412
+ printTargsDefs(tparams.zip(tparams), isDef = false )
1397
1413
this += highlightTypeDef(" => " , color)
1398
1414
printTypeOrBoundsTree(body)
1399
1415
0 commit comments