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

rewise early exit to positive condition in EqualsAvoidsNull #488

Conversation

pankratz76
Copy link
Contributor

@pankratz76 pankratz76 commented Mar 25, 2025

What's changed?

  • rewise early exit to positive condition in EqualsAvoidsNull
  • separate concerns: one thing only

What's your motivation?

  • clean code

@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Mar 25, 2025
@pankratz76 pankratz76 changed the title naturalize if condition in EqualsAvoidsNull rewise early exit to positive condition in EqualsAvoidsNull Mar 25, 2025
@pankratz76 pankratz76 changed the title rewise early exit to positive condition in EqualsAvoidsNull rewise early exit to positive condition in EqualsAvoidsNull Mar 25, 2025
@pankratz76 pankratz76 marked this pull request as ready for review March 25, 2025 18:34
@pankratz76
Copy link
Contributor Author

@greg-at-moderne kindly request feedback

Copy link
Contributor

@greg-at-moderne greg-at-moderne left a comment

Choose a reason for hiding this comment

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

TBH, I don't fully find it better with the overloaded standard visit... method.

@pankratz76
Copy link
Contributor Author

TBH, I don't fully find it better with the overloaded standard visit... method.

yes thats non a good story telling. Structuring it with SOC is ok, right? Its just about finding the proper size and name. Please see updates version. Thx

Expression firstArgument = m.getArguments().get(0);

private J applyLiteralsFirstInComparisons(J.MethodInvocation m, Expression firstArgument) {
checkPotentialNullCheck(m, getCursor().getParentTreeCursor().getValue());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know how checkPotentialNullCheck is working, but from the storytelling here, I would expect this to act as an early exit. A null check does not get flipped, which doesn’t make sense because null is checked again below in literalsFirstInComparisonsNull, so it must be treated as well.

Therefore, it seems more like a treatment or preparation step and should be renamed to preparePotentialNullCheck to better reflect its purpose in allowing the process to continue.

@pankratz76 pankratz76 force-pushed the test-equalsAvoidsNullNonIdempotent-flip branch from 133ce35 to e8a1460 Compare March 25, 2025 19:16
@pankratz76
Copy link
Contributor Author

#497

@pankratz76 pankratz76 closed this Apr 8, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Apr 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants