Skip to content

Commit 4b53de6

Browse files
committed
Update kotlinx-coroutines to 1.10.2 and kotlinx-serialization to 1.8.0
- Upgrade kotlinx-coroutines from 1.8.1 to 1.10.2 (49 recipes, up from 37) - Upgrade kotlinx-serialization from 1.6.3 to 1.8.0 - Fix DeprecatedMethodScanner to include extension function receiver types in method patterns - Regenerate type table with updated library versions
1 parent f70aad1 commit 4b53de6

5 files changed

Lines changed: 54 additions & 26 deletions

File tree

rewrite-kotlin/build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ dependencies {
3131
testImplementation("com.google.testing.compile:compile-testing:0.+")
3232

3333
// Kotlin libraries for KotlinDeprecationRecipeGenerator
34-
testRuntimeOnly("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1")
35-
testRuntimeOnly("org.jetbrains.kotlinx:kotlinx-serialization-core:1.6.3")
34+
testRuntimeOnly("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2")
35+
testRuntimeOnly("org.jetbrains.kotlinx:kotlinx-serialization-core:1.8.0")
3636
}
3737

3838
recipeDependencies {
3939
// Kotlin libraries with @Deprecated(replaceWith=ReplaceWith(...)) annotations
4040
// Use the JVM variant artifact names since Kotlin multiplatform resolves to these
41-
testParserClasspath("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.8.1")
42-
testParserClasspath("org.jetbrains.kotlinx:kotlinx-serialization-core-jvm:1.6.3")
41+
testParserClasspath("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.10.2")
42+
testParserClasspath("org.jetbrains.kotlinx:kotlinx-serialization-core-jvm:1.8.0")
4343
}
4444

4545
java {

rewrite-kotlin/src/main/resources/META-INF/rewrite/kotlin-deprecations-kotlinx-coroutines-core-1.yml

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# limitations under the License.
1515
#
1616

17-
# Recipes generated for `@Deprecated` methods with `ReplaceWith` in `org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1`
17+
# Recipes generated for `@Deprecated` methods with `ReplaceWith` in `org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2`
1818
#
1919

2020
---
@@ -25,6 +25,24 @@ description: >-
2525
Automatically generated recipes to replace deprecated Kotlin methods based on
2626
`@Deprecated(replaceWith=ReplaceWith(...))` annotations.
2727
recipeList:
28+
# @Deprecated("Use the overload that also accepts the `value` and the coroutine context in lambda", ReplaceWith("resume(value) { cause, _, _ -> onCancellation(cause) }"), DeprecationLevel.WARNING)
29+
- org.openrewrite.kotlin.replace.ReplaceKotlinMethod:
30+
methodPattern: 'kotlinx.coroutines.CancellableContinuation resume(.., kotlin.Function1)'
31+
replacement: 'resume(value) { cause, _, _ -> onCancellation(cause) }'
32+
classpathFromResources:
33+
- 'kotlinx-coroutines-core-jvm-1'
34+
# @Deprecated("Deprecated for good. Override 'limitedParallelism(parallelism: Int, name: String?)' instead", ReplaceWith("limitedParallelism(parallelism, null)"), DeprecationLevel.HIDDEN)
35+
- org.openrewrite.kotlin.replace.ReplaceKotlinMethod:
36+
methodPattern: 'kotlinx.coroutines.CoroutineDispatcher limitedParallelism(kotlin.Int)'
37+
replacement: 'limitedParallelism(parallelism, null)'
38+
classpathFromResources:
39+
- 'kotlinx-coroutines-core-jvm-1'
40+
# @Deprecated("This function does not do what its name implies: it will not cancel the future if just cancel() was called.", ReplaceWith("this.invokeOnCancellation { future.cancel(false) }"), DeprecationLevel.WARNING)
41+
- org.openrewrite.kotlin.replace.ReplaceKotlinMethod:
42+
methodPattern: 'kotlinx.coroutines.JobKt cancelFutureOnCancellation(kotlinx.coroutines.CancellableContinuation, java.util.concurrent.Future)'
43+
replacement: 'this.invokeOnCancellation { future.cancel(false) }'
44+
classpathFromResources:
45+
- 'kotlinx-coroutines-core-jvm-1'
2846
# @Deprecated("Deprecated in the favour of 'receiveCatching'", ReplaceWith("receiveCatching().getOrNull()"), DeprecationLevel.HIDDEN)
2947
- org.openrewrite.kotlin.replace.ReplaceKotlinMethod:
3048
methodPattern: 'kotlinx.coroutines.channels.ChannelsKt receiveOrNull(kotlinx.coroutines.channels.ReceiveChannel, kotlin.coroutines.Continuation)'
@@ -67,10 +85,10 @@ recipeList:
6785
replacement: 'trySend(element).isSuccess'
6886
classpathFromResources:
6987
- 'kotlinx-coroutines-core-jvm-1'
70-
# @Deprecated("Flow analogue of 'cache()' is 'shareIn' with unlimited replay and 'started = SharingStared.Lazily' argument'", ReplaceWith("this.shareIn(scope, Int.MAX_VALUE, started = SharingStared.Lazily)"), DeprecationLevel.ERROR)
88+
# @Deprecated("Flow analogue of 'cache()' is 'shareIn' with unlimited replay and 'started = SharingStarted.Lazily' argument'", ReplaceWith("this.shareIn(scope, started = SharingStarted.Lazily, replay = Int.MAX_VALUE)"), DeprecationLevel.ERROR)
7189
- org.openrewrite.kotlin.replace.ReplaceKotlinMethod:
7290
methodPattern: 'kotlinx.coroutines.flow.FlowKt cache(kotlinx.coroutines.flow.Flow)'
73-
replacement: 'this.shareIn(scope, Int.MAX_VALUE, started = SharingStared.Lazily)'
91+
replacement: 'this.shareIn(scope, started = SharingStarted.Lazily, replay = Int.MAX_VALUE)'
7492
classpathFromResources:
7593
- 'kotlinx-coroutines-core-jvm-1'
7694
# @Deprecated("Flow analogue of 'combineLatest' is 'combine'", ReplaceWith("this.combine(other, transform)"), DeprecationLevel.ERROR)
@@ -181,25 +199,25 @@ recipeList:
181199
replacement: 'catch { e -> if (predicate(e)) emit(fallback) else throw e }'
182200
classpathFromResources:
183201
- 'kotlinx-coroutines-core-jvm-1'
184-
# @Deprecated("Flow analogue of 'publish()' is 'shareIn'. publish().connect() is the default strategy (no extra call is needed), publish().autoConnect() translates to 'started = SharingStared.Lazily' argument, publish().refCount() translates to 'started = SharingStared.WhileSubscribed()' argument.", ReplaceWith("this.shareIn(scope, 0)"), DeprecationLevel.ERROR)
202+
# @Deprecated("Flow analogue of 'publish()' is 'shareIn'. publish().connect() is the default strategy (no extra call is needed), publish().autoConnect() translates to 'started = SharingStarted.Lazily' argument, publish().refCount() translates to 'started = SharingStarted.WhileSubscribed()' argument.", ReplaceWith("this.shareIn(scope, 0)"), DeprecationLevel.ERROR)
185203
- org.openrewrite.kotlin.replace.ReplaceKotlinMethod:
186204
methodPattern: 'kotlinx.coroutines.flow.FlowKt publish(kotlinx.coroutines.flow.Flow)'
187205
replacement: 'this.shareIn(scope, 0)'
188206
classpathFromResources:
189207
- 'kotlinx-coroutines-core-jvm-1'
190-
# @Deprecated("Flow analogue of 'publish(bufferSize)' is 'buffer' followed by 'shareIn'. publish().connect() is the default strategy (no extra call is needed), publish().autoConnect() translates to 'started = SharingStared.Lazily' argument, publish().refCount() translates to 'started = SharingStared.WhileSubscribed()' argument.", ReplaceWith("this.buffer(bufferSize).shareIn(scope, 0)"), DeprecationLevel.ERROR)
208+
# @Deprecated("Flow analogue of 'publish(bufferSize)' is 'buffer' followed by 'shareIn'. publish().connect() is the default strategy (no extra call is needed), publish().autoConnect() translates to 'started = SharingStarted.Lazily' argument, publish().refCount() translates to 'started = SharingStarted.WhileSubscribed()' argument.", ReplaceWith("this.buffer(bufferSize).shareIn(scope, 0)"), DeprecationLevel.ERROR)
191209
- org.openrewrite.kotlin.replace.ReplaceKotlinMethod:
192210
methodPattern: 'kotlinx.coroutines.flow.FlowKt publish(kotlinx.coroutines.flow.Flow, kotlin.Int)'
193211
replacement: 'this.buffer(bufferSize).shareIn(scope, 0)'
194212
classpathFromResources:
195213
- 'kotlinx-coroutines-core-jvm-1'
196-
# @Deprecated("Flow analogue of 'replay()' is 'shareIn' with unlimited replay. replay().connect() is the default strategy (no extra call is needed), replay().autoConnect() translates to 'started = SharingStared.Lazily' argument, replay().refCount() translates to 'started = SharingStared.WhileSubscribed()' argument.", ReplaceWith("this.shareIn(scope, Int.MAX_VALUE)"), DeprecationLevel.ERROR)
214+
# @Deprecated("Flow analogue of 'replay()' is 'shareIn' with unlimited replay. replay().connect() is the default strategy (no extra call is needed), replay().autoConnect() translates to 'started = SharingStarted.Lazily' argument, replay().refCount() translates to 'started = SharingStarted.WhileSubscribed()' argument.", ReplaceWith("this.shareIn(scope, Int.MAX_VALUE)"), DeprecationLevel.ERROR)
197215
- org.openrewrite.kotlin.replace.ReplaceKotlinMethod:
198216
methodPattern: 'kotlinx.coroutines.flow.FlowKt replay(kotlinx.coroutines.flow.Flow)'
199217
replacement: 'this.shareIn(scope, Int.MAX_VALUE)'
200218
classpathFromResources:
201219
- 'kotlinx-coroutines-core-jvm-1'
202-
# @Deprecated("Flow analogue of 'replay(bufferSize)' is 'shareIn' with the specified replay parameter. replay().connect() is the default strategy (no extra call is needed), replay().autoConnect() translates to 'started = SharingStared.Lazily' argument, replay().refCount() translates to 'started = SharingStared.WhileSubscribed()' argument.", ReplaceWith("this.shareIn(scope, bufferSize)"), DeprecationLevel.ERROR)
220+
# @Deprecated("Flow analogue of 'replay(bufferSize)' is 'shareIn' with the specified replay parameter. replay().connect() is the default strategy (no extra call is needed), replay().autoConnect() translates to 'started = SharingStarted.Lazily' argument, replay().refCount() translates to 'started = SharingStarted.WhileSubscribed()' argument.", ReplaceWith("this.shareIn(scope, bufferSize)"), DeprecationLevel.ERROR)
203221
- org.openrewrite.kotlin.replace.ReplaceKotlinMethod:
204222
methodPattern: 'kotlinx.coroutines.flow.FlowKt replay(kotlinx.coroutines.flow.Flow, kotlin.Int)'
205223
replacement: 'this.shareIn(scope, bufferSize)'
@@ -241,51 +259,51 @@ recipeList:
241259
replacement: 'this.flatMapLatest(transform)'
242260
classpathFromResources:
243261
- 'kotlinx-coroutines-core-jvm-1'
244-
# @Deprecated("cancel() is resolved into the extension of outer CoroutineScope which is likely to be an error.Use currentCoroutineContext().cancel() instead or specify the receiver of cancel() explicitly", ReplaceWith("currentCoroutineContext().cancel(cause)"), DeprecationLevel.ERROR)
262+
# @Deprecated("cancel() is resolved into the extension of outer CoroutineScope which is likely to be an error. Use currentCoroutineContext().cancel() instead or specify the receiver of cancel() explicitly", ReplaceWith("currentCoroutineContext().cancel(cause)"), DeprecationLevel.ERROR)
245263
- org.openrewrite.kotlin.replace.ReplaceKotlinMethod:
246-
methodPattern: 'kotlinx.coroutines.flow.LintKt cancel(java.util.concurrent.CancellationException)'
264+
methodPattern: 'kotlinx.coroutines.flow.LintKt cancel(kotlinx.coroutines.flow.FlowCollector, java.util.concurrent.CancellationException)'
247265
replacement: 'currentCoroutineContext().cancel(cause)'
248266
classpathFromResources:
249267
- 'kotlinx-coroutines-core-jvm-1'
250268
# @Deprecated("Applying 'cancellable' to a SharedFlow has no effect. See the SharedFlow documentation on Operator Fusion.", ReplaceWith("this"), DeprecationLevel.ERROR)
251269
- org.openrewrite.kotlin.replace.ReplaceKotlinMethod:
252-
methodPattern: 'kotlinx.coroutines.flow.LintKt cancellable()'
270+
methodPattern: 'kotlinx.coroutines.flow.LintKt cancellable(kotlinx.coroutines.flow.SharedFlow)'
253271
replacement: 'this'
254272
classpathFromResources:
255273
- 'kotlinx-coroutines-core-jvm-1'
256274
# @Deprecated("SharedFlow never completes, so this operator typically has not effect, it can only catch exceptions from 'onSubscribe' operator", ReplaceWith("this"), DeprecationLevel.WARNING)
257275
- org.openrewrite.kotlin.replace.ReplaceKotlinMethod:
258-
methodPattern: 'kotlinx.coroutines.flow.LintKt catch(*)'
276+
methodPattern: 'kotlinx.coroutines.flow.LintKt catch(kotlinx.coroutines.flow.SharedFlow, *)'
259277
replacement: 'this'
260278
classpathFromResources:
261279
- 'kotlinx-coroutines-core-jvm-1'
262280
# @Deprecated("Applying 'conflate' to StateFlow has no effect. See the StateFlow documentation on Operator Fusion.", ReplaceWith("this"), DeprecationLevel.ERROR)
263281
- org.openrewrite.kotlin.replace.ReplaceKotlinMethod:
264-
methodPattern: 'kotlinx.coroutines.flow.LintKt conflate()'
282+
methodPattern: 'kotlinx.coroutines.flow.LintKt conflate(kotlinx.coroutines.flow.StateFlow)'
265283
replacement: 'this'
266284
classpathFromResources:
267285
- 'kotlinx-coroutines-core-jvm-1'
268286
# @Deprecated("Applying 'distinctUntilChanged' to StateFlow has no effect. See the StateFlow documentation on Operator Fusion.", ReplaceWith("this"), DeprecationLevel.ERROR)
269287
- org.openrewrite.kotlin.replace.ReplaceKotlinMethod:
270-
methodPattern: 'kotlinx.coroutines.flow.LintKt distinctUntilChanged()'
288+
methodPattern: 'kotlinx.coroutines.flow.LintKt distinctUntilChanged(kotlinx.coroutines.flow.StateFlow)'
271289
replacement: 'this'
272290
classpathFromResources:
273291
- 'kotlinx-coroutines-core-jvm-1'
274292
# @Deprecated("Applying 'flowOn' to SharedFlow has no effect. See the SharedFlow documentation on Operator Fusion.", ReplaceWith("this"), DeprecationLevel.ERROR)
275293
- org.openrewrite.kotlin.replace.ReplaceKotlinMethod:
276-
methodPattern: 'kotlinx.coroutines.flow.LintKt flowOn(kotlin.coroutines.CoroutineContext)'
294+
methodPattern: 'kotlinx.coroutines.flow.LintKt flowOn(kotlinx.coroutines.flow.SharedFlow, kotlin.coroutines.CoroutineContext)'
277295
replacement: 'this'
278296
classpathFromResources:
279297
- 'kotlinx-coroutines-core-jvm-1'
280298
# @Deprecated("SharedFlow never completes, so this operator has no effect.", ReplaceWith("this"), DeprecationLevel.WARNING)
281299
- org.openrewrite.kotlin.replace.ReplaceKotlinMethod:
282-
methodPattern: 'kotlinx.coroutines.flow.LintKt retry(kotlin.Long, *)'
300+
methodPattern: 'kotlinx.coroutines.flow.LintKt retry(kotlinx.coroutines.flow.SharedFlow, kotlin.Long, *)'
283301
replacement: 'this'
284302
classpathFromResources:
285303
- 'kotlinx-coroutines-core-jvm-1'
286304
# @Deprecated("SharedFlow never completes, so this operator has no effect.", ReplaceWith("this"), DeprecationLevel.WARNING)
287305
- org.openrewrite.kotlin.replace.ReplaceKotlinMethod:
288-
methodPattern: 'kotlinx.coroutines.flow.LintKt retryWhen(*)'
306+
methodPattern: 'kotlinx.coroutines.flow.LintKt retryWhen(kotlinx.coroutines.flow.SharedFlow, *)'
289307
replacement: 'this'
290308
classpathFromResources:
291309
- 'kotlinx-coroutines-core-jvm-1'
@@ -297,3 +315,9 @@ recipeList:
297315
- 'kotlinx.coroutines.selects.onTimeout'
298316
classpathFromResources:
299317
- 'kotlinx-coroutines-core-jvm-1'
318+
# @Deprecated("Use the overload that also accepts the `value` and the coroutine context in lambda", ReplaceWith("resume(value) { cause, _, _ -> onCancellation(cause) }"), DeprecationLevel.WARNING)
319+
- org.openrewrite.kotlin.replace.ReplaceKotlinMethod:
320+
methodPattern: 'kotlinx.coroutines.sync.MutexImpl$CancellableContinuationWithOwner resume(kotlin.Unit, kotlin.Function1)'
321+
replacement: 'resume(value) { cause, _, _ -> onCancellation(cause) }'
322+
classpathFromResources:
323+
- 'kotlinx-coroutines-core-jvm-1'

rewrite-kotlin/src/main/resources/META-INF/rewrite/kotlin-deprecations-kotlinx-serialization-core-1.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# limitations under the License.
1515
#
1616

17-
# Recipes generated for `@Deprecated` methods with `ReplaceWith` in `org.jetbrains.kotlinx:kotlinx-serialization-core:1.6.3`
17+
# Recipes generated for `@Deprecated` methods with `ReplaceWith` in `org.jetbrains.kotlinx:kotlinx-serialization-core:1.8.0`
1818
#
1919

2020
---

rewrite-kotlin/src/test/java/org/openrewrite/kotlin/replace/DeprecatedMethodScanner.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,16 @@ private String buildMethodPatternFromKotlin(String className, KmFunction functio
318318
pattern.append(function.getName());
319319
pattern.append("(");
320320

321-
List<KmValueParameter> params = function.getValueParameters();
322-
if (!params.isEmpty()) {
323-
pattern.append(params.stream()
324-
.map(p -> typeToPattern(p.getType()))
325-
.collect(joining(", ")));
321+
StringJoiner paramJoiner = new StringJoiner(", ");
322+
// Extension functions have a receiver type that becomes the first JVM parameter
323+
KmType receiverType = function.getReceiverParameterType();
324+
if (receiverType != null) {
325+
paramJoiner.add(typeToPattern(receiverType));
326+
}
327+
for (KmValueParameter param : function.getValueParameters()) {
328+
paramJoiner.add(typeToPattern(param.getType()));
326329
}
330+
pattern.append(paramJoiner);
327331
pattern.append(")");
328332

329333
return pattern.toString();
Binary file not shown.

0 commit comments

Comments
 (0)