The Invert Boolean refactoring allows you to change the sense of a Boolean method or variable to the opposite one.
This refactoring is also available from UML Class diagram.
Example
| Before | After |
|---|---|
private double a; ... public boolean method() { if (a > 15 && a < 100) { a = 5; return true; } return false; } |
private double a; ... public boolean method() { if (a > 15 && a < 100) { a = 5; return false; } return true; } |
boolean b = true; ... public double method() { ... b = false; ... } |
boolean b = false; ... public double method() { ... b = true; ... } |
- Place the caret at the name of the method or variable to be refactored.
- Do one of the following:
- On the main menu choose .
- On the context menu, choose .
- In the Invert Boolean dialog, specify the name for the inverted method or variable.
- Preview and apply changes.