Eclipse code formatter multiline function call closing bracket indention
Asked Answered
R

1

8

Currently my eclipse formatter formats a multiline function call like this:

someObject.doSomething(
  some().long().chain().of().methods()
  );

But what I want is for eclipse to align the closing bracket with the method call:

someObject.doSomething(
  some().long().chain().of().methods()
);

I have tried playing around with new line and wrapping rules in the code formatter but haven't been able to achieve this. What would be the solution?


After some time of digging I found a similar question which has an accepted answer but seems not to answer the same question: Can the Eclipse formatter be configured to indent multiple lines between parenthesis properly?

The author of this question also states:

Edit: I found the settings for "Line Wrapping" -> "Default indentation for wrapped lines" and "Default indentation for array initializes" and have set them to "1" instead of "0". That is better for the array initializers, but still doesn't indent closing parethesis to match the opening parenthesis the way that I want it to:

Rappee answered 21/9, 2015 at 11:48 Comment(1)
maybe in "Parentheses" -> "Method invocation"?Jewel
B
0

The latest proposal on this does not take into account the closing );, but the first expression.
See Eclipse 4.23 (Q1 2022):

Method invocation wrapping indentation

It turns out it's not obvious how to indent a wrapped method invocation when the preceding expression itself is complex enough to also be wrapped into multiple lines.

Should the indentation be added to the existing indentation at the end of the expression, or just reset and assume that only the indentation of expression's first line matters?

Previously only the former behavior was available, now there's a setting to choose the latter.

The checkbox called Indent from the base expression's first line is located in the Line Wrapping > Wrapping settings > Function calls section, right under the Qualified invocations setting.

Method invocation wrapping -- https://static.mcmap.net/file/mcmap/ZG-AbGLDKwf1c1bQXVMsZ7BxXS2vbmb/eclipse/news/4.23/images/formatter-invocation-wrapping.png

Ballarat answered 27/2, 2022 at 21:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.