简体   繁体   中英

Autocomplete constructor calls in IntelliJ/ AndroidStudio

I'd like to change the code completion for constructors in Android Studio. I'm looking for a Eclipse-like behaviour, For example:

Given the class

class Foo{
   public Foo(Object name,Object description, Object address, Object zipCode){ 
       ....
   }
}

When, in the code I type new Foo( and pres Ctrl + P I get a floating hint for the completion but I'd like the IDE to automatically enter the placeholder name for all the params and then I replace the params I need.

Also tried to press Ctrl + Swift + Space but it requires to have the field previously declared in the class

Basically I want to speed up to write code like that

class MockitoTest {

    Foo foo;

    @Mock
    Object mockName;
    @Mock
    Object mockDescription;
    @Mock
    Object mockAddress;
    @Mock
    Object mockZipCode;

    @Before
    public void setUp() throws Exception {
       MockitoAnnotations.initMocks(this);
       foo= new Foo(mockName,mockDescription,mockAddress,mockZipCode);
    }    
}

Where the first step is to declare

    @Before
    public void setUp() throws Exception {
       MockitoAnnotations.initMocks(this);
       foo= new Foo(mockName,mockDescription,mockAddress,mockZipCode);
    }  

And then press Alt + Enter and select the option Create field for mockName for each param

从1.1版开始,Android Studio不支持此行为。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM