Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse: Fulltext autocompletion for Java?

Tags:

java

eclipse

can I has fulltext autocompletion for Java @ Eclipse? Let's demonstrate:

Final piece of code:

getVariants().add(new Variant(MediaType.TEXT_XML));

How do I code now:

getv[ctrl+space].a[Enter]new V[ctrl+space, down arrow, Enter]M[Ctrl+Space, Enter].text_x

Basically, Eclipse completes word "TEXT_XML" when I provide letters "TEXT_X".

How would I like to code:

getv[ctrl+space].a[Enter]new V[ctrl+space, down arrow, Enter]M[Ctrl+Space, Enter].xml

and Eclipse should realise I meant "TEXT_XML" (fulltext autocompletion).

like image 232
Xorty Avatar asked Apr 22 '11 13:04

Xorty


People also ask

How do I get auto suggestions in eclipse?

Step 1: Open your Eclipse or Spring Tool Suite, then go to the Window > Preferences as shown in the below image. Step 2: In the next screen go to the Java > Editor > Content Assist > Auto activation triggers for Java as shown in the below image.

How do I enable Ctrl space in eclipse?

Eclipse --> Windows --> Preferences --> Java --> Editor --> Content Assist --> Advanced --> select all Java & Java Type Proposals. Save this answer. Show activity on this post. To enable Ctrl+Space.

Why methods are not showing in eclipse?

Open Eclipse Preferences. Go to Preferences > Java > Editor > Content Assist > Advanced. Make sure that Other Java Proposals is selected in the list of proposal kinds.


2 Answers

As far as I'm aware, there is no way of enabling a full-text code completion in the Eclipse preferences view. This has been bugging me for a while, too. I did quite a bit of digging and I'm pretty certain there is no easy way of achieving this.

However, there are two ways of implementing the desired, but I assume both of which are way to much work for fixing this little nuisance.

  1. There is an Eclipse plug-in extension point for the JDT Java Completion Proposal Computer - reference page A sample project which implements this extension point can be found in this repository. This is fairly convenient, but still a lot of boilerplate and tedious coding.

  2. You can change the findKeywords method in the internal org.eclipse.jdt.internal.codeassist.CompletionEngine class and compile your own JDT fork. But this is discouraged for so many reasons. First of all, this class is a 12000 line monster and hard to just jump in. And of course, if you'd only hack a kludge in, there is little chance of this becoming an official contribution, so you'd need to worry about every eclipse release.

Additionally, there might be a very chillaxed way in the future. Although this might exceed your requirements a bit.

Have a look at the Code Recommenders project. This blog has an outline of the project objectives It doesn't mention full-text auto-completion specifically, but I'd assume its matching algorithms go even beyond that.

Edit: In the proper SO-spirit, I'll keep this answer up to date:

Apparently the feature is now implemented in the Code Recommenders plug-in. See this blog post and this forum thread. I'm quite surprised it only took 10 locs. To me the extension point appeared more complex.

like image 82
Jules Avatar answered Oct 04 '22 07:10

Jules


If your MediaType class does not contain a large number of accessible fields/methods you could simply use

getv[ctrl+space].a[Enter]new V[ctrl+space, down arrow, Enter]M[Ctrl+Space, Enter].[Ctrl+Space, down arrow, Enter]

you may need to press the down arrow more than once, though to select the desired field.

like image 41
lothar Avatar answered Oct 04 '22 07:10

lothar