Eclipse autocomplete problems
Asked Answered
D

3

5

I use Map a lot in Java with eclipse. e.g.

  Map<String, String> map = new HashMap<>();

then when I am ready to add something with put:

 String key = null;
 String value = null;
 // somewhere before the put, key and value get populated with Strings
 map.put(key, value);

the problem is, every time I type "map.put", Eclipse autocomplete changes it to "map.compute()" so I have to edit and remove the "com" and the "e".

I looked at Window -> preferences -> Java -> Editor -> Content Assist but nothing was apparent. I could, I suppose, turn off all content assist, but that would be like "throwing the baby out with the bath water". There are a lot of useful things in the content assist.

My Eclipse:

Eclipse IDE for Enterprise Java Developers. Version: 2018-12 (4.10.0) Build id: 20181214-0600 OS: Windows 10, v.10.0, x86_64 / win32 Java version: 1.8.0_144

How can I fix eclipse so it will make the correct suggestions like it did in previous versions?

Devil answered 3/5, 2019 at 14:30 Comment(4)
I have Neon, but the setting might be similar. In the Content Assist settings, what is the value set to Sort proposals? For me, mine is set to by relevance (which I've never changed), but I reproduced your problem when I changed that setting to alphabetically.Targett
strange, but I looked and I guess my version thinks "compute" is more relevant than "put" for a map, even when set to relevant instead of alphabetical. As a matter of fact, either way it is the same, unless there is some other setting that I need to do?Devil
No other setting that I know. Maybe ensure that you've clicked 'apply', maybe restart Eclipse afterwards to see if that might change anything. Taking a look around, your issue seem to be a common complaint that they call "code recommenders". I might suggest to try the Photon version of Eclipse, as it seems like the version you mentioned is not yet named, at least based on this wikipedia info table.Targett
It started up with "relevant" already selected. I will check out your Photon suggestion. ThanksDevil
E
4

None of the proposed solutions worked for me. What fixed it was to disable "Show substring matches" (in Preferences -> Java -> Editor -> Content Assist).

It should be considered that this will break the functionality to just type a random part of the desired reference, e.g. typing "PreparedStatement" no longer leads to OraclePreparedStatement. A feature that I don't care about, but this is obviously a matter of personal preference.

In my opinion, the name of that option is a slight misnomer since the substring aspect only applies to leading and not to trailing content.

Update: In Eclipse 2020-06, there is no longer an option "Show substring matches". In its place there is "Show subword matches", but even when disabled, suggestions for typing map.put still include compute. At least when sorted by relevance rather than alphabetically, put is listed in the suggestions before compute.

Ecclesiastical answered 17/1, 2020 at 13:15 Comment(0)
B
3

Window->Preferences Java->Editor->Content Assist->Advanced

Unchecking "Java Proposals (Task-Focused)" and instead checking regular "Java Type Proposals" fixed the problem for me. I'm using Eclipse for Enterprise Java Developers 2019-03 on Windows 10.

Blitz answered 4/10, 2019 at 1:15 Comment(0)
A
1

This appears to be due to the unfortunate decision to remove 'Code Recommenders' going forward from 2018-12

"... Code Recommenders will unfortunately not make it into 2018-12."

https://bugs.eclipse.org/bugs/show_bug.cgi?id=542689

The solution currently is to add it manually from the marketplace.

Help -> Eclipse Marketplace -> Search for 'Code Recommenders'

There are no guarantees it will work for Java 11+.

Once installed, you'll have to:

  • restart Eclipse
  • close the 'Autocomplete installed' information page
  • attempt autocomplete once and select the top option that's something like 'Autocomplete enabled'

Finally attempt autocomplete again, this time it should work as expected

Update: It appears Code Recommenders has been archived due to lack of maintainers. When you try to download it, you will get a 404. Hopefully this is temporary.

Agra answered 20/6, 2019 at 21:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.