When you get unintended results in Eclipse's code completion that might be the side effect of substring code completion.
Tags: eclipse, java, substring, completion
Published: 2019-07-28 12:08:09

---
title: When you get unintended results in Eclipse's code completion that might be the side effect of substring code completion.
published: true
description: Setting to make Eclipse code completion comfortable
tags: Eclipse,Java,substring,completion
---
# Overview
- When you want to complete the method name of a class,sometimes eclipse will complete an unintended method name.
- I want to explain the measures in such a case.
- It's probably a side effect of the new feature "Substring code completion" added in [Eclipse NEON](https://www.eclipse.org/eclipse/news/4.6/jdt.php)


## Environment

- Eclipse IDE 2019‑06

# "Unintended completion" is as follows.Take a look first.

After entering "Arrays", enter a dot(.) To start code completion.
Next, if you enter "tostring" and press the enter key, "deepToString" is selected as a problem.

![substring_miss_before_.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/170905/4a73e605-6104-2073-4648-e0e201c9ec63.gif)


## "Substring code completion" is a useful feature,you know.

Even if only "string" is typed, those that include "string" as part of the method name will be suggested as candidates.

![substring_ok.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/170905/731b8d1d-2513-0898-18dd-94ea309b8b51.gif)

# Solution-1: Turn off substring completion

Select **Window>Preference>Java>Editor>Content Assist** ,then you can find **Show substring matches** setting ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/170905/ec003ceb-52de-271a-9cbd-83873e730029.png).And then turn it off ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/170905/9a19cb9f-b238-e47a-79b4-e62be45a958b.png)


![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/170905/2902f2b0-17a6-ee7b-c77d-8216768ec1d8.png)

## Try to use "substring completion off"

It feels pretty good.
Unintentional "deepToString" is no longer complemented.

![off_substring.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/170905/67d8801b-b59e-72d0-54e7-e1d0905f5e4d.gif)

## However, if "substring completion" is off, substring completion can not be completed naturally.

I tried typing "string" after "Arrays." and there were no more candidates.

![off_substring_miss.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/170905/b52be34e-0ade-edab-bc01-224daa9d054f.gif)

# Solution-2

Reopen settings window as before **Window>Preference>Java>Editor>Content Assist**  and turn "substring completion" on ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/170905/df96a4ec-3fbb-3a5d-4e11-47f5a1e2722a.png)

Next, click the [+] "plus" mark on "Content Assist", then expand the settings and select "Advanced".

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/170905/f1919d60-d644-9c43-b327-b0974630dedd.png)

Check **Java Proposals** like as follows.

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/170905/2fc4eb7a-8d0c-aef9-e783-d835f4ada068.png)


## Try code completion

Look at this.

 It seems that it moves by the intended action

![proposals_fullmatch.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/170905/85bd1c14-50d1-67d3-d92a-6c77bff26eae.gif)

## Try Code Completion with Substring Match

The substring completion is also working properly.

![proposals_partmatch.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/170905/85f588ca-7683-2eb0-6a3c-1921d4dc1157.gif)

Solution-2 seems to work more as intended.

# Impression
As for code completion, I think, "Intellij IDEA" (or Android Studio) is much more advanced and corresponds to "substring code completion" and seems to be pre-tuned to have no such side effects.

(I didn't notice it until I encountered it in Eclipse, but the slight differences improved by the tuning of the feeling of use affect productivity and quality, etc.)