JockX
JockX

Reputation: 2126

Intellij formatter chained method calls

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");

Upvotes: 6

Views: 3489

Answers (1)

Jaumzera
Jaumzera

Reputation: 2359

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

Upvotes: 12

Related Questions