Skip to content

Rewrite Map.mapValues -> Map.mapValues.toMap #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scalafix/input/src/main/scala/fix/SetMapSrc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ class SetMapSrc(set: Set[Int], map: Map[Int, Int]) {
map + (2 -> 3, 3 -> 4)
(set + (2, 3)).map(x => x)
set + (2, 3) - 4
map.mapValues(_ + 1)
}
1 change: 1 addition & 0 deletions scalafix/output/src/main/scala/fix/SetMapSrc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ class SetMapSrc(set: Set[Int], map: Map[Int, Int]) {
map + (2 -> 3) + (3 -> 4)
(set + 2 + 3).map(x => x)
set + 2 + 3 - 4
map.mapValues(_ + 1).toMap
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
Symbol("_root_.scala.collection.mutable.MapLike.retain.")
)

val mapMapValues =
SymbolMatcher.exact(
Symbol("_root_.scala.collection.immutable.MapLike#mapValues(Lscala/Function1;)Lscala/collection/immutable/Map;.")
)

val retainSet =
SymbolMatcher.normalized(
Symbol("_root_.scala.collection.mutable.SetLike.retain.")
Expand Down Expand Up @@ -253,11 +258,15 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
ctx.removeTokens(extraParens)
}.asPatch
}


def replaceMapMapValues(ctx: RuleCtx): Patch = {
ctx.tree.collect {
case ap @ Term.Apply(Term.Select(_, mapMapValues(_)), List(_)) =>
ctx.addRight(ap, ".toMap")
}.asPatch
}

override def fix(ctx: RuleCtx): Patch = {
// println(ctx.index.database)

replaceToList(ctx) +
replaceSymbols(ctx) +
replaceTupleZipped(ctx) +
Expand All @@ -270,6 +279,8 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
replaceMutSetMapPlus(ctx) +
replaceMutMapUpdated(ctx) +
replaceIterableSameElements(ctx) +
replaceArrayBuilderMake(ctx)
replaceArrayBuilderMake(ctx) +
replaceMapMapValues(ctx)

}
}