Eclipse : transform static method invocation to a static import
Asked Answered
R

1

46

Is there a way to transform automatically this static method invocation (Arrays.asList):

import java.util.Arrays;
import java.util.List;

public class StaticImport {
    public static void main(String[] args) {
        List<String> list = Arrays.asList("hello", "world");
        System.out.println(list);
    }
}

to this invocation using a static import:

import static java.util.Arrays.asList;

import java.util.List;

public class StaticImport {
    public static void main(String[] args) {
        List<String> list = asList("hello", "world");
        System.out.println(list);
    }
}

I know that i can configure the code completion using this Window » Preferences » Java » Editor » Content Assist » Favoritesas described in this answer.

My question is about transforming an existing static method invocation. Ideally, i would like do not have to configure a "favorite import".

Rancid answered 22/3, 2013 at 9:55 Comment(1)
see this : #289361Sessile
C
99

Put the cursor on the method name (asList) and press Ctrl-Shift-M.

This is the default keyboard shortcut for the 'Add Import' command. You can also find the command on the 'Source' menu.

Causation answered 22/3, 2013 at 11:43 Comment(2)
Thanks! but if has many Arrays.asList, only remove Arrays of this current cursor line.Byway
@zhuguowei, bummer ! :(Toluca

© 2022 - 2024 — McMap. All rights reserved.