Eclipse content assist auto appends type for variable

前端 未结 5 1844
Happy的楠姐
Happy的楠姐 2021-01-04 03:58

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 variabl

相关标签:
5条回答
  • 2021-01-04 04:13

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

    0 讨论(0)
  • 2021-01-04 04:13

    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.

    0 讨论(0)
  • 2021-01-04 04:20

    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.

    0 讨论(0)
  • 2021-01-04 04:23

    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.

    0 讨论(0)
  • 2021-01-04 04:27

    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.

    0 讨论(0)
提交回复
热议问题