@@ -35,6 +35,12 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
35
35
val mapPlus2 = SymbolMatcher .exact(
36
36
Symbol (" _root_.scala.collection.immutable.MapLike#`+`(Lscala/Tuple2;Lscala/Tuple2;Lscala/collection/Seq;)Lscala/collection/immutable/Map;." )
37
37
)
38
+ val mutSetPlus = SymbolMatcher .exact(
39
+ Symbol (" _root_.scala.collection.mutable.SetLike#`+`(Ljava/lang/Object;)Lscala/collection/mutable/Set;." )
40
+ )
41
+ val mutMapPlus = SymbolMatcher .exact(
42
+ Symbol (" _root_.scala.collection.mutable.MapLike#`+`(Lscala/Tuple2;)Lscala/collection/mutable/Map;." )
43
+ )
38
44
39
45
def foldSymbol (isLeft : Boolean ): SymbolMatcher = {
40
46
val op =
@@ -165,7 +171,6 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
165
171
166
172
def replaceSetMapPlus2 (ctx : RuleCtx ): Patch = {
167
173
def rewritePlus (ap : Term .ApplyInfix , lhs : Term , op : Term .Name , rhs1 : Term , rhs2 : Term ): Patch = {
168
-
169
174
val tokensToReplace =
170
175
if (ap.tokens.headOption.map(_.is[Token .LeftParen ]).getOrElse(false )) {
171
176
// don't drop surrounding parens
@@ -183,7 +188,6 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
183
188
ctx.removeTokens(tokensToReplace) +
184
189
tokensToReplace.headOption.map(x => ctx.addRight(x, newTree))
185
190
}
186
-
187
191
ctx.tree.collect {
188
192
case ap @ Term .ApplyInfix (lhs, op @ mapPlus2(_), _, List (a, b)) =>
189
193
rewritePlus(ap, lhs, op, a, b)
@@ -193,6 +197,21 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
193
197
}.asPatch
194
198
}
195
199
200
+ def replaceMutSetMapPlus (ctx : RuleCtx ): Patch = {
201
+ def rewriteMutPlus (lhs : Term , op : Term .Name ): Patch = {
202
+ ctx.addRight(lhs, " .clone()" ) +
203
+ ctx.addRight(op, " =" )
204
+ }
205
+
206
+ ctx.tree.collect {
207
+ case Term .ApplyInfix (lhs, op @ mutSetPlus(_), _, List (_)) =>
208
+ rewriteMutPlus(lhs, op)
209
+
210
+ case Term .ApplyInfix (lhs, op @ mutMapPlus(_), _, List (_)) =>
211
+ rewriteMutPlus(lhs, op)
212
+ }.asPatch
213
+ }
214
+
196
215
override def fix (ctx : RuleCtx ): Patch = {
197
216
// println(ctx.index.database)
198
217
@@ -204,6 +223,7 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
204
223
replaceMutableMap(ctx) +
205
224
replaceMutableSet(ctx) +
206
225
replaceSymbolicFold(ctx) +
207
- replaceSetMapPlus2(ctx)
226
+ replaceSetMapPlus2(ctx) +
227
+ replaceMutSetMapPlus(ctx)
208
228
}
209
229
}
0 commit comments