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
Window → Preferences → Java → Code Style → Formater → Edit → Line wrapping → Never join already wrapped lines
Window > Preferences > Java > Code Style > Formater > Edit > Line wrapping > Function Calls, set the 'Line wrapping policy' as 'Wrap all elements, every element on a new line'.
For those who have eclipse code formatting settings checked into source control (for consistent code formatting across the whole team), the .settings
folder is checked in.
The property that will give you this formatting behavior is in the .settings/org.eclipse.jdt.core.prefs
file.
The property is:
org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=80
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With