Skip to content

Commit e738da5

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

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

scalafix/build.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ lazy val tests = project
3737
sourceDirectory.in(output, Compile).value,
3838
"inputClassdirectory" ->
3939
classDirectory.in(input, Compile).value
40-
)
40+
),
41+
test in Test := (test in Test).dependsOn(compile in (output, Compile)).value
4142
)
4243
.dependsOn(input, rules)
4344
.enablePlugins(BuildInfoPlugin)
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{ case (x, y) => 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{ case (x, y) => 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)