Refactoring - moving variable declaration

Anyone know how to do the refactoring as follows:

<!--
Before refactoring
-->
for (int i = 0; i < sorts.length; i++) {
SortOrder sort = sorts+;

<!--
After refactoring
-->
SortOrder sort = null;
for (int i = 0; i < sorts.length; i++) {
sort = sorts+;

Thanks in advance

Martin

2 comments
Comment actions Permalink

Martin wrote:

Anyone know how to do the refactoring as follows:

<!--
Before refactoring
-->
for (int i = 0; i < sorts.length; i++) {
SortOrder sort = sorts+;

<!--
After refactoring
-->
SortOrder sort = null;
for (int i = 0; i < sorts.length; i++) {
sort = sorts+;


Try using the "Split into declaration and assignment" intention action
by positioning the cursor on the "SortOrder sort = sorts+;" line and
pressing Alt-Enter. After that you should be able to cut & paste the
declaration before the loop and add the null initializer.

Ciao,
Gordon

--
Gordon Tyler (Software Developer)
Quest Software <http://java.quest.com/>
260 King Street East, Toronto, Ontario M5A 4L5, Canada
Voice: (416) 933-5046 | Fax: (416) 933-5001

0
Comment actions Permalink

Gordon Tyler wrote:

Martin wrote:

>> Anyone know how to do the refactoring as follows:
>>
>> <!--
>> Before refactoring
>> -->
>> for (int i = 0; i < sorts.length; i++) {
>> SortOrder sort = sorts+;
>>
>> <!--
>> After refactoring
>> -->
>> SortOrder sort = null;
>> for (int i = 0; i < sorts.length; i++) {
>> sort = sorts+;


Try using the "Split into declaration and assignment" intention action
by positioning the cursor on the "SortOrder sort = sorts+;" line and
pressing Alt-Enter. After that you should be able to cut & paste the
declaration before the loop and add the null initializer.

Ciao,
Gordon


I do this quite frequently as well.

It would be really nice if there was an intention action to do this
without the additional cut & paste and add null initializer actions.

btw, if you have the LineMover plugin, it is a better option than the
cut & paste step, although still suboptimal for this case.

Tim

0

Please sign in to leave a comment.