Bug 572790 - [AutoRefactor #74/153] 1 if rather than duplicate
Merge consecutive if statements with same code block that end with a
jump statement:
Given:
if (i1 == 0) {
System.out.println("The same code");
return;
}
if (i1 == 1) {
System.out.println("The same code");
return;
}
System.out.println("Next code");
When:
Applying "One if rather than duplicate blocks that fall through" clean
up...
Then:
if ((i1 == 0) || (i1 == 1)) {
System.out.println("The same code");
return;
}
System.out.println("Next code");
Change-Id: I42fa0c8c62e83f5d2f9c237601e377cd23b3e1c0
Signed-off-by: Fabrice Tiercelin <fabrice.tiercelin@yahoo.fr>
Depends-On: I94d94c3f1bb101f74a10d320baff0ae3a938a4d6
diff --git a/4.20/images/one-falling-through-if-after.png b/4.20/images/one-falling-through-if-after.png
new file mode 100644
index 0000000..098ae6c
--- /dev/null
+++ b/4.20/images/one-falling-through-if-after.png
Binary files differ
diff --git a/4.20/images/one-falling-through-if-before.png b/4.20/images/one-falling-through-if-before.png
new file mode 100644
index 0000000..494c15e
--- /dev/null
+++ b/4.20/images/one-falling-through-if-before.png
Binary files differ
diff --git a/4.20/images/one-falling-through-if-preferences.png b/4.20/images/one-falling-through-if-preferences.png
new file mode 100644
index 0000000..945a461
--- /dev/null
+++ b/4.20/images/one-falling-through-if-preferences.png
Binary files differ
diff --git a/4.20/jdt.html b/4.20/jdt.html
index 576a757..0c0b9db 100644
--- a/4.20/jdt.html
+++ b/4.20/jdt.html
@@ -157,6 +157,25 @@
</td>
</tr>
+ <tr id="one-falling-through-if"> <!-- https://bugs.eclipse.org/bugs/show_bug.cgi?id=572790 -->
+ <td class="title"><a href="#one-falling-through-if">One if rather than duplicate blocks that fall through clean up</a></td>
+ <td class="content">
+ A new clean up has been added that merges consecutive <code>if</code> statements with same code block that end with a jump statement.
+ <p>
+ To apply the clean up, select <b>Single 'if' statement rather than duplicate blocks that fall through</b> check box on the <b>Duplicate code</b> tab in your clean up profile.
+ </p>
+ <p><img src="images/one-falling-through-if-preferences.png" alt="Preferences" width="800"/></p>
+ <p>
+ For the given code:
+ </p>
+ <p><img src="images/one-falling-through-if-before.png" alt="Before"/></p>
+ <p>
+ One gets:
+ </p>
+ <p><img src="images/one-falling-through-if-after.png" alt="After"/></p>
+ </td>
+ </tr>
+
<tr id="valueof-rather-than-instantiation"> <!-- https://bugs.eclipse.org/bugs/show_bug.cgi?id=572234 -->
<td class="title"><a href="#valueof-rather-than-instantiation">valueOf() rather than instantiation clean up</a></td>
<td class="content">