简体   繁体   English

IntelliJ / AndroidStudio中的自动完成构造函数调用

[英]Autocomplete constructor calls in IntelliJ/ AndroidStudio

I'd like to change the code completion for constructors in Android Studio. 我想更改Android Studio中构造函数的代码完成。 I'm looking for a Eclipse-like behaviour, For example: 我正在寻找类似Eclipse的行为,例如:

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. 当在代码中键入new Foo(并按Ctrl + P时),我得到一个关于完成的浮动提示,但我希望IDE自动为所有参数输入占位符名称,然后替换所需的参数。

Also tried to press Ctrl + Swift + Space but it requires to have the field previously declared in the class 还尝试按Ctrl + Swift + 空格键,但它需要具有先前在类中声明的字段

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 然后按Alt + Enter ,然后为每个参数选择选项“ Create field for mockName

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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