Skip to content

Commit e2fa336

Browse files
committed
Unimport Predef conversions if used.
1 parent eb10070 commit e2fa336

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

output/src/main/scala/fix/Collectionstrawman_v0.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package fix
22

3-
import scala.Predef.{augmentString => _, wrapString => _, _}
3+
import scala.Predef.{augmentString => _, intArrayOps => _, wrapString => _, _}
44
import strawman.collection.{ Iterable, Set, arrayToArrayOps, stringToStringOps }
55
import strawman.collection.immutable.{ ::, HashMap, LazyList, List, Map, Nil, Range, Vector }
66
import strawman.collection.immutable.LazyList.#::

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ import scala.meta._
77
case class Collectionstrawman_v0(sctx: SemanticCtx)
88
extends SemanticRewrite(sctx) {
99
val immutableListSymbol = Symbol("_root_.scala.collection.immutable.List.")
10+
implicit class XtensionSymbolCollection(symbol: Symbol) {
11+
def name = symbol match {
12+
case Symbol.Global(_, sig) => sig.name
13+
case _ => symbol.syntax
14+
}
15+
}
16+
1017
val unimports = Map(
1118
Symbol("_root_.scala.Predef.augmentString.") ->
1219
Symbol("_root_.strawman.collection.stringToStringOps."),
@@ -15,10 +22,19 @@ case class Collectionstrawman_v0(sctx: SemanticCtx)
1522
)
1623

1724
def ifSymbolFound(ctx: RewriteCtx): Patch = {
18-
val toImport = ctx.semanticCtx.names
19-
.flatMap(r => unimports.get(r.sym.normalized))
20-
.map(ctx.addGlobalImport)
21-
toImport.asPatch
25+
val toImport = for {
26+
r <- ctx.semanticCtx.names
27+
in = r.sym.normalized
28+
out <- unimports.get(in).toList
29+
} yield {
30+
ctx.addGlobalImport(out) +
31+
ctx.addGlobalImport(
32+
Importer(q"scala.Predef", Importee.Unimport(Name(in.name)) :: Nil))
33+
}
34+
val predefUnderscore =
35+
if (toImport.isEmpty) Patch.empty
36+
else ctx.addGlobalImport(importer"scala.Predef._")
37+
toImport.asPatch + predefUnderscore
2238
}
2339

2440
val rangeImport = Symbol("_root_.strawman.collection.immutable.Range.")

0 commit comments

Comments
 (0)