@@ -53,28 +53,29 @@ case class Collection213ExperimentalV0(index: SemanticdbIndex)
5353 }
5454
5555 def replaceSetMapPlusMinus (ctx : RuleCtx ): Patch = {
56- def rewriteOp (op : Tree , rhs : Tree , doubleOp : String , col0 : String ): Patch = {
57- val col = " _root_.scala.collection." + col0
58- val callSite =
59- if (startsWithParens(rhs)) {
60- ctx.addLeft(rhs, col)
61- } else {
62- ctx.addLeft(rhs, col + " (" ) +
63- ctx.addRight(rhs, " )" )
64- }
65-
66- ctx.addRight(op, doubleOp) + callSite
56+ def rewriteOp (ap : Term .ApplyInfix , doubleOp : String , col0 : String ): Patch = {
57+ val col = col0 match {
58+ case " Set" => q " _root_.scala.collection.Set "
59+ case " Map" => q " _root_.scala.collection.Map "
60+ }
61+ val newAp = ap
62+ .copy(
63+ args = Term .Apply (col, ap.args) :: Nil ,
64+ op = Term .Name (doubleOp * 2 )
65+ )
66+ .toString()
67+ ctx.replaceTree(ap, newAp)
6768 }
6869
6970 ctx.tree.collect {
70- case ap @ Term .ApplyInfix (CollectionSet (), op @ setPlus(_), Nil , List (rhs) ) =>
71- rewriteOp(op, rhs , " +" , " Set" )
71+ case ap @ Term .ApplyInfix (CollectionSet (), setPlus(_), Nil , _ ) =>
72+ rewriteOp(ap , " +" , " Set" )
7273
73- case Term .ApplyInfix (CollectionSet (), op @ setMinus(_), Nil , List (rhs) ) =>
74- rewriteOp(op, rhs , " -" , " Set" )
74+ case ap @ Term .ApplyInfix (CollectionSet (), setMinus(_), Nil , _ ) =>
75+ rewriteOp(ap , " -" , " Set" )
7576
76- case Term .ApplyInfix (_, op @ mapPlus(_), Nil , List (rhs) ) =>
77- rewriteOp(op, rhs , " +" , " Map" )
77+ case ap @ Term .ApplyInfix (_, op @ mapPlus(_), Nil , _ ) =>
78+ rewriteOp(ap , " +" , " Map" )
7879 }.asPatch
7980 }
8081
0 commit comments