Skip to content

Commit

Permalink
Merge pull request #549 from bjaglin/update/sbt-scalafix-0.10.0
Browse files Browse the repository at this point in the history
scalafix 0.10.1
  • Loading branch information
SethTisue committed Jul 26, 2022
2 parents a3411ab + 3174d0d commit a7a85c3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ The migration rules use scalafix. Please see the [official installation instruct

```scala
// project/plugins.sbt
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.34")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.1")
```

### Collection213Upgrade
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.2.0
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.5")
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.2.0")
addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "3.0.1")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.34")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.1")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,29 @@ case class Collection213ExperimentalV0(index: SemanticdbIndex)
}

def replaceSetMapPlusMinus(ctx: RuleCtx): Patch = {
def rewriteOp(op: Tree, rhs: Tree, doubleOp: String, col0: String): Patch = {
val col = "_root_.scala.collection." + col0
val callSite =
if (startsWithParens(rhs)) {
ctx.addLeft(rhs, col)
} else {
ctx.addLeft(rhs, col + "(") +
ctx.addRight(rhs, ")")
}

ctx.addRight(op, doubleOp) + callSite
def rewriteOp(ap: Term.ApplyInfix, doubleOp: String, col0: String): Patch = {
val col = col0 match {
case "Set" => q"_root_.scala.collection.Set"
case "Map" => q"_root_.scala.collection.Map"
}
val newAp = ap
.copy(
args = Term.Apply(col, ap.args) :: Nil,
op = Term.Name(doubleOp * 2)
)
.toString()
ctx.replaceTree(ap, newAp)
}

ctx.tree.collect {
case ap @ Term.ApplyInfix(CollectionSet(), op @ setPlus(_), Nil, List(rhs)) =>
rewriteOp(op, rhs, "+", "Set")
case ap @ Term.ApplyInfix(CollectionSet(), setPlus(_), Nil, _) =>
rewriteOp(ap, "+", "Set")

case Term.ApplyInfix(CollectionSet(), op @ setMinus(_), Nil, List(rhs)) =>
rewriteOp(op, rhs, "-", "Set")
case ap @ Term.ApplyInfix(CollectionSet(), setMinus(_), Nil, _) =>
rewriteOp(ap, "-", "Set")

case Term.ApplyInfix(_, op @ mapPlus(_), Nil, List(rhs)) =>
rewriteOp(op, rhs, "+", "Map")
case ap @ Term.ApplyInfix(_, op @ mapPlus(_), Nil, _) =>
rewriteOp(ap, "+", "Map")
}.asPatch
}

Expand Down

0 comments on commit a7a85c3

Please sign in to comment.