Skip to content

Commit 25b3b51

Browse files
Rewrite retain to filterInPlace (fix scala/collection-strawman #556)
1 parent 284ca71 commit 25b3b51

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
rule = "scala:fix.Scalacollectioncompat_NewCollections"
3+
*/
4+
package fix
5+
6+
import scala.collection.mutable.Map
7+
8+
object MethodRenames {
9+
Map(1 -> 1).retain((_, _) => true)
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package fix
2+
3+
import scala.collection.mutable.Map
4+
5+
object MethodRenames {
6+
Map(1 -> 1).filterInPlace((_, _) => true)
7+
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ case class Scalacollectioncompat_NewCollections(index: SemanticdbIndex)
3030
Symbol("_root_.scala.runtime.Tuple3Zipped.Ops.zipped.")
3131
)
3232

33+
val retain =
34+
SymbolMatcher.normalized(
35+
Symbol("_root_.scala.collection.mutable.MapLike.retain.")
36+
)
37+
38+
def replaceMutableMap(ctx: RuleCtx) =
39+
ctx.tree.collect {
40+
case retain(t: Name) =>
41+
ctx.replaceTree(t, "filterInPlace")
42+
}.asPatch
43+
3344
def replaceToList(ctx: RuleCtx) =
3445
ctx.tree.collect {
3546
case iterator(t: Name) =>
@@ -110,6 +121,7 @@ case class Scalacollectioncompat_NewCollections(index: SemanticdbIndex)
110121
replaceSymbols(ctx) +
111122
replaceTupleZipped(ctx) +
112123
replaceCopyToBuffer(ctx) +
113-
replaceStreamAppend(ctx)
124+
replaceStreamAppend(ctx) +
125+
replaceMutableMap(ctx)
114126
}
115127
}

0 commit comments

Comments
 (0)