Bug 572851 - [AutoRefactor #75/153] Redundant truth
Directly checks boolean values instead of comparing them with
true/false:
- The operator can be equals, not equals or XOR,
- The constants can be a literal or a java.lang.Boolean constant,
- One operand should be primitive so no new null pointer exceptions may
occur.
Given:
if (isValid == true) {
int i = 0;
}
When:
Applying "Boolean value rather than comparison" clean up...
Then:
if (isValid) {
int i = 0;
}
Change-Id: Ie59f0a572f86f12a0f75b9d94d95119c402a627a
Signed-off-by: Fabrice Tiercelin <fabrice.tiercelin@yahoo.fr>
Depends-On: If40bd448d4654c66c10587a5c75d1358f385e59d
diff --git a/4.20/images/redundant-truth-after.png b/4.20/images/redundant-truth-after.png
new file mode 100644
index 0000000..9f34538
--- /dev/null
+++ b/4.20/images/redundant-truth-after.png
Binary files differ
diff --git a/4.20/images/redundant-truth-before.png b/4.20/images/redundant-truth-before.png
new file mode 100644
index 0000000..7da8865
--- /dev/null
+++ b/4.20/images/redundant-truth-before.png
Binary files differ
diff --git a/4.20/images/redundant-truth-preferences.png b/4.20/images/redundant-truth-preferences.png
new file mode 100644
index 0000000..8d0548b
--- /dev/null
+++ b/4.20/images/redundant-truth-preferences.png
Binary files differ
diff --git a/4.20/jdt.html b/4.20/jdt.html
index 2ff1ba1..576a757 100644
--- a/4.20/jdt.html
+++ b/4.20/jdt.html
@@ -179,6 +179,30 @@
</td>
</tr>
+ <tr id="redundant-truth"> <!-- https://bugs.eclipse.org/bugs/show_bug.cgi?id=572851 -->
+ <td class="title"><a href="#redundant-truth">Redundant truth clean up</a></td>
+ <td class="content">
+ A new clean up has been added that directly checks boolean values instead of comparing them with <code>true</code>/<code>false</code>.
+ <p>
+ The operator can be equals, not equals or XOR.
+ The constants can be a literal or a <code>java.lang.Boolean</code> constant.
+ One operand should be primitive so no new <code>null</code> pointer exceptions may occur.
+ </p>
+ <p>
+ To apply the clean up, select <b>Boolean value rather than comparison</b> check box on the <b>Unnecessary Code</b> tab in your clean up profile.
+ </p>
+ <p><img src="images/redundant-truth-preferences.png" alt="Preferences" width="800"/></p>
+ <p>
+ For the given code:
+ </p>
+ <p><img src="images/redundant-truth-before.png" alt="Before"/></p>
+ <p>
+ One gets:
+ </p>
+ <p><img src="images/redundant-truth-after.png" alt="After"/></p>
+ </td>
+ </tr>
+
<tr id="implicit-comparator"> <!-- https://bugs.eclipse.org/bugs/show_bug.cgi?id=572426 -->
<td class="title"><a href="#implicit-comparator">Implicit comparator clean up</a></td>
<td class="content">