GoLand 2021.3 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.

Inline editing in GoLand

    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