IntelliJ IDEA 11.1 Web Help

8.0+

IntelliJ IDEA provides the following inline refactorings:

Examples

Inline variable

Before After
              public void method() {
    int number = anotherClass.intValue();
    int b = a + number;
}
    
              public void method() {
    int b = a + anotherClass.intValue();
}
    
              public void method() {
    AnotherClass.InnerClass aClass = anotherClass.innerClass;
    int a = aClass.i;
}
    
              public void method() {
    int a = anotherClass.innerClass.i;
}
    

Inline method

Before After
              public void method() {
    int c=add(a,b);
    int d=add(a,c);
}

private int add(int a, int b) {
    return a+b;
}
    
              public void method() {
    int c= a + b;
    int d= a + c;
}
    
              public ArrayList method() {
    String[] strings = {"a","b","c"};
    ArrayList list=add(strings);
    return list;
}

private ArrayList add(String[] strings) {
    ArrayList list = new ArrayList();
    for (int i=0; i< strings.length; i++)
        {list.add(strings[i]);}
    return list;
}
    
              public ArrayList method() {
    String[] strings = {"a","ab","abc"};
    ArrayList list1 = new ArrayList();
    for (int i=0; i< strings.length; i++)
        {list.add(strings[i]);}
    ArrayList list = list1;
    return list;
}
    

Inline constructor

Before After
              public class Class {
    public intvarInt;
    public Class() {
        this(0);
    }

    public Class(int i) {
        varInt=i;
    }

    public void method() {
        Class aClass=new Class();
        ...
    }
}
    
              public class Class {
    public intvarInt;
    public Class(int i) {
        varInt=i;
    }
    public void method() {
        Class aClass=new Class(0);
        ...
    }
}
    
8.0+↓

Inline superclass

Before After
              public class Bar {
    ...
    int calculations1() { ... }
    int calculations2() { ... }
}

class Foo extends Bar {
    int someMethod() {
        ...
        if (something > calculations1()) {
            ...
            return calculations2();
        }
        ...
    }
}
    
              class Foo {
    ...
    int someMethod() {
        ...
        if (something > calculations1()) {
            ...
            return calculations2();
        }
        ...
    }
    int calculations1() {...}
    int calculations2() {...}
}
    
To perform the inline refactoring
  1. Place the caret in the editor at the desired symbol to be inlined.
  2. Do one of the following:
    • On the main menu or on the context menu of the selection, choose Refactor | Inline .
    • Press Ctrl+Alt+NCommand Alt N.
  3. In the Inline dialog, that corresponds to the selected symbol, specify the inlining options.
  4. Preview and apply changes.

See Also

Procedures:

Reference:

Web Resources: