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

Upstream RemoveMethodInvocationsVisitor #4639

Merged
merged 21 commits into from
Nov 12, 2024

Conversation

nmck257
Copy link
Collaborator

@nmck257 nmck257 commented Nov 1, 2024

What's changed?

This visitor existed in rewrite-spring; I'm moving it over here (with some minor bugfixes)
https://github.com/openrewrite/rewrite-spring/blob/b0a95c850c521ebf6104c946f044ef9c1c43bd5b/src/main/java/org/openrewrite/java/spring/RemoveMethodInvocationsVisitor.java#L39

What's your motivation?

This visitor had a bug with long invocation chains which include args which are themselves long invocation chains. Also some NPE risks. I wanted to fix those, and I figure there's nothing specific to rewrite-spring in here so it makes sense to give broader reach.
It could probably also be wrapped into a recipe for convenient consumption in the future.

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

I added two new test cases:

  • removeFromWithinArguments (verifies the bugfix I cared about)
  • removeWithoutSelect (annotated as expected to fail; something I noticed along the way. my src changes convert this test case from uncaught NPE to no-changes)

~Next week I'll probably deprecate all the original code in rewrite-spring and adjust the impls to pass through to this class.

Anyone you would like to review specifically?

Have you considered any alternatives or workarounds?

I could apply the same fixes in-place in rewrite-spring, if preferred

Any additional context

I took care to preserve git history from rewrite-spring for these files, so I'd love to not squash the PR on merge

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

knutwannheden and others added 19 commits April 12, 2023 11:59
* Update for rewrite 8.0

* Cosmetics

* Fix a few more issues

* Fix a few more test failures

* Fix a few more test failures

* Upgrade recipes to new `JavaTemplate` API

* Replace `getRecipeList()` overrides with `@Getter(lazy = true)` property

* Consistently use `latest.release` or `latest.integration`

* Revert "Replace `getRecipeList()` overrides with `@Getter(lazy = true)` property"

This reverts commit 897d59e79c9515564da45911ce2246934c5b1ae7.

* Migrate to new `Recipe#getInitialState(ExecutionContext)` API

* Polish

* Fix a broken test

Due to reversal of logic after inlining `doAfterVisit()` logic.

* Fix another broken test

We should change the `UpgradeDependencyVersion` in `rewrite-java-dependencies` so that workarounds like this are not necessary.

* Fix last failing test (use `doAfterVisit()` again)

---------

Co-authored-by: Sam Snyder <[email protected]>
* Update for rewrite 8.0

* Cosmetics

* Fix a few more issues

* Fix a few more test failures

* Fix a few more test failures

* Upgrade recipes to new `JavaTemplate` API

* Replace `getRecipeList()` overrides with `@Getter(lazy = true)` property

* Consistently use `latest.release` or `latest.integration`

* Revert "Replace `getRecipeList()` overrides with `@Getter(lazy = true)` property"

This reverts commit 897d59e79c9515564da45911ce2246934c5b1ae7.

* Migrate to new `Recipe#getInitialState(ExecutionContext)` API

* Polish

* Fix a broken test

Due to reversal of logic after inlining `doAfterVisit()` logic.

* Fix another broken test

We should change the `UpgradeDependencyVersion` in `rewrite-java-dependencies` so that workarounds like this are not necessary.

* Fix last failing test (use `doAfterVisit()` again)

---------

Co-authored-by: Sam Snyder <[email protected]>
…fter porting them over from rewrite-spring with preserved history
nmck257 and others added 2 commits November 1, 2024 17:20
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@@ -64,6 +64,7 @@ dependencies {
testRuntimeOnly(project(":rewrite-java-17"))
testImplementation("com.tngtech.archunit:archunit:1.0.1")
testImplementation("com.tngtech.archunit:archunit-junit5:1.0.1")
testImplementation("org.junit-pioneer:junit-pioneer:2.0.0")
Copy link
Member

Choose a reason for hiding this comment

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

I would rather use JUnit 5's built in assertThrows() unless there is some really compelling advantage to @ExpectedToFail

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've seen it in other modules, and I like the semantics of it for documenting a not-yet-implemented feature with a test.
But yeah, it does require another dep, and we can get similar functionality with assertThrows. I can swap it out when I'm at my desk later.

Copy link
Contributor

Choose a reason for hiding this comment

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

I also quite like @ExpectedToFail for tests which test something that is supposed to work but doesn't due to a bug. I use assertThrows() when I want to test that something is supposed to throw an exception.

When the bug is fixed, all I have to do is to remove the @ExpectedToFail annotation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sounds like @sambsnyd is outvoted here, unless I hear otherwise :)
any other review concerns for this PR, before we rebase-not-squash and merge?
@timtebeek , @knutwannheden

@nmck257 nmck257 merged commit cf71b0d into main Nov 12, 2024
2 checks passed
@nmck257 nmck257 deleted the feature/RemoveMethodInvocationsVisitor branch November 12, 2024 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants