IntelliJ IDEA 14.1.0 Help

Inline

IntelliJ IDEA provides the following inline refactorings:

  • The Inline Variable refactoring replaces redundant variable usage with its initializer. See example. This refactoring is opposite to the Extract Variable refactoring.
  • Inline Method refactoring results in placing method's body into the body of its caller(s). You can opt to:
    • inline all occurrences of the method, and delete the method
    • inline only a single occurrence, and retain the method
    See example. This refactoring is opposite to the Extract Method refactoring.
  • Inline to Anonymous Class refactoring allows replacing redundant class with its contents.
  • Inline Constructor allows compressing a chain of constructors, if one of them is a special case of another. Seeexample.
  • Inline JSP/JSPX works like a regular Java inline refactoring.
  • Inline Superclass refactoring results in pushing superclass' methods into the class where they are used, and removing the superclass.

Examples

    Inline variable

    Before After
    public void method() { notherClass.intValue(); mber;
    public void method() { otherClass.intValue();
    public void method() { nnerClass aClass = anotherClass.innerClass; .i;
    public void method() { rClass.innerClass.i;

    Inline method

    Before After
    public void method() { ; ; t a, int b) {
    public void method() {
    public ArrayList method() { gs = {"a","b","c"}; =add(strings); add(String[] strings) { = new ArrayList(); i< strings.length; i++) strings[i]);}
    public ArrayList method() { gs = {"a","ab","abc"}; 1 = new ArrayList(); i< strings.length; i++) strings[i]);} = list1;

    Inline constructor

    Before After
    public class Class { varInt; { nt i) { thod() { ss=new Class();
    public class Class { varInt; nt i) { thod() { ss=new Class(0);

    Inline superclass

    Before After
    public class Bar { ns1() { ... } ns2() { ... } Bar { () { ing > calculations1()) { calculations2();
    class Foo { () { ing > calculations1()) { calculations2(); ns1() {...} ns2() {...}

    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+N.
    3. In the Inline dialog , that corresponds to the selected symbol, specify the inlining options.
    4. Preview and apply changes.

    See Also

    Last modified: 24 March 2015
    comments powered by Disqus