Wrapping chained method calls on a separate line in Eclipse for Java

Complementing Deepak Azad’s answer, what you exactly need is the following:

Windows: Window → Preferences → Java → Code Style
→ Formatter → Edit → Line wrapping (tab)

Mac OS: ADT → Preferences → Java → Code Style
→ Formatter → Edit → Line wrapping (tab)

Then, in the list at the left, select:

Function Calls → Qualified invocations

Now below this list, set Line wrapping policy to:

Wrap all elements, except first element if not necessary

Check:

Force split, even if line shorter than maximum line width

Finally, set Indentation policy to (thanks @Turbo):

Indent on column

It should give you the exact behavior you asked for.


BONUS: Android Studio / IntelliJ Idea:

Mac OS: Android Studio → Preferences (Cmd +,) → Editor → Code Style → Java → Wrapping And Braces tab → Chained method calls

select

Wrap always

and check

Align when multiline

Leave a Comment