Java – Eclipse autocomplete irritation

autocompleteeclipsejava

I seem to frequently trip over a particular "feature" of Eclipse's autocomplete behavior. Say that I'm programming in Java and start to code a method call like this:

for (int i = 0; i < n; ++i) {
    thing.

When I type the ., Eclipse pops up a list of candidate methods for thing. Suppose I select method(int index). Eclipse inserts my choice:

for (int i = 0; i < n; ++i) {
    thing.method(index)

It also highlights index and pops up a list of variables I might want to use. The first item on the list is index and the second one is i. Not wanting to move my hands from the keyboard, I type i.

The problem is, I then out of habit usually press enter to complete the autocompletion sequence. Unfortunately, this causes Eclipse to select the first item on the suggestion list that starts with i, which is index. Argh! To avoid this, I need to either:

  1. remember to press tab instead of enter after typing i;
  2. select i from the suggestion list instead of typing it;
  3. press esc (twice!) to get rid of the suggestion list before pressing enter.

With all of these, I'm forced to interrupt my thinking about my code in order to think about how to use Eclipse.

I realize that this is a long-winded rant for a fairly niggling problem, but I do actually have a question. Are there any settings in Eclipse (short of turning off autocompletion, which is otherwise very helpful) to either (1) tell it to rank legal options above illegal ones in the suggestion list or (2) otherwise tell Eclipse that when I type an i, that's what I want?

Best Answer

In the 'Java -> Editor -> Content Assist' preference page set 'Fill method arguments and show guessed arguments' to 'Insert best guessed arguments'

Preference page