Skip to content

Commit d25861f

Browse files
Rewrite Map.zip -> Map.zip.toMap
1 parent 58a01af commit d25861f

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

scalafix/input/src/main/scala/fix/SetMapSrc.scala

+1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ class SetMapSrc(set: Set[Int], map: Map[Int, Int]) {
88
map + (2 -> 3, 3 -> 4)
99
(set + (2, 3)).map(x => x)
1010
set + (2, 3) - 4
11+
map.zip(List())
1112
}

scalafix/output/src/main/scala/fix/SetMapSrc.scala

+1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ class SetMapSrc(set: Set[Int], map: Map[Int, Int]) {
88
map + (2 -> 3) + (3 -> 4)
99
(set + 2 + 3).map(x => x)
1010
set + 2 + 3 - 4
11+
map.zip(List()).toMap
1112
}

scalafix/rules/src/main/scala/fix/Scalacollectioncompat_newcollections.scala

+14-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
7171
Symbol("_root_.scala.collection.mutable.SetLike.retain.")
7272
)
7373

74+
val mapZip =
75+
SymbolMatcher.exact(
76+
Symbol("_root_.scala.collection.IterableLike#zip(Lscala/collection/GenIterable;Lscala/collection/generic/CanBuildFrom;)Ljava/lang/Object;.")
77+
)
78+
7479
def replaceMutableSet(ctx: RuleCtx) =
7580
ctx.tree.collect {
7681
case retainSet(n: Name) =>
@@ -238,7 +243,14 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
238243
}.asPatch
239244
}
240245

246+
def replaceMapZip(ctx: RuleCtx): Patch = {
247+
ctx.tree.collect {
248+
case ap @ Term.Apply(Term.Select(_, mapZip(_)), List(_)) =>
249+
ctx.addRight(ap, ".toMap")
241250

251+
}.asPatch
252+
}
253+
242254
override def fix(ctx: RuleCtx): Patch = {
243255
// println(ctx.index.database)
244256

@@ -253,6 +265,7 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
253265
replaceSetMapPlus2(ctx) +
254266
replaceMutSetMapPlus(ctx) +
255267
replaceMutMapUpdated(ctx) +
256-
replaceIterableSameElements(ctx)
268+
replaceIterableSameElements(ctx) +
269+
replaceMapZip(ctx)
257270
}
258271
}

0 commit comments

Comments
 (0)