Auto complete a statement in eclipse
Is there a way to auto complete a statement in eclipse? If I type
if (condition) 
it should, after pressing so开发者_开发百科me 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
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)
if (${condition:var(boolean)}) {
 ${cursor}
}
You can then access the template by typing its name (most likely just 'if') and pressing Ctrl-space
Ctrl + Space is default for code assist.
For more customization you need templates.
Try 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:
 - write your if condition along with the first bracket 
if(condition){- hit enter, then eclipse will do its job.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论