rewrite-static-analysis icon indicating copy to clipboard operation
rewrite-static-analysis copied to clipboard

Replace nested ifs with one if and conditions joined with &&

Open greg-at-moderne opened this issue 9 months ago • 1 comments

What problem are you trying to solve?

Simplify code.

Describe the situation before applying the recipe

    class A {
        void foo(boolean a, boolean b) {
            if (a) {
                if (b) {
                }
            }
        }
    }

Describe the situation after applying the recipe

    class A {
        void foo(boolean a, boolean b) {
            if (a && b) {
            }
        }
    }

Things to take into account

  • parenthesis might or might not be needed
  • only applicable if there's no other logic in the outer if

greg-at-moderne avatar Apr 30 '25 12:04 greg-at-moderne

This issue is stale because it has not had any activity for 60 days. Remove question label or comment or this will be closed in two weeks. Issues may be reopened when there is renewed interest.

github-actions[bot] avatar Jul 28 '25 11:07 github-actions[bot]