Eclipse content assist auto appends type for variable
Asked Answered
C

5

18

I just started to use Juno for a couple of days, the content assist mechanism seems different from what it behaves before.

For example, if I try to declare a variable

Boolean isVisible

The content assist of Juno will give you a drop-down list with the variable name

isVisibleBoolean

as hint.

And the very annoying thing is that no matter what I typed in(; or SPACE), the "isVisibleBoolean" will be selected.

Does anybody know how can I disable the auto-variable-type-appending thing?

Much appreciated.

I'm using Mac OS X 10.8.1 currently, haven't tested it yet in windows.

Chrotoem answered 15/9, 2012 at 1:53 Comment(2)
Not sure about Juno, in Luna, you can uncheck Window->Preference->Java->Editor->Content Assist->Insert single proposals automatically.Semilunar
Thanks for the answer, I have moved on from eclipse to intelliJ, :DChrotoem
V
8

Based on the discussion for Eclipse Bug 412992, check your Content Assist Auto Activation settings: Window->Preferences->Java->Editor->Content Assist

If, for example, characters a-z are listed as "Auto activation triggers for Java", you can remove them and the type name will not be auto-appended to a new variable name when you hit ' ' or ';'. It's up to you to determine the best configuration/tradeoffs for your style based on the available options.

Vortex answered 16/7, 2013 at 17:8 Comment(1)
This kinda sucks -- it's like the defaults suck, and they can't be configured to not suck -- but there's a couple options on making them suck less -- @Daniel's answer below suggests putting only "." and caps characters in there, which is a pretty good start -- or in Luna -- there's an option in the content assist menu "Insert Single Proposals Automatically" it looks like if you uncheck this, the problem goes away also.Semilunar
U
3

It seems that it is not possible. See answers to Eclipse Bug 378588: https://bugs.eclipse.org/bugs/show_bug.cgi?id=378588

Upholster answered 9/7, 2013 at 9:42 Comment(0)
B
3

This is still a problem in Eclipse 2018-12 and it only seems to occur if you changed the Auto activation triggers for Java setting to e.g. ._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ, which'll make the Content Assist (almost) always pop up, even without pressing Ctrl+Space (Windows).

There's a new setting that was added in Eclipse 2018-12 and makes it a bit less annoying (mentioned in the comments below the bug report):

In Window - Preferences - Java - Editor - Content Assist tick the Disable insertion triggers except 'Enter' box.

With this setting enabled, Content Assist is still going to trigger (depending on the other settings) but you have to press Enter to accept a suggestion.

Bane answered 23/6, 2020 at 13:48 Comment(0)
P
2

Not a perfect solution:

Window->Preference->Java->Editor->Content Assist->Auto activation Triggers for Java: .ABCDEFGHIJKLMNOPQRSTUVWXYZ

In this way, only classes and types will be popped up for proposals.

Just a suggestion, the choice is up to you.

Phyla answered 10/11, 2013 at 8:28 Comment(1)
Not a bad idea (assuming we're using TitleCase for things -- I am for the most part, which is against the standard, but this is pretty helpful in that case) -- A second option is to go into that same menu and uncheck "Insert Single Proposals Automatically" -- it looks like this makes the problem goes away also.Semilunar
N
-2

What you see there is name completion for object types. And this may often make sense, e.g. pressing Ctrl-Space after List book will complete that to List bookList. For primitive types this is not done, so int count will not get any completion when pressing Ctrl-Space. This would be a (not really good) solution to your problem by declaring the variable as primitve boolean.

What I really recommend as solution is to change your style of writing variable declarations. For your example, write isVisible = false instead, have the editor complain about the missing type declaration, hit Ctrl-1 (from wherever your cursor might be placed), Enter.

Nadanadab answered 16/9, 2012 at 6:0 Comment(1)
Hi Bananeweizen, Thanks for your help there, I was making a example there, you probably have been using Hibernate for a long time, in this case you want to do something like @Id @GeneratedValue(strategy = XXX)Long id. Then eclipse will give you Long idLong, which makes perfect sense for the readability of the code, but really is not we want, is it? And for the recommendation, I think that will definitely work, but it is slow and unnecessary to do that for every field.Chrotoem

© 2022 - 2024 — McMap. All rights reserved.