AutoRefactor icon indicating copy to clipboard operation
AutoRefactor copied to clipboard

New refactoring - Simplify more complex boolean expressions

Open JnRouvignac opened this issue 12 years ago • 0 comments

Example 1

This code:

if (b) {
    return someMethod();
} else {
    return false;
}

Can be rewritten to:

return b && someMethod();

Example 2

This code:

if (b) {
    return someMethod();
} else {
    return true;
}

Can be rewritten to:

return !b || someMethod();

Variations

  • with local variable declaration
  • with local variable assignment
  • with instance variable assignment
  • no else clause
  • use of boolean primitives
  • use of boolean objects
  • ...

JnRouvignac avatar Apr 25 '13 11:04 JnRouvignac