Problems with Extract method and final modifiers

Hi,

I have following code:

...
final String value = ...
// >
doSomething(value);
final int result = doSomethingElse();
// <
useInt(result);
...

When I now want to extract the code between // > and // <, IDEA
incorrectly uses the final modifiers:

... final String value = ...
int result = extractedMethod(value);
useInt(result);
...

private int extractedMethod(final String value) {
doSomething(value);
final int result = doSomethingElse();
return result;
}

IDEA makes the parameter final for no reason, but forgets the "int
result" to be made final. Last but not least, instead of creating the
temporary local variable "result" in extractedMethod(String) it could
return the value directly.
--
Lars Köhler

4 comments
Comment actions Permalink

Lars Köhler wrote:

Hi,

I have following code:

...
final String value = ...
// >
doSomething(value);
final int result = doSomethingElse();
// <
useInt(result);
...

When I now want to extract the code between // > and // <, IDEA
incorrectly uses the final modifiers:

... final String value = ...
int result = extractedMethod(value);
useInt(result);
...

private int extractedMethod(final String value) {
doSomething(value);
final int result = doSomethingElse();
return result;
}

IDEA makes the parameter final for no reason, but forgets the "int
result" to be made final. Last but not least, instead of creating the
temporary local variable "result" in extractedMethod(String) it could
return the value directly.


Lars,

please file an SCR.

Friendly,
Dmitry

--
Dmitry Lomov
Software Developer
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"

0
Comment actions Permalink

Lars,

please file an SCR.


Hmm, after some searching 11153 looks relatively similar.

--
Lars Köhler

0
Comment actions Permalink

Lars Köhler wrote:

>> Lars,
>>
>> please file an SCR.


Hmm, after some searching 11153 looks relatively similar.


Not really: the most important problem with your request is that Extract
Method fails to add final modifier to 'result'. Please submit the another
reuqest.

Thanks in advance,
Friendly,
Dmitry


--
Dmitry Lomov
Software Developer
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"

0
Comment actions Permalink

OK, done (27058).

--
Lars Köhler

0

Please sign in to leave a comment.