@@ -5,8 +5,7 @@ import scalafix.syntax._
5
5
import scalafix .util ._
6
6
import scala .meta ._
7
7
8
- case class Scalacollectioncompat_newcollections (index : SemanticdbIndex )
9
- extends SemanticRule (index, " Scalacollectioncompat_newcollections" ) {
8
+ case class Stable (index : SemanticdbIndex ) extends SemanticRule (index, " Stable" ) {
10
9
11
10
// Two rules triggers the same rewrite TraversableLike.to and CanBuildFrom
12
11
// we keep track of what is handled in CanBuildFrom and guard against TraversableLike.to
@@ -26,36 +25,9 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
26
25
close <- ctx.matchingParens.close(open)
27
26
} yield (open, close)
28
27
29
- // terms dont give us terms https://github.com/scalameta/scalameta/issues/1212
30
- // WARNING: TOTAL HACK
31
- // this is only to unblock us until Term.tpe is available: https://github.com/scalameta/scalameta/issues/1212
32
- // if we have a simple identifier, we can look at his definition at query it's type
33
- // this should be improved in future version of scalameta
34
- object TypeMatcher {
35
- def apply (symbols : Symbol * )(implicit index : SemanticdbIndex ): TypeMatcher =
36
- new TypeMatcher (symbols : _* )(index)
37
- }
38
-
39
- final class TypeMatcher (symbols : Symbol * )(implicit index : SemanticdbIndex ) {
40
- def unapply (tree : Tree ): Boolean = {
41
- index.denotation(tree)
42
- .exists(_.names.headOption.exists(n => symbols.exists(_ == n.symbol)))
43
- }
44
- }
45
-
46
- val CollectionMap : TypeMatcher = TypeMatcher (
47
- Symbol (" _root_.scala.collection.immutable.Map#" ),
48
- Symbol (" _root_.scala.collection.mutable.Map#" ),
49
- Symbol (" _root_.scala.Predef.Map#" )
50
- )
51
-
52
- val CollectionSet : TypeMatcher = TypeMatcher (Symbol (" _root_.scala.collection.Set#" ))
53
-
54
28
def replaceSymbols (ctx : RuleCtx ): Patch = {
55
29
ctx.replaceSymbols(
56
30
" scala.collection.LinearSeq" -> " scala.collection.immutable.List" ,
57
- " scala.Stream" -> " scala.LazyList" ,
58
- " scala.collection.immutable.Stream" -> " scala.collection.immutable.LazyList" ,
59
31
" scala.Traversable" -> " scala.Iterable" ,
60
32
" scala.collection.Traversable" -> " scala.collection.Iterable" ,
61
33
" scala.TraversableOnce" -> " scala.IterableOnce" ,
@@ -125,10 +97,7 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
125
97
Symbol (" _root_.scala.collection.mutable.MapLike.retain." )
126
98
)
127
99
128
- val mapMapValues =
129
- SymbolMatcher .exact(
130
- Symbol (" _root_.scala.collection.immutable.MapLike#mapValues(Lscala/Function1;)Lscala/collection/immutable/Map;." )
131
- )
100
+
132
101
133
102
val retainSet =
134
103
SymbolMatcher .normalized(
@@ -232,16 +201,6 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
232
201
ctx.replaceTree(t, q " $buffer ++= $collection" .syntax)
233
202
}.asPatch
234
203
235
- val streamAppend = SymbolMatcher .normalized(
236
- Symbol (" _root_.scala.collection.immutable.Stream.append." )
237
- )
238
-
239
- def replaceStreamAppend (ctx : RuleCtx ): Patch =
240
- ctx.tree.collect {
241
- case streamAppend(t : Name ) =>
242
- ctx.replaceTree(t, " lazyAppendedAll" )
243
- }.asPatch
244
-
245
204
def replaceSetMapPlus2 (ctx : RuleCtx ): Patch = {
246
205
def rewritePlus (ap : Term .ApplyInfix , lhs : Term , op : Term .Name , rhs1 : Term , rhs2 : Term ): Patch = {
247
206
val tokensToReplace =
@@ -311,15 +270,6 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
311
270
}.asPatch
312
271
}
313
272
314
-
315
-
316
- def replaceMapMapValues (ctx : RuleCtx ): Patch = {
317
- ctx.tree.collect {
318
- case ap @ Term .Apply (Term .Select (_, mapMapValues(_)), List (_)) =>
319
- ctx.addRight(ap, " .toMap" )
320
- }.asPatch
321
- }
322
-
323
273
object CanBuildFromNothing {
324
274
def apply (paramss : List [List [Term .Param ]], body : Term , ctx : RuleCtx ): Patch = {
325
275
paramss.flatten.collect{
@@ -507,15 +457,13 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
507
457
replaceSymbols(ctx) +
508
458
replaceTupleZipped(ctx) +
509
459
replaceCopyToBuffer(ctx) +
510
- replaceStreamAppend(ctx) +
511
460
replaceMutableMap(ctx) +
512
461
replaceMutableSet(ctx) +
513
462
replaceSymbolicFold(ctx) +
514
463
replaceSetMapPlus2(ctx) +
515
464
replaceMutSetMapPlus(ctx) +
516
465
replaceMutMapUpdated(ctx) +
517
466
replaceArrayBuilderMake(ctx) +
518
- replaceIterableSameElements(ctx) +
519
- replaceMapMapValues(ctx)
467
+ replaceIterableSameElements(ctx)
520
468
}
521
469
}
0 commit comments