Skip to content

Add recipe generator for Kotlin's Deprecated ReplaceWith#57

Closed
timtebeek wants to merge 3 commits into
mainfrom
generator-for-kotlin-Deprecated-ReplaceWith
Closed

Add recipe generator for Kotlin's Deprecated ReplaceWith#57
timtebeek wants to merge 3 commits into
mainfrom
generator-for-kotlin-Deprecated-ReplaceWith

Conversation

@timtebeek

Copy link
Copy Markdown
Member

Comment thread src/test/java/org/openrewrite/kotlin/internal/KotlinDeprecatedMethodScanner.java Outdated
Comment thread src/test/java/org/openrewrite/kotlin/internal/KotlinDeprecatedMethodScanner.java Outdated
Comment thread src/test/java/org/openrewrite/kotlin/internal/KotlinDeprecatedMethodScanner.java Outdated
Comment thread src/test/java/org/openrewrite/kotlin/internal/KotlinDeprecatedMethodScanner.java Outdated
Comment thread src/test/java/org/openrewrite/kotlin/internal/KotlinDeprecatedMethodScanner.java Outdated
Comment thread src/test/java/org/openrewrite/kotlin/internal/KotlinDeprecatedMethodScanner.java Outdated
Comment thread src/test/java/org/openrewrite/kotlin/internal/KotlinDeprecatedMethodScanner.java Outdated
timtebeek added a commit to openrewrite/rewrite that referenced this pull request Jan 17, 2026
Follows the pattern we already have for `InlineMethodCalls`, but now for Kotlin.

Related openrewrite/rewrite-third-party#57
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
import kotlin.Deprecated;
import kotlin.Metadata;
import kotlin.ReplaceWith;
import kotlin.metadata.*;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import kotlin.metadata.*;
import kotlin.metadata.KmClass;
import kotlin.metadata.KmClassifier;
import kotlin.metadata.KmFunction;
import kotlin.metadata.KmPackage;
import kotlin.metadata.KmType;
import kotlin.metadata.KmValueParameter;

Comment on lines +189 to +190
} else if (artifactId.startsWith("kotlinx-coroutines")) {
return "org.jetbrains.kotlinx";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else if (artifactId.startsWith("kotlinx-coroutines")) {
return "org.jetbrains.kotlinx";
}
if (artifactId.startsWith("kotlinx-coroutines")) {
}
if (artifactId.startsWith("kotlinx-serialization")) {

Comment on lines +264 to +265
} else {
return buildMethodPatternFromReflection(className, method);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else {
return buildMethodPatternFromReflection(className, method);
return buildMethodPatternFromReflection(className, method);

if (classifier instanceof KmClassifier.Class classClassifier) {
String name = classClassifier.getName().replace('/', '.');
return mapKotlinType(name);
} else if (classifier instanceof KmClassifier.TypeParameter) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else if (classifier instanceof KmClassifier.TypeParameter) {
}
if (classifier instanceof KmClassifier.TypeParameter) {

import kotlin.Deprecated;
import kotlin.Metadata;
import kotlin.ReplaceWith;
import kotlin.metadata.*;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import kotlin.metadata.*;
import kotlin.metadata.KmClass;
import kotlin.metadata.KmClassifier;
import kotlin.metadata.KmFunction;
import kotlin.metadata.KmPackage;
import kotlin.metadata.KmType;
import kotlin.metadata.KmValueParameter;

@timtebeek

Copy link
Copy Markdown
Member Author

@timtebeek timtebeek closed this Jan 25, 2026
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Jan 25, 2026
@timtebeek timtebeek deleted the generator-for-kotlin-Deprecated-ReplaceWith branch January 25, 2026 19:54
timtebeek added a commit to openrewrite/rewrite that referenced this pull request Feb 13, 2026
…ceWith` (#6561)

* Add `ReplaceDeprecatedKotlinMethod` with `template` argument

Follows the pattern we already have for `InlineMethodCalls`, but now for Kotlin.

Related openrewrite/rewrite-third-party#57

* Update recipes.csv

* Move and add scanner/generator for faster iterations

* Improve the scanner, generator and replacement recipe

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Move filter to scanner; keep Kotlin types and use `*` for generic types

* Handle extension functions and receivers

* Add comments to show original expression

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Special handling for suspend and coroutines

* Add recipes for Kotlinx

* Polish `ReplaceDeprecatedKotlinMethod`

* Also support replacements for constructors

* Rename recipe

* Add a test for constructor replacement

* Quick renames

* Expect explicit groupId passed in

* Apply formatter

* Polish DeprecatedMethodScanner

* Collapse catch blocks

* Use `<init>`

Co-authored-by: Knut Wannheden <knut@moderne.io>

* Exclude transitive kotlin-stdlib from kotlin-metadata-jvm (#6726)

The kotlin-metadata-jvm:2.1.0 dependency pulls in kotlin-stdlib:2.1.0,
which conflicts with the parser's embedded kotlin-stdlib:1.9.25 and
causes existing Kotlin tests to fail with metadata version errors.

Co-authored-by: Tim te Beek <tim@mac.home>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>

* Comment out the testRuntime dependencies when not generating

* Increase heap size

* Update recipes.csv

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Knut Wannheden <knut@moderne.io>
Co-authored-by: Tim te Beek <tim@mac.home>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Recipe to apply Kotlin's @Deprecated(replaceWith=...) suggestions

1 participant