Inline
Use the Inline refactoring to reverse the extract refactoring for a method or a variable.
Place the caret at the code fragment you want to inline.
Press Ctrl+Alt+N. Alternatively, right-click the code fragment and go to the
menu. Select the inline refactoring that you need.In the dialog, specify the inlining options.
(Optional) Select Preview to preview changes.
Preview and apply changes.
Examples
Inline Variable
Inline Variable refactoring replaces redundant variable usage with its initializer.
Before | After |
---|---|
func main() {
subj := subject{name: "world"}
format := "hello %s"
fmt.Printf(format, subj.name)
}
| func main() {
subj := subject{name: "world"}
fmt.Printf("hello %s", subj.name)
}
|
Inline Function/Method
Inline Function/Method results in placing method's body into the body of its caller(s).
Before | After |
---|---|
func main() {
print(hello())
}
func hello() string {
return "Hello World!"
}
| Inline all invocations and remove declaration func main() {
print("Hello World!")
} Inline all invocations and keep declaration func main() {
print("Hello World!")
}
func hello() string {
return "Hello World!"
} Inline this invocation only and keep declaration func main() {
print("Hello World!")
}
func hello() string {
return "Hello World!"
} |
Last modified: 30 November 2021