Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimplifyWebTestClientCalls does not work on Kotlin code #663

Merged

Conversation

barbulescu
Copy link
Contributor

@barbulescu barbulescu commented Jan 11, 2025

What's changed?

Add support for both int (Java) and long (Kotlin) status code types.

What's your motivation?

Have this recipe work on Kotlin code.

Anything in particular you'd like reviewers to focus on?

Anyone you would like to review specifically?

Have you considered any alternatives or workarounds?

Any additional context

Followed the instructions on Discord.

Wanted to add support for HttpStatus argument but one extra step is to remove the import if not used anywhere else.
Decided to have a follow-up PR for this fix.

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@timtebeek timtebeek self-requested a review January 11, 2025 18:18
@timtebeek timtebeek added enhancement New feature or request recipe Recipe requested labels Jan 11, 2025
@timtebeek
Copy link
Contributor

Thanks a lot @barbulescu ; you've stumbled upon an issue with the underlying KotlinParser, which I've logged here:

That meant that literals of the type int where returning a Long value as you've discovered, which then needed the casts seen here. Ideally we fix this upstream; I'll try my hand at that first.

@barbulescu barbulescu marked this pull request as ready for review January 11, 2025 19:50
@barbulescu barbulescu marked this pull request as draft January 11, 2025 19:51
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • src/main/java/org/openrewrite/java/spring/http/SimplifyWebTestClientCalls.java
    • lines 30-31

@timtebeek
Copy link
Contributor

You've uncovered another imperfection with the way we represent types that come from Java libraries in Kotlin:

That'll negatively affect our ability to match methods used in Kotlin code, such that existing recipes might not match where they should. We should take a closer look in rewrite-kotlin in how that type information is built up, and ensure Java types are used, or adjust the matcher to match both Java and Kotlin types for int and kotlin.Int` and others.

@timtebeek timtebeek marked this pull request as ready for review January 11, 2025 22:37
Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Thanks for the necessary adjustments to make this work for Kotlin as well, and helping uncover two imperfections upstream in rewrite-kotlin, and the help in getting one of those cleared out already. We'll merge this iteration and can separately look to cover the HttpStatus case you're after indeed.

@timtebeek timtebeek merged commit 4192cfb into openrewrite:main Jan 11, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request recipe Recipe requested
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants