Refactoring. Find&Replace method code duplicates.


I'm wondering what the new feature ' Refactoring. Find&Replace method code
duplicates. ' does exactly?

It sounds great but so far all I get is "idea has not found any code that
can be replaced with method call".

-- Glen


6 comments
Comment actions Permalink

It will pick any duplication of the portion of code elsewhere in the same file and replace it with a call to the extracted method.

However I found it very restrictive. It seems to only pick up exact duplicate (don't get me wrong, it is already something. It just needs to be improved).
Simple this like that


It won't pick the other one if I try to extract both lines in one of the method. Intuitively I thought it would do this

Unfortunately not.
The restrictive to only search the current page is also sub-optimal. Sometimes you know that something like this must exist, even already factored. It would be nice to have the option to run a configurable duplication analysis with the same tuning option as the global analysis.

Jacques

0
Comment actions Permalink

It will pick any duplication of the portion of code elsewhere in the same file and replace it with a call to the extracted method.


Does it really work only in the same file??? This would be a very hard
limitation!

Tom

0
Comment actions Permalink

Thomas Singer (MoTJ) wrote:

>> It will pick any duplication of the portion of code elsewhere in the same
>> file and replace it with a call to the extracted method.


Does it really work only in the same file??? This would be a very hard
limitation!


Yes, that is right - unfortunately.

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

0
Comment actions Permalink

Jacques Morel wrote:

It will pick any duplication of the portion of code elsewhere in the same
file and replace it with a call to the extracted method.

However I found it very restrictive. It seems to only pick up exact
duplicate (don't get me wrong, it is already something. It just needs to
be improved). Simple this like that

 method1() {
>    call(x,y,z,"1");
>    x.add(y);
> }
> 
> 
> method1() {
>    call(x,y,t,"3");
>    x.add(y);
> }
> ]]>


It won't pick the other one if I try to extract both lines in one of the
method. Intuitively I thought it would do this

 method1() {
>    extractedMethod(z,"1");
> }
> 
> 
> method1() {
>    extractedMethod(t,"3");
> }
> ]]>

Unfortunately not.


The point of this refactoring is that it does not extract any method.
To do what you want to do, you should introduce a parameter for "1" in
method1().

Friendly,
Dmitry

The restrictive to only search the current page is also sub-optimal.
Sometimes you know that something like this must exist, even already
factored. It would be nice to have the option to run a configurable
duplication analysis with the same tuning option as the global analysis.


That will be great indeed. We will surely have this in 5.0.

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

0
Comment actions Permalink

Yes, that is right - unfortunately.


Why only for the file? Would it require too much effort or would it be
too slow?

Tom

0
Comment actions Permalink

Thomas Singer (MoTJ) wrote:

>> Yes, that is right - unfortunately.


Why only for the file? Would it require too much effort or would it be
too slow?


It will requre too much effort to make it not too slow :)

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

0

Please sign in to leave a comment.