Can CLion Refactor Multiple if Statements Into a Single If Statement?

Answered

I ran across some code I want to refactor, and I was wondering if CLion knows how to refactor it the way I want. Consider the following code snippet:

if (aBool && *s == '4') {    if (j != 0) {        /* some code here */    }}

The two if statements can (and should) be combined into a single if statement:

if (aBool && *s == '4' && j != 0) {
    /* some code here */
}

Is there a way to have CLion merge those like that?

0
2 comments

Hi! Please check that the "Merge nested ‘if’s" intention is enabled in File | Settings | Editor | Intentions | C and C++.

If it's enabled, CLion should suggest you to alter the code provided by you. Please place the cursor on this code line and click on a yellow bulb or press Alt + Enter to see the suggested options:

0

Thanks! I figured it would, I just didn't know how. Clicking the light bulb... THAT trick I will remember! I'm guessing a lot of good stuff is available via that little light bulb.

0

Please sign in to leave a comment.