GoLand 2024.1 Help

Inline

Use the Inline refactoring to reverse the extract refactoring for a method or a variable.

  1. Place the caret at the code fragment you want to inline.

  2. Press Ctrl+Alt+N. Alternatively, right-click the code fragment and go to the Refactor menu. Select the inline refactoring that you need.

  3. In the dialog, specify the inlining options.

  4. (Optional) Select Preview to preview changes.

  5. 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

    package main import "fmt" func main() { fmt.Println(<caret>hello()) print(hello()) } func hello() string { return "Hello World!" }

    Inline all invocations and remove declaration

    package main import "fmt" func main() { fmt.Println(<caret>"Hello World!") print("Hello World!") }

    Inline all invocations and keep declaration

    package main import "fmt" func main() { fmt.Println(<caret>"Hello World!") print("Hello World!") } func hello() string { return "Hello World!" }

    Inline this invocation only and keep declaration

    package main import "fmt" func main() { fmt.Println(<caret>"Hello World!") print(hello()) } func hello() string { return "Hello World!" }
    Last modified: 26 May 2024