@@ -185,31 +185,33 @@ trait Stable212Base extends CrossCompatibility { self: SemanticRule =>
185
185
else Patch .empty
186
186
}
187
187
188
- def extractCollection (toCol : Tree ): String = {
189
- toCol match {
190
- case Term .ApplyType (q " scala.Predef.fallbackStringCanBuildFrom " , _) =>
191
- " scala.collection.immutable.IndexedSeq"
192
- case Term .ApplyType (Term .Select (coll,_), _) =>
193
- coll.syntax
194
- case Term .Apply (Term .ApplyType (Term .Select (coll, _), _), _) =>
195
- coll.syntax
196
- case Term .Select (coll,_) =>
197
- coll.syntax
198
- case _ => {
199
- throw new Exception (
200
- s """ |cannot extract collection from .to
201
- |
202
- |---------------------------------------------
203
- |syntax:
204
- | ${toCol.syntax}
205
- |
206
- |---------------------------------------------
207
- |structure:
208
- | ${toCol.structure}""" .stripMargin
209
- )
210
- }
211
- }
212
- }
188
+ def extractCollection (toCol : Tree ): String = {
189
+ toCol match {
190
+ case Term .ApplyType (q " scala.Predef.fallbackStringCanBuildFrom " , _) =>
191
+ " scala.collection.immutable.IndexedSeq"
192
+ case Term .ApplyType (Term .Select (coll,_), _) =>
193
+ coll.syntax
194
+ case Term .Apply (Term .ApplyType (Term .Select (coll, _), _), _) =>
195
+ coll.syntax
196
+ case Term .Select (coll,_) =>
197
+ coll.syntax
198
+ case coll : Type .Name =>
199
+ coll.syntax
200
+ case _ => {
201
+ throw new Exception (
202
+ s """ |cannot extract collection from .to
203
+ |
204
+ |---------------------------------------------
205
+ |syntax:
206
+ | ${toCol.syntax}
207
+ |
208
+ |---------------------------------------------
209
+ |structure:
210
+ | ${toCol.structure}""" .stripMargin
211
+ )
212
+ }
213
+ }
214
+ }
213
215
214
216
def replaceToList (ctx : RuleCtx ): Patch = {
215
217
ctx.tree.collect {
@@ -221,13 +223,24 @@ trait Stable212Base extends CrossCompatibility { self: SemanticRule =>
221
223
ctx.replaceToken(open, " (" ) + ctx.replaceToken(close, " )" )
222
224
}.asPatch
223
225
224
- case Term .Select (_, to @ toTpe(_)) =>
225
- val synth = ctx.index.synthetics.find(_.position.end == to.pos.end)
226
- synth.map{ s =>
227
- val Term .Apply (_, List (toCol)) = s.text.parse[Term ].get
228
- val col = extractCollection(toCol)
229
- ctx.addRight(to, " (" + col + " )" )
230
- }.getOrElse(Patch .empty)
226
+ case t @ Term .Select (_, to @ toTpe(n : Name )) if ! handledTo.contains(n) =>
227
+ // we only want f.to, not f.to(X)
228
+ val applied =
229
+ t.parent match {
230
+ case Some (_:Term .Apply ) => true
231
+ case _ => false
232
+ }
233
+
234
+ if (! applied) {
235
+ val synth = ctx.index.synthetics.find(_.position.end == to.pos.end)
236
+ synth.map{ s =>
237
+ val res = s.text.parse[Term ].get
238
+ val Term .Apply (_, List (toCol)) = res
239
+ val col = extractCollection(toCol)
240
+ ctx.addRight(to, " (" + col + " )" )
241
+ }.getOrElse(Patch .empty)
242
+ } else Patch .empty
243
+
231
244
}.asPatch
232
245
}
233
246
0 commit comments