Skip to content

Commit 0dbd244

Browse files
Fix Traversable & CC.to
Add more cases for Traversable Improve the implicit f(cc.to) call
1 parent d6a03c5 commit 0dbd244

File tree

10 files changed

+216
-150
lines changed

10 files changed

+216
-150
lines changed

scalafix/input/src/main/scala/fix/CompanionSrc.scala

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,40 @@ rule = "scala:fix.CrossCompat"
33
*/
44
package fix
55

6-
import scala.collection.{immutable => i, mutable => m}
7-
import scala.{collection => c}
6+
import scala.collection
7+
import scala.collection.{immutable, mutable}
88

99
object CompanionSrc {
1010

11-
(null: c.IndexedSeq[Int]).companion
12-
(null: c.Iterable[Int]).companion
13-
(null: c.Seq[Int]).companion
14-
(null: c.Traversable[Int]).companion
11+
(null: collection.IndexedSeq[Int]).companion
12+
(null: collection.Iterable[Int]).companion
13+
(null: collection.Seq[Int]).companion
14+
(null: collection.Traversable[Int]).companion
1515

16-
(null: i.HashSet[Int]).companion
17-
(null: i.IndexedSeq[Int]).companion
18-
(null: i.Iterable[Int]).companion
19-
(null: i.LinearSeq[Int]).companion
20-
(null: i.List[Int]).companion
21-
(null: i.ListSet[Int]).companion
22-
(null: i.Queue[Int]).companion
23-
(null: i.Seq[Int]).companion
24-
(null: i.Set[Int]).companion
25-
(null: i.Stack[Int]).companion
26-
(null: i.Stream[Int]).companion
27-
(null: i.Traversable[Int]).companion
28-
(null: i.Vector[Int]).companion
16+
(null: immutable.HashSet[Int]).companion
17+
(null: immutable.IndexedSeq[Int]).companion
18+
(null: immutable.Iterable[Int]).companion
19+
(null: immutable.LinearSeq[Int]).companion
20+
(null: immutable.List[Int]).companion
21+
(null: immutable.ListSet[Int]).companion
22+
(null: immutable.Queue[Int]).companion
23+
(null: immutable.Seq[Int]).companion
24+
(null: immutable.Set[Int]).companion
25+
(null: immutable.Stream[Int]).companion
26+
(null: immutable.Traversable[Int]).companion
27+
(null: immutable.Vector[Int]).companion
2928

30-
(null: m.ArrayBuffer[Int]).companion
31-
(null: m.ArraySeq[Int]).companion
32-
(null: m.ArrayStack[Int]).companion
33-
(null: m.Buffer[Int]).companion
34-
(null: m.DoubleLinkedList[Int]).companion
35-
(null: m.HashSet[Int]).companion
36-
(null: m.IndexedSeq[Int]).companion
37-
(null: m.Iterable[Int]).companion
38-
(null: m.LinearSeq[Int]).companion
39-
(null: m.LinkedHashSet[Int]).companion
40-
(null: m.LinkedList[Int]).companion
41-
(null: m.MutableList[Int]).companion
42-
(null: m.Queue[Int]).companion
43-
(null: m.ResizableArray[Int]).companion
44-
(null: m.Seq[Int]).companion
45-
(null: m.Set[Int]).companion
46-
(null: m.Traversable[Int]).companion
29+
(null: mutable.ArrayBuffer[Int]).companion
30+
(null: mutable.ArraySeq[Int]).companion
31+
(null: mutable.ArrayStack[Int]).companion
32+
(null: mutable.Buffer[Int]).companion
33+
(null: mutable.HashSet[Int]).companion
34+
(null: mutable.IndexedSeq[Int]).companion
35+
(null: mutable.Iterable[Int]).companion
36+
(null: mutable.LinearSeq[Int]).companion
37+
(null: mutable.LinkedHashSet[Int]).companion
38+
(null: mutable.Queue[Int]).companion
39+
(null: mutable.Seq[Int]).companion
40+
(null: mutable.Set[Int]).companion
41+
(null: mutable.Traversable[Int]).companion
4742
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
rule = "scala:fix.CrossCompat"
3+
*/
4+
package fix
5+
6+
import scala.collection.{immutable => i, mutable => m}
7+
import scala.{collection => c}
8+
9+
object CompanionSrc212 {
10+
(null: i.Stack[Int]).companion
11+
(null: m.DoubleLinkedList[Int]).companion
12+
(null: m.LinkedList[Int]).companion
13+
(null: m.MutableList[Int]).companion
14+
(null: m.ResizableArray[Int]).companion
15+
}
16+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
rule = "scala:fix.CrossCompat"
3+
*/
4+
package fix
5+
6+
import scala.collection.mutable
7+
8+
object ReplaceToSrc {
9+
List(1).to[Set]
10+
Set(1).to[List]
11+
12+
def f1(xs: List[Int]): Iterable[Int] =
13+
xs.to
14+
15+
List[Int]() // unrelated matching brackets
16+
17+
def f2(xs: List[Int]): Set[Int] =
18+
xs.to
19+
20+
def f3(xs: List[Int]): collection.mutable.Set[Int] =
21+
xs.to
22+
}

scalafix/input/src/main/scala/fix/TraversableSrc.scala

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ rule = "scala:fix.CrossCompat"
33
*/
44
package fix
55

6-
object TraversableSrc {
7-
def foo(xs: Traversable[(Int, String)], ys: List[Int]): Unit = {
8-
xs.to[List]
9-
xs.to[Set]
10-
xs.toIterator
11-
ys.iterator
12-
}
6+
import scala.collection.mutable
7+
import scala.collection.immutable
138

14-
def m1(xs: TraversableOnce[Int]): List[Int] =
15-
xs.to
9+
trait TraversableSrc {
10+
val to: TraversableOnce[Int]
11+
val cto: scala.collection.TraversableOnce[Int]
1612

17-
List[Int]() // unrelated matching brackets
13+
val t: Traversable[Int]
14+
val ct: collection.Traversable[Int]
15+
val it: immutable.Traversable[Int]
16+
val mt: mutable.Traversable[Int]
1817
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
3+
4+
package fix
5+
6+
import scala.collection
7+
import scala.collection.{immutable, mutable}
8+
import scala.collection.compat._
9+
10+
object CompanionSrc {
11+
12+
(null: collection.IndexedSeq[Int]).iterableFactory
13+
(null: collection.Iterable[Int]).iterableFactory
14+
(null: collection.Seq[Int]).iterableFactory
15+
(null: collection.Iterable[Int]).iterableFactory
16+
17+
(null: immutable.HashSet[Int]).iterableFactory
18+
(null: immutable.IndexedSeq[Int]).iterableFactory
19+
(null: immutable.Iterable[Int]).iterableFactory
20+
(null: immutable.LinearSeq[Int]).iterableFactory
21+
(null: immutable.List[Int]).iterableFactory
22+
(null: immutable.ListSet[Int]).iterableFactory
23+
(null: immutable.Queue[Int]).iterableFactory
24+
(null: immutable.Seq[Int]).iterableFactory
25+
(null: immutable.Set[Int]).iterableFactory
26+
(null: immutable.Stream[Int]).iterableFactory
27+
(null: immutable.Iterable[Int]).iterableFactory
28+
(null: immutable.Vector[Int]).iterableFactory
29+
30+
(null: mutable.ArrayBuffer[Int]).iterableFactory
31+
(null: mutable.ArraySeq[Int]).iterableFactory
32+
(null: mutable.ArrayStack[Int]).iterableFactory
33+
(null: mutable.Buffer[Int]).iterableFactory
34+
(null: mutable.HashSet[Int]).iterableFactory
35+
(null: mutable.IndexedSeq[Int]).iterableFactory
36+
(null: mutable.Iterable[Int]).iterableFactory
37+
(null: mutable.LinearSeq[Int]).iterableFactory
38+
(null: mutable.LinkedHashSet[Int]).iterableFactory
39+
(null: mutable.Queue[Int]).iterableFactory
40+
(null: mutable.Seq[Int]).iterableFactory
41+
(null: mutable.Set[Int]).iterableFactory
42+
(null: mutable.Iterable[Int]).iterableFactory
43+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
3+
4+
package fix
5+
6+
import scala.collection.mutable
7+
import scala.collection.compat._
8+
9+
object ReplaceToSrc {
10+
List(1).to(Set)
11+
Set(1).to(List)
12+
13+
def f1(xs: List[Int]): Iterable[Int] =
14+
xs.to(scala.collection.immutable.IndexedSeq)
15+
16+
List[Int]() // unrelated matching brackets
17+
18+
def f2(xs: List[Int]): Set[Int] =
19+
xs.to(scala.collection.immutable.Set)
20+
21+
def f3(xs: List[Int]): collection.mutable.Set[Int] =
22+
xs.to(scala.collection.mutable.Set)
23+
}

scalafix/output/src/main/scala/fix/TraversableSrc.scala

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33

44
package fix
55

6+
import scala.collection.mutable
7+
import scala.collection.immutable
68
import scala.collection.compat._
7-
object TraversableSrc {
8-
def foo(xs: Iterable[(Int, String)], ys: List[Int]): Unit = {
9-
xs.to(List)
10-
xs.to(Set)
11-
xs.iterator
12-
ys.iterator
13-
}
149

15-
def m1(xs: IterableOnce[Int]): List[Int] =
16-
xs.to(scala.collection.immutable.List)
10+
trait TraversableSrc {
11+
val to: IterableOnce[Int]
12+
val cto: IterableOnce[Int]
1713

18-
List[Int]() // unrelated matching brackets
14+
val t: Iterable[Int]
15+
val ct: collection.Iterable[Int]
16+
val it: immutable.Iterable[Int]
17+
val mt: mutable.Iterable[Int]
1918
}

scalafix/output212/src/main/scala/fix/CompanionSrc.scala

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
3+
4+
package fix
5+
6+
import scala.collection.{immutable => i, mutable => m}
7+
import scala.{collection => c}
8+
import scala.collection.compat._
9+
10+
object CompanionSrc212 {
11+
(null: i.Stack[Int]).iterableFactory
12+
(null: m.DoubleLinkedList[Int]).iterableFactory
13+
(null: m.LinkedList[Int]).iterableFactory
14+
(null: m.MutableList[Int]).iterableFactory
15+
(null: m.ResizableArray[Int]).iterableFactory
16+
}

0 commit comments

Comments
 (0)