@@ -31,7 +31,7 @@ trait Stable212Base extends CrossCompatibility { self: SemanticRule =>
3131 val foldLeftSymbol = foldSymbol(isLeft = true )
3232 val foldRightSymbol = foldSymbol(isLeft = false )
3333
34- val iterator = normalized( " _root_.scala.collection.TraversableLike.toIterator. " )
34+
3535 val toTpe = normalized(
3636 " _root_.scala.collection.TraversableLike.to." ,
3737 " _root_.scala.collection.TraversableOnce.to." ,
@@ -73,10 +73,9 @@ trait Stable212Base extends CrossCompatibility { self: SemanticRule =>
7373 " _root_.scala.collection.immutable.TreeSet#until(Ljava/lang/Object;)Lscala/collection/immutable/TreeSet;."
7474 )
7575
76- val traversable = exact(
77- " _root_.scala.collection.Traversable# " ,
76+ val `TraversableLike.toIterator` = normalized( " _root_.scala.collection.TraversableLike.toIterator. " )
77+ val traversableOnce = exact(
7878 " _root_.scala.collection.TraversableOnce#" ,
79- " _root_.scala.package.Traversable#" ,
8079 " _root_.scala.package.TraversableOnce#"
8180 )
8281
@@ -99,28 +98,42 @@ trait Stable212Base extends CrossCompatibility { self: SemanticRule =>
9998 sameElements + compatImport
10099 }
101100
102- def replaceSymbols0 (ctx : RuleCtx ): Patch = {
101+ def replaceTraversable (ctx : RuleCtx ): Patch = {
102+
103+ val traversableIterator =
104+ ctx.tree.collect {
105+ case `TraversableLike.toIterator`(t : Name ) =>
106+ ctx.replaceTree(t, " iterator" )
107+ }.asPatch
108+
103109 val traversableToIterable =
104110 ctx.replaceSymbols(
105- " scala.Traversable" -> " scala.Iterable" ,
106- " scala.collection.Traversable" -> " scala.collection.Iterable" ,
107- " scala.TraversableOnce " -> " scala.IterableOnce " ,
108- " scala.collection.TraversableOnce " -> " scala.collection.IterableOnce "
111+ " scala.Traversable" -> " scala.Iterable" ,
112+ " scala.collection.Traversable" -> " scala.collection.Iterable" ,
113+ " scala.collection.immutable.Traversable " -> " scala.collection.immutable.Iterable " ,
114+ " scala.collection.mutable.Traversable " -> " scala.collection.mutable.Iterable " ,
109115 )
110116
111- import scala .meta .contrib ._
112- val hasTraversable =
113- ctx.tree.exists {
114- case traversable(_) => true
115- case _ => false
117+ val traversableOnceToIterableOnce =
118+ ctx.tree.collect {
119+ case Type .Apply (sel @ Type .Select (chain, traversableOnce(n : Name )), _) =>
120+ val dot = chain.tokens.toList.reverse.drop(1 )
121+
122+ ctx.removeTokens(chain.tokens) +
123+ ctx.removeTokens(dot) +
124+ ctx.replaceTree(sel, " IterableOnce" )
116125
117- }
126+ case Type .Apply (traversableOnce(n : Name ), _) =>
127+ ctx.replaceTree(n, " IterableOnce" )
128+
129+
130+ }.asPatch
118131
119132 val compatImport =
120- if (hasTraversable ) addCompatImport(ctx)
133+ if (traversableOnceToIterableOnce.nonEmpty || traversableIterator.nonEmpty ) addCompatImport(ctx)
121134 else Patch .empty
122135
123- traversableToIterable + compatImport
136+ traversableOnceToIterableOnce + traversableToIterable + traversableIterator + compatImport
124137 }
125138
126139 def replaceSymbolicFold (ctx : RuleCtx ): Patch = {
@@ -251,14 +264,8 @@ trait Stable212Base extends CrossCompatibility { self: SemanticRule =>
251264 }
252265 }
253266
254- def replaceToList (ctx : RuleCtx ): Patch = {
255- val replaceToIterator =
256- ctx.tree.collect {
257- case iterator(t : Name ) =>
258- ctx.replaceTree(t, " iterator" )
259- }.asPatch
260-
261- val replaceTo =
267+ def replaceTo (ctx : RuleCtx ): Patch = {
268+ val patch =
262269 ctx.tree.collect {
263270 case Term .ApplyType (Term .Select (_, t @ toTpe(n : Name )), _) if ! handledTo.contains(n) =>
264271 trailingBrackets(n, ctx).map { case (open, close) =>
@@ -286,10 +293,10 @@ trait Stable212Base extends CrossCompatibility { self: SemanticRule =>
286293 }.asPatch
287294
288295 val compatImport =
289- if (replaceTo .nonEmpty) addCompatImport(ctx)
296+ if (patch .nonEmpty) addCompatImport(ctx)
290297 else Patch .empty
291298
292- compatImport + replaceToIterator + replaceTo
299+ compatImport + patch
293300 }
294301
295302 def replaceFuture (ctx : RuleCtx ): Patch = {
@@ -566,9 +573,9 @@ trait Stable212Base extends CrossCompatibility { self: SemanticRule =>
566573 }
567574
568575 override def fix (ctx : RuleCtx ): Patch = {
569- replaceSymbols0 (ctx) +
576+ replaceTraversable (ctx) +
570577 replaceCanBuildFrom(ctx) +
571- replaceToList (ctx) +
578+ replaceTo (ctx) +
572579 replaceCopyToBuffer(ctx) +
573580 replaceSymbolicFold(ctx) +
574581 replaceSetMapPlus2(ctx) +
0 commit comments