'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
Option | Type | Default |
---|---|---|
Highlight when the last common statement is a call | Checkbox | false |
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Java, 233.SNAPSHOT |
Last modified: 13 July 2023