Skip to content

Commit

Permalink
Smarter extract to local variable refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jjohnstn authored and akurtakov committed Nov 17, 2022
1 parent a5d1154 commit 7672a9f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
Binary file added 4.26/images/extract-local-var-after.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 4.26/images/extract-local-var-before.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions 4.26/jdt.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@ <h2>Java Editor </h2>
</td>
</tr>

<tr id="smarter-extract-local"> <!-- https://github.com/eclipse-jdt/eclipse.jdt.ui/pull/66 -->
<td class="title"><a href="#smarter-extract-local">Extract local variable improved</a></td>
<td class="content">
The extract local variable refactoring available from <b>Refactor -> Extract Local Variable</b> has been improved to recognize
situations where adding the local variable may cause a NullPointerException as it precedes code used to check for null. In these cases,
the positioning of the local variable is altered so the null check occurs before the variable declaration.
<p>For example, in the following class, a call to the String length() method is made after verifying the String variable is not null.</p>
<p><img src="images/extract-local-var-before.png" alt="Before"/></p>
<p>If we select the <b>s.length()</b> call and choose to extract this to a local variable to replace all occurrences, the result is:</p>
<p><img src="images/extract-local-var-after.png" alt="Before"/></p>
<p>Note how the declaration is after the if statement to ensure that the check for null occurs first</p>
</td>
</tr>
<!-- ******************* End of Java Editor ************************************* -->

<!-- ******************* Java Views and Dialogs ************************************* -->
Expand Down

0 comments on commit 7672a9f

Please sign in to comment.