Inspectopedia Help

'if' statement with identical branches

Reports if statements in which common parts can be extracted from the branches.

These common parts are independent from the condition and make if statements harder to understand.

Example:

if (x > 12) { doSomethingBefore(); doSomethingDifferent1(); doSomethingAfter(); } else { doSomethingBefore(); doSomethingDifferent2(); doSomethingAfter(); }

After the quick-fix is applied:

doSomethingBefore(); if (x > 12) { doSomethingDifferent1(); } else { doSomethingDifferent2(); } doSomethingAfter();

Updated in 2018.1

Inspection options

Here you can find the description of settings available for the 'if' statement with identical branches inspection, and the reference of their default values.

Highlight when the last common statement is a call

Not selected

Highlight else-if chains that can be simplified

Not selected

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin:

Java, 241.16690

Last modified: 29 April 2024