Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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");
like image 883
JockX Avatar asked Nov 12 '15 19:11

JockX


People also ask

How can I beautify Java code in IntelliJ?

Go to Settings/Preferences | Editor | Code Style, select your programming language, and open the Wrapping and Braces tab. In the Keep when reformatting section, select the formatting rules which you want to ignore and deselect those which should be applied. Reformat your code ( Ctrl+Alt+L ).

How check method calls in IntelliJ?

on the toolbar in the Find tool window or press Ctrl+Alt+Shift+F7 . While in the Find tool window, you can also use the Preview area to check the places where the usages were found, to see a call hierarchy for methods, data flow for fields, and so on.

How do I align lines in IntelliJ?

(default Ctrl + Alt + L ) for the whole file or Code → Auto-Indent Lines (default Ctrl + Alt + I ) for the current line or selection. You can customise the settings for how code is auto-formatted under File → Settings → Editor → Code Style .


1 Answers

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

like image 178
Jaumzera Avatar answered Oct 01 '22 22:10

Jaumzera