How can I improve eclipse code completion?
-
12-10-2019 - |
Question
Eclipse does not find the correct variable for code completion as shown below.
int i = 0;
f(xyz); // f takes an int but eclipse won't fill it with i.
Solution
Under "Window" > "Preferences" > "Java" > "Editor" > "Content Assist", make sure "Fill method arguments and show guess arguments" is set and "Insert best guessed arguments" is selected.
Edit:
I tried this in my Eclipse (Version: Helios Service Release 1 - Build id: 20100917-0705):
public class BestGuessedParameter {
static int xyz = 1;
static void f(final int xyz) {
}
public static void main(final String[] args) {
final int i = 0;
f/*cursor here*/
}
}
Right after I typed the f
, I hit space and selected f(xyz)
, Eclipse did supply f(i)
with i
highlighted and in a pop-down menu of i
(highlighted), xyz
, and 0
. i
was the default.
I couldn't find any info on how Eclipse selects the "best guessed parameters" (I have no idea where to look in the Eclipse source). I would guess that Eclipse "guesses" based on type, name, and visibility, and that Eclipse thinks there's a better match than your local variable. Perhaps if the local variable were closer in type and name, it would be a better match?