简体   繁体   English

自动在Eclipse中完成语句

[英]Auto complete a statement in eclipse

Is there a way to auto complete a statement in eclipse? 有没有一种方法可以自动完成Eclipse中的语句? If I type 如果我输入

if (condition) 

it should, after pressing some key, become 按下某个键后,它应该变成

if (condition) {
    // putting cursor here
}

You can just continue to type the { and enter, and the closing bracket will be completed automatically without any special command: 您可以继续输入{并输入,结束括号将自动完成,而无需任何特殊命令:

if (  condition) { /* cursor here , enter */


if (  condition) { 
  /* cursor here */
}

There is also autocompletion (Crtl-Space), which can do the following 还有自动补全(Crtl-Space),它可以执行以下操作

if /* cursor here , Ctrl-Space */

becomes 变成

if ( /* cursor here */ condition) {

}

or 要么

if ( /* cursor here */ condition) {

} else {

}

This kind of thing cannot be autocompleted the conventional way, since you're not adding to a class or variable name. 由于您没有添加类或变量名,因此无法以常规方式自动完成此类操作。 However, this should be possible using eclipse templates (Window->Preferences->Java->Editor->Templates) 但是,使用eclipse模板应该可以做到这一点(Window-> Preferences-> Java-> Editor-> Templates)

if (${condition:var(boolean)}) {
 ${cursor}
}

You can then access the template by typing its name (most likely just 'if') and pressing Ctrl-space 然后,您可以通过输入模板名称(很可能只是'if')并按Ctrl-空格键来访问模板

Ctrl + Space is default for code assist. 默认情况下, Ctrl +空格是代码辅助功能。
For more customization you need templates. 要进行更多自定义,您需要模板。

尝试Ctrl-Space

Ctrl + Space is used to auto complete words, variable names, classes etc, if you want eclipse to complete your if statement, do the following: Ctrl +空格键用于自动完成单词,变量名,类等,如果要让eclipse完成if语句,请执行以下操作:
- write your if condition along with the first bracket -在第一个括号内写下您的if条件

if(condition){

- hit enter, then eclipse will do its job. -按Enter键,然后eclipse即可完成工作。

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

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