IntelliJ IDEA 14.1.0 Help

Invert Boolean

The Invert Boolean refactoring allows you to change the sense of a Boolean method or variable to the opposite one.

Example

BeforeAfter
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; ... }

To invert the sense of a boolean method or variable

  1. Place the caret at the name of the method or variable to be refactored.
  2. Do one of the following:
    • On the main menu choose Refactor | Invert Boolean.
    • On the context menu, choose Refactor | Invert Boolean.
  3. In the Invert Boolean dialog, specify the name for the inverted method or variable.
  4. Preview and apply changes.

See Also

Last modified: 29 May 2015