Inline
Shortcut: CtrlAlt0N
The Inline refactoring lets you reverse the Extract refactoring for a method, constructor, parameter, superclass, anonymous class, and closure (for Swift).
You can inline the pattern variable since the Java 14 version. In this case, all the occurrences will be replaced with old-style cast expression.
Place the caret at the code fragment you want to inline.
Press CtrlAlt0N. Alternatively, right-click the code fragment and go to the Refactor menu. Select the inline refactoring that you need.
In the Inline dialog, specify the inlining options.
Preview and apply changes.
Inline Variable refactoring replaces redundant variable usage with its initializer.
note
The variable must be initialized at declaration. If the initial value is modified somewhere in the code, only the occurrences before modification will be inlined.
Before | After |
---|---|
|
|
|
|
Inline Method results in placing method's body into the body of its caller(s).
Before | After |
---|---|
|
|
|
|
Inline Constructor allows compressing a chain of constructors, if one of them is a special case of another.
Before | After |
---|---|
|
|
The Inline Superclass refactoring results in pushing superclass' methods into the class where they are used, and removing the superclass.
Before | After |
---|---|
|
|
Inline to Anonymous Class refactoring allows replacing redundant class with its contents. Starting with Java 8, the inlined anonymous classes can be converted to lambdas automatically.
Before | After |
---|---|
|
|
The Inline Parameter refactoring allows you to replace usages of the parameter with the value from the arguments of the method call.
Before | After |
---|---|
|
|
Thanks for your feedback!