Arturas M
Arturas M

Reputation: 4369

Eclipse not giving me variable name suggestions

well I've seen in Tips & Tricks of Eclipse that it's possible to get a variable name generated by eclipse by clicking Ctrl + Space. However I'm getting empty suggestions. Fors instance I'm typing this and click ctrl + space:

private Color

And I am supposed to get some name suggestions on it? All I'm getting is an empty list of suggestions. So what's turned off? Any idea?

Thanks in advance.

This is what I want to achieve: enter image description here

Upvotes: 16

Views: 28344

Answers (9)

Elio
Elio

Reputation: 468

I tried them one after the other and found out that the correct one is:

Windows -> Preferences -> Java -> Editor ->Content Assist -> Advanced: check Word Proposals

Upvotes: 2

Michael Fulton
Michael Fulton

Reputation: 4940

This is the default behavior after entering a Java type and a space, and then pressing CTRL+Space to activate auto-complete. For example, if you enter:

private Color 

then activate auto-complete it will suggest some variable names for you.

An easier way than having to press CTRL+Space all the time is to change the characters which automatically activate auto-complete. I find it very useful to have all characters which could possible be variable names to activate auto-complete. Try having ._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ as Auto activation triggers for Java found in Preferences -> Java -> Editor -> Content Assist:

Screen shot of the Content Assist settings

This way you can achieve how Visual Studio handles auto-complete.

Upvotes: 16

Rana Ranvijay Singh
Rana Ranvijay Singh

Reputation: 6155

Goto Window -> preferences -> java -> Editor -> content Assist ->Advances -> Select all the check boxes. DONE :)

Upvotes: 9

sushanth
sushanth

Reputation: 15

it just suggesting you can also declare the variable by that name..it just helping you because it was a tool write..nothing to worry about that..you can give your own name as you like kk..

import Color Class to your class: import java.awt.Color;

Upvotes: 0

Arturas M
Arturas M

Reputation: 4369

Thanks for everyones time and help. :)

I finally found it and the answer to this was that in my case the "java.awt.Color" wasn't imported and eclipse doesn't work on this one if it's not imported.

So it does suggest the name for you if your file had imported the class already, but if it hadn't it won't work.

I guess it makes the whole function pretty useless, but unfortunately that's how eclipse works. :/

Upvotes: 0

Liu guanghua
Liu guanghua

Reputation: 991

Ctrl + Space is maybe shortcuts of IM, so it is covered, I suggest you change the shortcuts of this function, for example: Alt + /,

if you don't know how to change shortcuts, please see the following steps:

  1. click Ctrl + Alt + L twice,
  2. find "Content Assist",
  3. change Binding value to you like shortcuts(cannot same the other shortcuts),
  4. click Apply button.

Upvotes: 0

Yogendra Singh
Yogendra Singh

Reputation: 34367

I believe you are trying to get variable name e.g. color after private Color where Color is you class i.e. private Color color. I see that working in my eclipse.

To verify your settings, go to below settings and verify as they look good to you.

    Windows -> Preferences -> Java -> Editor ->Content Assist

and

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

Upvotes: 16

Clark
Clark

Reputation: 1365

In Eclipse, it can get a variable name that you already made.

For example,

int awesomeVariable;
awesomeVariable = 50;

int superVariable;
superVariable = 

If I press Ctrl + Space after that =, it would generate some things that it could fill in. For example, it might suggest awesomeVariable. Basically, it doesn't generate a name for you, it just auto-completes with things you have already created.

Upvotes: 0

Karoly Horvath
Karoly Horvath

Reputation: 96258

private? It looks like you're creating something new.. eclipse cannot suggest in this case.

Autocomplete is for existing variables/functions/classes/etc.

Upvotes: 2

Related Questions