Skip to content
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/MutSetMapSrc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ class MutSetMapSrc(map: mutable.Map[Int, Int], set: mutable.Set[Int]) {
set + 2
map + (2 -> 3)
(set + 2).size
map.updated(1, 3)
}
1 change: 1 addition & 0 deletions scalafix/output/src/main/scala/fix/MutSetMapSrc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ class MutSetMapSrc(map: mutable.Map[Int, Int], set: mutable.Set[Int]) {
set.clone() += 2
map.clone() += (2 -> 3)
(set.clone() += 2).size
map.clone() += ((1, 3))
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
val mutMapPlus = SymbolMatcher.exact(
Symbol("_root_.scala.collection.mutable.MapLike#`+`(Lscala/Tuple2;)Lscala/collection/mutable/Map;.")
)
val mutMapUpdate =
SymbolMatcher.exact(
Symbol("_root_.scala.collection.mutable.MapLike#updated(Ljava/lang/Object;Ljava/lang/Object;)Lscala/collection/mutable/Map;.")
)

def foldSymbol(isLeft: Boolean): SymbolMatcher = {
val op =
Expand Down Expand Up @@ -212,6 +216,16 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
}.asPatch
}

def replaceMutMapUpdated(ctx: RuleCtx): Patch = {
ctx.tree.collect {
case Term.Apply(Term.Select(a, up @ mutMapUpdate(_)), List(k, v)) => {
ctx.addRight(up, "clone() += (") +
ctx.removeTokens(up.tokens) +
ctx.addRight(v, ")")
}
}.asPatch
}

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

Expand All @@ -224,6 +238,7 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
replaceMutableSet(ctx) +
replaceSymbolicFold(ctx) +
replaceSetMapPlus2(ctx) +
replaceMutSetMapPlus(ctx)
replaceMutSetMapPlus(ctx) +
replaceMutMapUpdated(ctx)
}
}