Skip to content

Commit c41b46e

Browse files
committed
Improve the to[X] rules
1 parent ea68880 commit c41b46e

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

output/src/main/scala/fix/Collectionstrawman_v0_Traversable.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package fix
22

33
import strawman.collection.Iterable
4-
import strawman.collection.immutable.List
4+
import strawman.collection.immutable.{ List, Set }
55
object Collectionstrawman_v0_Traversable {
66
def foo(xs: Iterable[(Int, String)], ys: List[Int]): Unit = {
7-
xs.to(List)
7+
xs.to(strawman.collection.immutable.List)
88
xs.to(strawman.collection.immutable.Set)
99
ys.toSeq
1010
xs.to(List)
11-
xs.to(strawman.collection.immutable.Set)
11+
xs.to(Set)
1212
xs.to(strawman.collection.Map)
1313
xs.iterator()
1414
ys.iterator()

rewrites/src/main/scala/fix/Collectionstrawman_v0.scala

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import scala.meta._
66

77
case class Collectionstrawman_v0(sctx: SemanticCtx)
88
extends SemanticRewrite(sctx) {
9-
val immutableListSymbol = Symbol("_root_.scala.collection.immutable.List.")
9+
1010
implicit class XtensionSymbolCollection(symbol: Symbol) {
1111
def name = symbol match {
1212
case Symbol.Global(_, sig) => sig.name
@@ -75,7 +75,7 @@ case class Collectionstrawman_v0(sctx: SemanticCtx)
7575
def m(name: String) =
7676
s"scala.collection.mutable.$name" -> s"strawman.collection.mutable.$name"
7777
ctx.replaceSymbols(
78-
s("Set"),
78+
p("Set"),
7979
i("HashMap"),
8080
i("Map"),
8181
p("Map"),
@@ -115,8 +115,10 @@ case class Collectionstrawman_v0(sctx: SemanticCtx)
115115
sctx.symbol(arg.pos).map(x => arg -> x)
116116
}
117117

118-
val toX = SymbolMatcher(
119-
Symbol("_root_.scala.collection.TraversableOnce.toMap."),
118+
val toGenericX = SymbolMatcher(
119+
Symbol("_root_.scala.collection.TraversableOnce.toMap.")
120+
)
121+
val toImmutableX = SymbolMatcher(
120122
Symbol("_root_.scala.collection.TraversableOnce.toList."),
121123
Symbol("_root_.scala.collection.TraversableOnce.toSet.")
122124
)
@@ -131,8 +133,10 @@ case class Collectionstrawman_v0(sctx: SemanticCtx)
131133
ctx.tree.collect {
132134
case iterator(n: Name, _) =>
133135
ctx.addRight(n.tokens.last, "()")
134-
case toX(n: Name, s) =>
135-
ctx.replaceTree(n, s"to(${s.name.stripPrefix("to")})")
136+
case toImmutableX(n: Name, s) =>
137+
ctx.replaceTree(n, s"to(strawman.collection.immutable.${s.name.stripPrefix("to")})")
138+
case toGenericX(n: Name, s) =>
139+
ctx.replaceTree(n, s"to(strawman.collection.${s.name.stripPrefix("to")})")
136140
case toTpe(n: Name, _) =>
137141
ctx.debug(n)
138142
(for {
@@ -141,6 +145,7 @@ case class Collectionstrawman_v0(sctx: SemanticCtx)
141145
open <- ctx.tokenList.find(name)(t => t.is[Token.LeftBracket])
142146
_ = ctx.debug(open)
143147
close <- ctx.matching.close(open.asInstanceOf[Token.LeftBracket])
148+
replacedTokens = ctx.tokenList.slice(open, close)
144149
} yield
145150
ctx.replaceToken(open, "(") +
146151
ctx.replaceToken(close, ")")).getOrElse(Patch.empty)

0 commit comments

Comments
 (0)