34

[Copied from]: Wrapping chained method calls on a separate line in eclipse for Java

For example, I have this:

someObject.A().B().C();

But I really want this:

someObject.A()
          .B()
          .C();

I wanted to ask how to achieve that formatting in intellij. I was unable to achieve it. I want to use the same formatting given in this answer.

Community
  • 1
  • 1
Abhinav Aggarwal
  • 1,205
  • 2
  • 11
  • 24

1 Answers1

70

Small disclaimer: this is IJ 14.4, it's possible that in later versions it may have been changed/renamed/etc, but it should be there somewhere nonetheless


Go to Settings -> Editor -> Code style -> Java and select the Wrapping and Braces tab, then scroll to Chained method calls. Check the little combo on the right of the item, default Do not wrap, and change it to Wrap always.

Chained method wrapping

Depending on your prefference, you may want to also consider the next Align when multiline checkbox

Align when multiline

Morfic
  • 15,178
  • 3
  • 51
  • 61
  • 2
    If you want builder pattern recognition, please see this feature request: https://youtrack.jetbrains.com/issue/IDEA-122600 – proski Nov 08 '16 at 03:00
  • Still valid in 2019.2. It's well worth to take some time and review all options. Auto align makes comparing code in a three-way diff a breeze. – Pieter De Bie Aug 13 '19 at 09:11