Skip to content

Commit 3174d0d

Browse files
committed
handle scalameta change in ApplyInfix RHS positions
scalameta/scalameta#2684, first released in scalameta 4.5.1 (scalafix 0.10.0), changed a behavior, so this takes a more intrusive but also more robust approach so that the rule works with scalafix 0.10.x.
1 parent a68f614 commit 3174d0d

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ The migration rules use scalafix. Please see the [official installation instruct
5353

5454
```scala
5555
// project/plugins.sbt
56-
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.34")
56+
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.1")
5757
```
5858

5959
### Collection213Upgrade

scalafix/rules/src/main/scala/scala/fix/collection/Collection213Experimental.scala

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)