IDEA already has some quickfixes for refactoring boolean expressions, for example applying Morgan's Law, but there are still some refactorings which are not supported.
For example I needed the Distributive Law to simplify the following code, but IDEA does not have a refactoring for that. Also I had to apply the rule (i % 2 == 0) equals (i % 2 != 1), and an intention action for it might also be possible.
String propEvenOdd;
boolean createEven;
int i;
if ((propEvenOdd == null || !createEven || i % 2 != 1) &&
(propEvenOdd == null || createEven || i % 2 != 0)) {
// do something
}
// ...after some refactoring:
if (propEvenOdd == null
|| (createEven && i % 2 == 0)
|| (!createEven && i % 2 == 1)) {
// do something
}
In short, I would like IDEA to have more intention actions for boolean handling, so that the above refactoring would be fully possible by using only the intention actions. This would prevent human errors when refactoring complicated boolean expressions.
Here are some lists of the laws of boolean algebra:
IDEA already has some quickfixes for refactoring boolean expressions, for example applying Morgan's Law, but there are still some refactorings which are not supported.
For example I needed the Distributive Law to simplify the following code, but IDEA does not have a refactoring for that. Also I had to apply the rule (i % 2 == 0) equals (i % 2 != 1), and an intention action for it might also be possible.
String propEvenOdd;
boolean createEven;
int i;
if ((propEvenOdd == null || !createEven || i % 2 != 1) &&
(propEvenOdd == null || createEven || i % 2 != 0)) {
// do something
}
// ...after some refactoring:
if (propEvenOdd == null
|| (createEven && i % 2 == 0)
|| (!createEven && i % 2 == 1)) {
// do something
}