IntelliJ IDEA 14.0.0 Web Help

Replace Method Code Duplicates

The Replace Method Code Duplicates allows you to find code repetitions similar to the selected method and replace them with calls to the method.

Example

Before After
public void method() { int a = 1; int b = 2; int c = a+b; int d = b+c; } ... private int add(int a, int b) { return a+b; }
public void method() { int a = 1; int b = 2; int c = add(a,b); int d = add(b,c); } ... private int add(int a, int b) { return a+b; }

To replace method code duplicates

  1. Position the cursor within the method, duplicates of which you want to search for.
  2. Do one of the following to open the Replace Method Code Duplicates dialog box:
    • On the Refactor menu, choose Replace Method Code Duplicates .
    • On the context menu, choose Refactor | Replace Method Code Duplicates .
  3. Press the Replace button to continue. For each code fragment found, IntelliJ IDEA will prompt you to confirm replacement.

See Also

Last modified: 12 November 2014
comments powered by Disqus