@@ -590,8 +590,9 @@ trait Printers
590590 else if (flags.is(Flags .Abstract )) this += highlightKeyword(" abstract class " , color) += highlightTypeDef(name, color)
591591 else this += highlightKeyword(" class " , color) += highlightTypeDef(name, color)
592592
593+ val typeParams = stats.collect { case IsTypeDef (targ) => targ }.filter(_.symbol.isTypeParam).zip(targs)
593594 if (! flags.is(Flags .Object )) {
594- printTargsDefs(targs )
595+ printTargsDefs(typeParams )
595596 val it = argss.iterator
596597 while (it.hasNext)
597598 printArgsDefs(it.next())
@@ -606,14 +607,19 @@ trait Printers
606607 if (parents1.nonEmpty)
607608 this += highlightKeyword(" extends " , color)
608609
609- def printParent (parent : TermOrTypeTree ): Unit = parent match {
610+ def printParent (parent : TermOrTypeTree , needEmptyParens : Boolean = false ): Unit = parent match {
610611 case IsTypeTree (parent) =>
611612 printTypeTree(parent)
612613 case IsTerm (Term .TypeApply (fun, targs)) =>
613614 printParent(fun)
615+ case IsTerm (Term .Apply (fun@ Term .Apply (_,_), args)) =>
616+ printParent(fun, true )
617+ if (! args.isEmpty || needEmptyParens)
618+ inParens(printTrees(args, " , " ))
614619 case IsTerm (Term .Apply (fun, args)) =>
615620 printParent(fun)
616- inParens(printTrees(args, " , " ))
621+ if (! args.isEmpty || needEmptyParens)
622+ inParens(printTrees(args, " , " ))
617623 case IsTerm (Term .Select (Term .New (tpt), _)) =>
618624 printTypeTree(tpt)
619625 case IsTerm (parent) =>
@@ -691,7 +697,7 @@ trait Printers
691697 case IsTypeDef (tdef @ TypeDef (name, rhs)) =>
692698 printDefAnnotations(tdef)
693699 this += highlightKeyword(" type " , color)
694- printTargDef(tdef, isMember = true )
700+ printTargDef(( tdef, tdef) , isMember = true )
695701
696702 case IsValDef (vdef @ ValDef (name, tpt, rhs)) =>
697703 printDefAnnotations(vdef)
@@ -754,7 +760,7 @@ trait Printers
754760 printProtectedOrPrivate(ddef)
755761
756762 this += highlightKeyword(" def " , color) += highlightValDef((if (isConstructor) " this" else name), color)
757- printTargsDefs(targs)
763+ printTargsDefs(targs.zip(targs) )
758764 val it = argss.iterator
759765 while (it.hasNext)
760766 printArgsDefs(it.next())
@@ -1125,13 +1131,13 @@ trait Printers
11251131 this
11261132 }
11271133
1128- def printTargsDefs (targs : List [TypeDef ] ): Unit = {
1134+ def printTargsDefs (targs : List [( TypeDef , TypeDef )], isDef : Boolean = true ): Unit = {
11291135 if (! targs.isEmpty) {
1130- def printSeparated (list : List [TypeDef ]): Unit = list match {
1136+ def printSeparated (list : List [( TypeDef , TypeDef ) ]): Unit = list match {
11311137 case Nil =>
1132- case x :: Nil => printTargDef(x)
1138+ case x :: Nil => printTargDef(x, isDef = isDef )
11331139 case x :: xs =>
1134- printTargDef(x)
1140+ printTargDef(x, isDef = isDef )
11351141 this += " , "
11361142 printSeparated(xs)
11371143 }
@@ -1140,9 +1146,19 @@ trait Printers
11401146 }
11411147 }
11421148
1143- def printTargDef (arg : TypeDef , isMember : Boolean = false ): Buffer = {
1144- this += arg.name
1145- arg.rhs match {
1149+ def printTargDef (arg : (TypeDef , TypeDef ), isMember : Boolean = false , isDef: Boolean = true ): Buffer = {
1150+ val (argDef, argCons) = arg
1151+
1152+ if (isDef) {
1153+ if (argDef.symbol.flags.is(Flags .Covariant )) {
1154+ this += highlightValDef(" +" , color)
1155+ } else if (argDef.symbol.flags.is(Flags .Contravariant )) {
1156+ this += highlightValDef(" -" , color)
1157+ }
1158+ }
1159+
1160+ this += argCons.name
1161+ argCons.rhs match {
11461162 case IsTypeBoundsTree (rhs) => printBoundsTree(rhs)
11471163 case rhs @ WildcardTypeTree () =>
11481164 printTypeOrBound(rhs.tpe)
@@ -1412,7 +1428,7 @@ trait Printers
14121428 printTypeTree(result)
14131429
14141430 case TypeTree .LambdaTypeTree (tparams, body) =>
1415- printTargsDefs(tparams)
1431+ printTargsDefs(tparams.zip(tparams), isDef = false )
14161432 this += highlightTypeDef(" => " , color)
14171433 printTypeOrBoundsTree(body)
14181434
@@ -1576,7 +1592,10 @@ trait Printers
15761592 val Annotation (ref, args) = annot
15771593 this += " @"
15781594 printTypeTree(ref)
1579- inParens(printTrees(args, " , " ))
1595+ if (args.isEmpty)
1596+ this
1597+ else
1598+ inParens(printTrees(args, " , " ))
15801599 }
15811600
15821601 def printDefAnnotations (definition : Definition ): Buffer = {
0 commit comments