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

fix(DefaultComesLast)[#289]: duplicate case fix #295

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

nbenjamin
Copy link

What's changed?

Fix for DefaultComesLast recipe creates duplicate case #289

What's your motivation?

Bug fix

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 a lot for taking this on! I have a slight worry about the test case, and with that the logic that we have now. Would you agree we need to assert a different outcome @delanym ?

@timtebeek timtebeek added the bug Something isn't working label May 19, 2024
@timtebeek timtebeek marked this pull request as draft May 21, 2024 08:21
Copy link
Contributor

@punkratz312 punkratz312 left a comment

Choose a reason for hiding this comment

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

fell free to leverage operator first speaking api

@@ -75,7 +75,7 @@ public J.Switch visitSwitch(J.Switch switch_, P p) {
aCase.getStatements().isEmpty() && !foundNonEmptyCase) {
casesGroupedWithDefault.add(aCase);
} else {
if (defaultCase != null && defaultCase.getStatements().isEmpty() && !foundNonEmptyCase) {
if (defaultCase != null && defaultCase.getStatements().isEmpty() && foundNonEmptyCase) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (defaultCase != null && defaultCase.getStatements().isEmpty() && foundNonEmptyCase) {
if (nonNull(defaultCase) && isEmpty(defaultCase.getStatements()) && foundNonEmptyCase) {

https://stackoverflow.com/questions/28140193/purpose-of-objects-isnull-objects-nonnull
https://commons.apache.org/proper/commons-collections/apidocs/org/apache/commons/collections4/CollectionUtils.html#isEmpty(java.util.Collection)

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/staticanalysis/ChainStringBuilderAppendCalls.java
    • lines 36-38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

5 participants