How to fix IntelliJ IDEA method parameter auto-completion?
Asked Answered
A

5

14

I am using IntelliJ IDEA 15, and I noticed that (by default) Eclipse offers a much more convenient auto-completion, when it comes to writing method calls, which require multiple parameters.

Eclipse automatically fills in default parameters and allows you to quickly navigate through them by pressing Tab:

enter image description here

However, IntelliJ IDEA does not handle it as conveniently and makes you write them manually:

enter image description here

Is there a way to make IntelliJ IDEA, handle method call auto-completion in a similar way to Eclipse's, and pre-write all the parameters for you, having you just press Tab (or another key) to navigate through them? If it is not possible in original IntelliJ, is there an add-on/plugin/external tool that will improve the intelligent code completion in such cases?


Note: I am not being lazy, it just gets quite annoying, having to manually complete each parameter and put a comma after each one, when code completion should do it for you.

Acosmism answered 16/2, 2016 at 2:45 Comment(0)
G
9

IntelliJ doesn't do it and AFAIK there isn't a plugin for it.
There is no solution for you (unless you built a plugin yourself, but then you'd just have another job to maintain that plugin)

The alternative is to break the habit/need for it and use IntelliJ's Code Completion shortcuts:

  • Ctrl+P to view possible parameters for function.
  • Ctrl+Shift+Space to list the possible variables that could be entered as a parameter in the respective parameter position (based on type).
    This also enters a comma if another parameter is required for the function.

Hardcoding numbers/strings as parameters to a custom function wouldn't be advisable as that negates the point of the parameters. It's better practice and more common to pass in a pre-defined variable; At which point Ctrl+Shift+Space is the easiest way for Code Completion.
This would also prevent you from closing quotations and adding commas.

Also note: IntelliSense is Microsoft's Intelligent Code Completion implementation which neither IntelliJ nor Eclipse uses.


As frant.hartm states in their answer:

Unfortunately the view of Intellij developers is that this feature would be too error prone. See this issue on youtrack.

They even state that people are welcome to make a plugin that does this.

Getty answered 14/3, 2016 at 16:17 Comment(1)
Finally someone developed a plugin - github.com/kontext-e/AutoFillingCallArguments.Leatherman
O
3

The closest thing to this AFAIK is "method parameter completion", which allows you to auto complete parameters of current method as parameters of the inner method call at once (works for methods and constructors when calling super()).

method parameter completion

Unfortunately the view of Intellij developers is that this feature would be too error prone. See this issue on youtrack.

Otero answered 15/3, 2016 at 10:32 Comment(0)
C
2

IDEA doesn't fill the arguments automatically. You can use Ctrl+Shift+Space for auto-completion (completion is based on type, not name) or Ctrl+Alt+Space for suggestion. Or Ctrl+P to see what arguments are accepted.

Chopper answered 16/2, 2016 at 2:51 Comment(2)
I am aware of that, but it still requires to close quotes after strings, and put the commas between parameters manually. Is there a way to do it automatically, like Eclipse does it?Acosmism
Unfortunately this is not yet available in Intellij as Eclipse, but in Intellij auto-completion is done one-by-one with comma insert, those who immigrate from Eclipse to Intellij may have these problems. It needs time got habit with new IDE.Chopper
C
2

Try

Ctrl + Space

for

Basic Code Completion

And like previously was written

Ctrl + Shift + Space

for

Type Code Completion

or try the second variant TWICE. More about Auto-Completing Code is in here

Chryso answered 17/3, 2016 at 15:30 Comment(0)
U
1

The Auto filling Java call arguments plugin should do the trick : https://plugins.jetbrains.com/plugin/8638-auto-filling-java-call-arguments/reviews

I recommend to install manually the forked 1.2 version which fixes a bug with overloaded methods : https://github.com/kontext-e/AutoFillingCallArguments/issues/1#issuecomment-1513391992

Unmitigated answered 18/4, 2023 at 15:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.