Skip to content

Commit 22fcbcb

Browse files
Rewrite Map.zip -> Map.zip.toMap
1 parent 6a1d39c commit 22fcbcb

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ class SetMapSrc(set: Set[Int], map: Map[Int, Int]) {
99
(set + (2, 3)).map(x => x)
1010
set + (2, 3) - 4
1111
map.mapValues(_ + 1)
12+
map.zip(List())
1213
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ class SetMapSrc(set: Set[Int], map: Map[Int, Int]) {
99
(set + 2 + 3).map(x => x)
1010
set + 2 + 3 - 4
1111
map.mapValues(_ + 1).toMap
12+
map.zip(List()).toMap
1213
}

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,17 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
7777
Symbol("_root_.scala.collection.mutable.SetLike.retain.")
7878
)
7979

80+
8081
val arrayBuilderMake =
8182
SymbolMatcher.normalized(
8283
Symbol("_root_.scala.collection.mutable.ArrayBuilder.make(Lscala/reflect/ClassTag;)Lscala/collection/mutable/ArrayBuilder;.")
8384
)
8485

86+
val mapZip =
87+
SymbolMatcher.exact(
88+
Symbol("_root_.scala.collection.IterableLike#zip(Lscala/collection/GenIterable;Lscala/collection/generic/CanBuildFrom;)Ljava/lang/Object;.")
89+
)
90+
8591
def replaceMutableSet(ctx: RuleCtx) =
8692
ctx.tree.collect {
8793
case retainSet(n: Name) =>
@@ -254,10 +260,16 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
254260
case ap @ Term.Apply(at @ Term.ApplyType(Term.Select(lhs, arrayBuilderMake(_)), args), Nil) =>
255261
val extraParens =
256262
ap.tokens.slice(at.tokens.size, ap.tokens.size)
257-
258263
ctx.removeTokens(extraParens)
259264
}.asPatch
260265
}
266+
267+
def replaceMapZip(ctx: RuleCtx): Patch = {
268+
ctx.tree.collect {
269+
case ap @ Term.Apply(Term.Select(_, mapZip(_)), List(_)) =>
270+
ctx.addRight(ap, ".toMap")
271+
}.asPatch
272+
}
261273

262274
def replaceMapMapValues(ctx: RuleCtx): Patch = {
263275
ctx.tree.collect {
@@ -280,7 +292,7 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
280292
replaceMutMapUpdated(ctx) +
281293
replaceIterableSameElements(ctx) +
282294
replaceArrayBuilderMake(ctx) +
295+
replaceMapZip(ctx) +
283296
replaceMapMapValues(ctx)
284-
285297
}
286298
}

0 commit comments

Comments
 (0)