@@ -8,30 +8,6 @@ import scala.meta._
8
8
case class Scalacollectioncompat_newcollections (index : SemanticdbIndex )
9
9
extends SemanticRule (index, " Scalacollectioncompat_newcollections" ) {
10
10
11
- // WARNING: TOTAL HACK
12
- // this is only to unblock us until Term.tpe is available: https://github.com/scalameta/scalameta/issues/1212
13
- // if we have a simple identifier, we can look at his definition at query it's type
14
- // this should be improved in future version of scalameta
15
- object TypeMatcher {
16
- def apply (symbols : Symbol * )(implicit index : SemanticdbIndex ): TypeMatcher =
17
- new TypeMatcher (symbols : _* )(index)
18
- }
19
-
20
- final class TypeMatcher (symbols : Symbol * )(implicit index : SemanticdbIndex ) {
21
- def unapply (tree : Tree ): Boolean = {
22
- index.denotation(tree)
23
- .exists(_.names.headOption.exists(n => symbols.exists(_ == n.symbol)))
24
- }
25
- }
26
-
27
- val CollectionMap : TypeMatcher = TypeMatcher (
28
- Symbol (" _root_.scala.collection.immutable.Map#" ),
29
- Symbol (" _root_.scala.collection.mutable.Map#" ),
30
- Symbol (" _root_.scala.Predef.Map#" )
31
- )
32
-
33
- val CollectionSet : TypeMatcher = TypeMatcher (Symbol (" _root_.scala.collection.Set#" ))
34
-
35
11
def replaceSymbols (ctx : RuleCtx ): Patch = {
36
12
ctx.replaceSymbols(
37
13
" scala.collection.LinearSeq" -> " scala.collection.immutable.List" ,
@@ -54,18 +30,6 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
54
30
Symbol (" _root_.scala.runtime.Tuple2Zipped.Ops.zipped." ),
55
31
Symbol (" _root_.scala.runtime.Tuple3Zipped.Ops.zipped." )
56
32
)
57
- val setPlus =
58
- SymbolMatcher .exact(
59
- Symbol (" _root_.scala.collection.SetLike#`+`(Ljava/lang/Object;)Lscala/collection/Set;." )
60
- )
61
- val setMinus =
62
- SymbolMatcher .exact(
63
- Symbol (" _root_.scala.collection.SetLike#`-`(Ljava/lang/Object;)Lscala/collection/Set;." )
64
- )
65
- val mapPlus =
66
- SymbolMatcher .exact(
67
- Symbol (" _root_.scala.collection.MapLike#`+`(Lscala/Tuple2;)Lscala/collection/Map;." )
68
- )
69
33
val setPlus2 = SymbolMatcher .exact(
70
34
Symbol (" _root_.scala.collection.SetLike#`+`(Ljava/lang/Object;Ljava/lang/Object;Lscala/collection/Seq;)Lscala/collection/Set;." )
71
35
)
@@ -119,11 +83,6 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
119
83
Symbol (" _root_.scala.collection.mutable.ArrayBuilder.make(Lscala/reflect/ClassTag;)Lscala/collection/mutable/ArrayBuilder;." )
120
84
)
121
85
122
- val mapZip =
123
- SymbolMatcher .exact(
124
- Symbol (" _root_.scala.collection.IterableLike#zip(Lscala/collection/GenIterable;Lscala/collection/generic/CanBuildFrom;)Ljava/lang/Object;." )
125
- )
126
-
127
86
def startsWithParens (tree : Tree ): Boolean =
128
87
tree.tokens.headOption.map(_.is[Token .LeftParen ]).getOrElse(false )
129
88
@@ -262,34 +221,6 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
262
221
}.asPatch
263
222
}
264
223
265
- def replaceSetMapPlusMinus (ctx : RuleCtx ): Patch = {
266
- def rewriteOp (op : Tree , rhs : Tree , doubleOp : String , col0 : String ): Patch = {
267
- val col = " _root_.scala.collection." + col0
268
- val callSite =
269
- if (startsWithParens(rhs)) {
270
- ctx.addLeft(rhs, col)
271
- }
272
- else {
273
- ctx.addLeft(rhs, col + " (" ) +
274
- ctx.addRight(rhs, " )" )
275
- }
276
-
277
- ctx.addRight(op, doubleOp) + callSite
278
- }
279
-
280
- ctx.tree.collect {
281
- case Term .ApplyInfix (CollectionSet (), op @ setPlus(_), Nil , List (rhs)) =>
282
- rewriteOp(op, rhs, " +" , " Set" )
283
-
284
- case Term .ApplyInfix (CollectionSet (), op @ setMinus(_), Nil , List (rhs)) =>
285
- rewriteOp(op, rhs, " -" , " Set" )
286
-
287
- case Term .ApplyInfix (_, op @ mapPlus(_), Nil , List (rhs)) =>
288
- rewriteOp(op, rhs, " +" , " Map" )
289
- }.asPatch
290
- }
291
-
292
-
293
224
def replaceMutSetMapPlus (ctx : RuleCtx ): Patch = {
294
225
def rewriteMutPlus (lhs : Term , op : Term .Name ): Patch = {
295
226
ctx.addRight(lhs, " .clone()" ) +
@@ -331,12 +262,7 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
331
262
}.asPatch
332
263
}
333
264
334
- def replaceMapZip (ctx : RuleCtx ): Patch = {
335
- ctx.tree.collect {
336
- case ap @ Term .Apply (Term .Select (CollectionMap (), mapZip(_)), List (_)) =>
337
- ctx.addRight(ap, " .toMap" )
338
- }.asPatch
339
- }
265
+
340
266
341
267
def replaceMapMapValues (ctx : RuleCtx ): Patch = {
342
268
ctx.tree.collect {
@@ -355,12 +281,10 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
355
281
replaceMutableSet(ctx) +
356
282
replaceSymbolicFold(ctx) +
357
283
replaceSetMapPlus2(ctx) +
358
- replaceSetMapPlusMinus(ctx) +
359
284
replaceMutSetMapPlus(ctx) +
360
285
replaceMutMapUpdated(ctx) +
361
286
replaceIterableSameElements(ctx) +
362
287
replaceArrayBuilderMake(ctx) +
363
- replaceMapZip(ctx) +
364
288
replaceMapMapValues(ctx)
365
289
}
366
290
}
0 commit comments