Scott
Scott

Reputation: 115

How can I quickly replace separate variable declarations with in-line declarations in a function?

I have a task to refactor some code, and one of the thing I need to do is replace many instances of separate variable declaration with in-line declaration as part of a function. It's taking a long time to do manually, and I wonder if there is a faster way in IntelliJ

    public void getUrlOutputNotNull() {
        final Paginator objectUnderTest = new Paginator();
        final String actual = objectUnderTest.getUrl();
        Assert.assertEquals("", actual);
    }

is supposed to become

    public void getUrlOutputNotNull() {
        final Paginator objectUnderTest = new Paginator();
        Assert.assertEquals("", objectUnderTest.getUrl());
    }

I'm doing it all manually currently. Is there a way in IntelliJ to automate this process or at least do it faster?

Upvotes: 0

Views: 61

Answers (1)

Olga Klisho
Olga Klisho

Reputation: 1394

You may inline the variable. For this put the cursor within the actual:

Assert.assertEquals("", actu<cursor>al);

and press Refactor | Inline variable (or Alt + Cmd + N on Mac OS).

Upvotes: 2

Related Questions