1

More often than not the "helpful" Intellij habit of adding an opening parenthesis when it detects a method is instead a minor hindrance/irritation: I have to stop typing, back up, remove the character then resume typing.

Is there any setting to fix this?

Note there is a related question about java for the same issue - and it seems for Java it is still not resolved:

How do I turn off auto-parenthesis generation in Intellij IDEA?

In particular this comment applies to me:

So, this option is turned off already for me. I just tested and found out that this ONLY happens in Actionscript files. In Java it only gives me the ( character and it lets my type over it

And the image there also applies to me:

enter image description here

3
  • What makes you think it's not resolved? Does that option help?
    – CrazyCoder
    Apr 3, 2017 at 8:20
  • @CrazyCoder I just updated the OP to show how the conditions mentioned in that other post apply to me: but they mentioned no way to disable the opening parenthesis. Apr 3, 2017 at 13:23
  • 1
    @javadba did you find a way to fix this?
    – Sergei G
    May 6, 2018 at 23:42

1 Answer 1

10

I've found something of a workaround that does prevent IntelliJ from adding parentheses, however it isn't a setting and involves the code itself so it may not actually fully relieve your annoyance.

If you write out an object, then you write a method call on the object, IntelliJ will create the parentheses and insert your cursor between them. Below is an example, | represents the cursor.

//Start with:
objectA method|

//Press `RETURN` and it becomes:
objectA method(|)

However, if IntelliJ detects that an argument is already present when you write the method call, then it should omit the parentheses.

//Start with:
objectA| objectB

//Write the method call:
objectA method| objectB

//Press `RETURN` and it becomes:
objectA method |objectB

The problem is that people generally write the argument after the method call. Although you could use a placeholder to trick IntelliJ into thinking there is an argument present, while you can still write normally. Note that you can either write the placeholder on the same line as the method call, or the line immediately below it (with only whitespace in between), in order for IntelliJ to detect it as an argument.

//Start with:
objectA|
"placeholder"

//Write the method call:
objectA method|
"placeholder"

//Press `RETURN` and it becomes
objectA method |
"placeholder"

//Continue to write the argument
objectA method objectB|
"placeholder"

The above behaviour only appears to occur when infix notation would be valid, such as where method is defined within objectA's class. However, it seems as though the placeholder argument doesn't actually have to be the type specified as the method's argument in order for IntelliJ to detect it as an argument of the method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.