IDEA really shines when you can use Locate Duplicates to find repeated code fragments and then do Extract Method to extract the fragement into a new method, and IDEA replaces all the fragments with the method call.
I hadn't used the Replace Method Code Duplicates before, but recently started to try it out, but I am having some problems.
For example, I did Analyze->Locate Duplicates on a file. The top duplicate found had 3 duplicates of the following code:
I highlight one of the code fragments, and invoke ExtractMethod.
(BTW Would be great if you can invoke Extract Method directly from Find - Duplicates Tool Window.
http://www.jetbrains.net/jira/browse/IDEABKL-2623. Extract Method seems much more common an
operation than the Send to Left, Send to Right buttons on the Find - Duplicates results window.)
Enter new method name "buildMonitorGroupMap" and Hit OK.
Process Duplicates Dialog pops up.
"IDEA has detected 2 code fragments in this file that can be replaced with a call to extracted method. Would you like to review and replace them?"
If I say No, and finish the Extract Method, the code has changed to:
and I have a new method:
Now if I put my cursor on the new method and invoke
Replace Method Code Duplicates, IDEA doesn't find any:
"IDEA has not found any code that can be replaced with method call?"
Shouldn't Replace Method Code Duplicates find the same thing that Extract Method found?
Seems like a bug.