@@ -6,6 +6,8 @@ import scala.meta._
66
77import scala .collection .mutable
88
9+ import System .{lineSeparator => nl }
10+
911trait CrossCompatibility {
1012 def isCrossCompatible : Boolean
1113}
@@ -26,6 +28,9 @@ trait Stable212Base extends CrossCompatibility { self: SemanticRule =>
2628 normalized(s " _root_.scala.collection.TraversableOnce.` $op`. " )
2729 }
2830
31+ val foldLeftSymbol = foldSymbol(isLeft = true )
32+ val foldRightSymbol = foldSymbol(isLeft = false )
33+
2934 val iterator = normalized(" _root_.scala.collection.TraversableLike.toIterator." )
3035 val toTpe = normalized(" _root_.scala.collection.TraversableLike.to." )
3136 val copyToBuffer = normalized(" _root_.scala.collection.TraversableOnce.copyToBuffer." )
@@ -39,8 +44,8 @@ trait Stable212Base extends CrossCompatibility { self: SemanticRule =>
3944 val mutSetPlus = exact(" _root_.scala.collection.mutable.SetLike#`+`(Ljava/lang/Object;)Lscala/collection/mutable/Set;." )
4045 val mutMapPlus = exact(" _root_.scala.collection.mutable.MapLike#`+`(Lscala/Tuple2;)Lscala/collection/mutable/Map;." )
4146 val mutMapUpdate = exact(" _root_.scala.collection.mutable.MapLike#updated(Ljava/lang/Object;Ljava/lang/Object;)Lscala/collection/mutable/Map;." )
42- val foldLeftSymbol = foldSymbol(isLeft = true )
43- val foldRightSymbol = foldSymbol(isLeft = false )
47+ val `Future.onFailure` = exact( " _root_.scala.concurrent.Future#onFailure(Lscala/PartialFunction;Lscala/concurrent/ExecutionContext;)V. " )
48+ val `Future.onSuccess` = exact( " _root_.scala.concurrent.Future#onSuccess(Lscala/PartialFunction;Lscala/concurrent/ExecutionContext;)V. " )
4449
4550 val traversable = exact(
4651 " _root_.scala.package.Traversable#" ,
@@ -262,6 +267,29 @@ trait Stable212Base extends CrossCompatibility { self: SemanticRule =>
262267 compatImport + replaceToIterator + replaceTo
263268 }
264269
270+ def replaceFuture (ctx : RuleCtx ): Patch = {
271+
272+ def toOnCompletePF (f : Tree , cases : List [Tree ], tryApply : String ): Patch = {
273+ val indent = " " * cases.head.pos.startColumn
274+
275+ ctx.replaceTree(f, " onComplete" ) +
276+ cases.map{ case Case (c, _, _) =>
277+ ctx.addLeft(c, tryApply + " (" ) +
278+ ctx.addRight(c, " )" )
279+ }.asPatch +
280+ ctx.addRight(cases.last, nl + indent + " case _ => ()" )
281+ }
282+
283+ ctx.tree.collect {
284+ case Term .Apply (Term .Select (_, f @ `Future.onFailure`(_)), List (Term .PartialFunction (cases))) =>
285+ toOnCompletePF(f, cases, " scala.util.Failure" )
286+
287+ case Term .Apply (Term .Select (_, f @ `Future.onSuccess`(_)), List (Term .PartialFunction (cases))) =>
288+ toOnCompletePF(f, cases, " scala.util.Success" )
289+
290+ }.asPatch
291+ }
292+
265293 private val compatImportAdded = mutable.Set [Input ]()
266294
267295 def addCompatImport (ctx : RuleCtx ): Patch = {
@@ -284,7 +312,7 @@ trait Stable212Base extends CrossCompatibility { self: SemanticRule =>
284312 replaceMutMapUpdated(ctx) +
285313 replaceArrayBuilderMake(ctx) +
286314 replaceIterableSameElements(ctx) +
287- replaceBreakout(ctx)
315+ replaceBreakout(ctx) +
316+ replaceFuture(ctx)
288317 }
289-
290318}
0 commit comments