@@ -66,11 +66,6 @@ trait Stable212Base extends CrossCompatibility { self: SemanticRule =>
66
66
" scala.collection.Traversable" -> " scala.collection.Iterable"
67
67
)
68
68
69
- val linearSeqToList =
70
- ctx.replaceSymbols(
71
- " scala.collection.LinearSeq" -> " scala.collection.immutable.List" ,
72
- )
73
-
74
69
import scala .meta .contrib ._
75
70
val hasTraversable =
76
71
ctx.tree.exists {
@@ -83,7 +78,7 @@ trait Stable212Base extends CrossCompatibility { self: SemanticRule =>
83
78
if (hasTraversable) addCompatImport(ctx)
84
79
else Patch .empty
85
80
86
- traversableToIterable + linearSeqToList + compatImport
81
+ traversableToIterable + compatImport
87
82
}
88
83
89
84
def replaceSymbolicFold (ctx : RuleCtx ): Patch = {
@@ -173,34 +168,51 @@ trait Stable212Base extends CrossCompatibility { self: SemanticRule =>
173
168
CanBuildFrom (paramss, body, ctx, collectionCanBuildFrom, nothing)
174
169
}.asPatch
175
170
176
- val imports =
177
- ctx.tree.collect {
178
- case i : Importee if collectionCanBuildFromImport.matches(i) =>
179
- ctx.removeImportee(i)
180
- }.asPatch
171
+ if (useSites.nonEmpty) {
172
+ val imports =
173
+ ctx.tree.collect {
174
+ case i : Importee if collectionCanBuildFromImport.matches(i) =>
175
+ ctx.removeImportee(i)
176
+ }.asPatch
181
177
182
- val compatImport = addCompatImport(ctx)
178
+ val compatImport = addCompatImport(ctx)
183
179
184
- if (useSites.nonEmpty) useSites + imports + compatImport
180
+ useSites + imports + compatImport
181
+ }
185
182
else Patch .empty
186
183
}
187
184
188
185
def replaceToList (ctx : RuleCtx ): Patch = {
189
- ctx.tree.collect {
190
- case iterator(t : Name ) =>
191
- ctx.replaceTree(t, " iterator" )
186
+ val replaceToIterator =
187
+ ctx.tree.collect {
188
+ case iterator(t : Name ) =>
189
+ ctx.replaceTree(t, " iterator" )
190
+ }.asPatch
192
191
193
- case Term .ApplyType (Term .Select (_, t @ toTpe(n : Name )), _) if ! handledTo.contains(n) =>
194
- trailingBrackets(n, ctx).map { case (open, close) =>
195
- ctx.replaceToken(open, " (" ) + ctx.replaceToken(close, " )" )
196
- }.asPatch
197
- }.asPatch
192
+ val replaceTo =
193
+ ctx.tree.collect {
194
+ case Term .ApplyType (Term .Select (_, t @ toTpe(n : Name )), _) if ! handledTo.contains(n) =>
195
+ trailingBrackets(n, ctx).map { case (open, close) =>
196
+ ctx.replaceToken(open, " (" ) + ctx.replaceToken(close, " )" )
197
+ }.asPatch
198
+ }.asPatch
199
+
200
+ val compatImport =
201
+ if (replaceTo.nonEmpty) addCompatImport(ctx)
202
+ else Patch .empty
203
+
204
+ compatImport + replaceToIterator + replaceTo
198
205
}
199
206
207
+ private val compatImportAdded = mutable.Set [Input ]()
200
208
201
209
def addCompatImport (ctx : RuleCtx ): Patch = {
202
- if (isCrossCompatible) ctx.addGlobalImport(importer " scala.collection.compat._ " )
203
- else Patch .empty
210
+ if (isCrossCompatible && ! compatImportAdded.contains(ctx.input)) {
211
+ compatImportAdded += ctx.input
212
+ ctx.addGlobalImport(importer " scala.collection.compat._ " )
213
+ } else {
214
+ Patch .empty
215
+ }
204
216
}
205
217
206
218
override def fix (ctx : RuleCtx ): Patch = {
0 commit comments