Skip to content

Commit 1d0ded2

Browse files
jjohnstnvogella
authored andcommitted
Add N&N for renaming unused locals to unnamed variable
eclipse-jdt/eclipse.jdt.ui#1747
1 parent 4a86d68 commit 1d0ded2

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed
91.5 KB
Loading
115 KB
Loading

news/4.34/jdt.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,27 @@ <h2>Java Editor </h2>
7676
<p><img src="images/ifelseboolean-after.png" alt="convert boolean if/else to single return after"/></p>
7777
</td>
7878
</tr>
79+
<tr id="unused-to-unnamed-quickfix">
80+
<td class="title"><a href="#unused-to-unnamed-quickfix">Rename unused to unnamed quickfix/cleanup</a></td>
81+
<td class="content">
82+
The quick-fix/clean-up for unused local variables has been enhanced when using Java 22 or above to rename to the unnamed variable ("_") where appropriate. These situations include:
83+
<ul>
84+
<li>unused lambda parameters</li>
85+
<li>unused try-with-resources resources</li>
86+
<li>unused pattern variables in switch</li>
87+
<li>unused variables in enhanced for statement</li>
88+
<li>unused variables in regular for statement</li>
89+
</ul>
90+
<p>In these cases, a quick-fix will be offered to rename to the unnamed variable. The quick-fix is a multi-fix and will also offer to fix multiple instances of the problem.</p>
91+
<p>For example, hovering one of the unused variables in the file will show:</p>
92+
<p><img src="images/unnamed-quickfix-before.png" alt="rename to unnamed variable before"/></p>
93+
<p>and selecting to fix multiple problems of the same category results in:</p>
94+
<p><img src="images/unnamed-quickfix-after.png" alt="rename to unnamed variable after"/></p>
95+
<p>The new rename functionality is embedded into the existing <b>Remove unused local variables</b> clean-up found on the <b>Unnecessary Code</b> tab of the clean-up configuration dialog. The clean-up
96+
will rename to the unnamed variable for unused locals or lambda parameters when
97+
the compliance level is 22 or above.</p>
98+
</td>
99+
</tr>
79100
<tr id="if-else-to-switch-null-handling">
80101
<td class="title"><a href="#if-else-to-switch-null-handling">Null handling for if/else to switch clean-up</a></td>
81102
<td class="content">

0 commit comments

Comments
 (0)