Intellij formatter chained method calls
Asked Answered
M

1

6

How to force IntellJ code formatter to autoindent wrapped arguments list on different level than wrapped chained method calls:

EDIT: See updated examples for better problem description. The default formatter works as expected if I wrap each consecutive method call to a new line. The problem occurs only if I want to leave one or more dots per line:

Wrapping this:

new Something()
    .chained("arg1", "arg2", "very long arg I want to see in new line")
    .chained("arg1", "arg2", "very long arg I want to see in new line")
    .extra().chained("arg1", "arg2", "very long arg I want to see in new line")
    .extra().chained("arg1", "arg2", "very long arg I want to see in new line");

I would expect something like this:

new Something()
    .chained("arg1", "arg2", 
        "very long arg I want to see in new line")
    .chained("arg1", "arg2", 
        "very long arg I want to see in new line")
    .extra().chained("arg1", "arg2", 
        "very long arg I want to see in new line")
    .extra().chained("arg1", "arg2", 
        "very long arg I want to see in new line");

But the result is:

new Something()
    .chained("arg1", "arg2", 
        "very long arg I want to see in new line")
    .chained("arg1", "arg2", 
        "very long arg I want to see in new line")
    .extra().chained("arg1", "arg2", 
    "very long arg I want to see in new line")
    .extra().chained("arg1", "arg2", 
    "very long arg I want to see in new line");
Madiemadigan answered 12/11, 2015 at 19:33 Comment(0)
D
12

Go to File > Settings > Editor > Code Style > Java > Wrapping and Braces

Configure Chained method calls to Wrap always and mark Align when multiline:

enter image description here

Discrepant answered 17/7, 2019 at 20:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.