I've looked throughout Preferences -> Java -> Code Style -> Formatter and can't find any way to get eclipse to format my code like:
something. someMethod(). anotherMethod(). lastMethod();
Instead of:
something .someMethod() .anotherMethod() .lastMethod();
I know that's non-standard, but that's what I need.
Edit: This is not about getting lines to wrap. It's specifically about where the wrap happens in relation to the period. I want the period at the end of the line, before the newline and right now eclipse wants the period at the start of the next line.
Edit2: Even if I could find out where eclipse's source code it decides where to wrap the line, that might help. I think it might be in the JDT project, but I'm not 100% and there's a lot in there.
There is a "Toggle Word Wrap" command hidden in the "Window > Editor" menu (default shortcut is Alt+Shift+Y). Or you can use the Quick Access bar: Ctrl+3, and type wrap.
First of all, I don't think there is a way to get the standard Eclipse Java code formatter break lines after a .
... apart from modifying the formatter code itself. (And that means you are not running the standard formatter anymore!)
All is not lost. I did a Google search for "eclipse formatter plugin", and came across a link to the Jindent plugin in the Eclipse Marketplace. Digging a bit further, I found the documentation for the Jindent Formatter Settings. According to "5.6.1.9.4 Method Calls", Jindent can be told to break lines after a "." rather than before one.
So ... if you are prepared to pay for a Jindent license, you can get an Eclipse plugin for it for free that will indent your Java code the way that you prefer.
Disclaimers:
Current Java style guides recommend that you break lines before .
symbols, operators and so on. I would advise that you learn to live with the "standard" style ... because that is what other people who read your code are most likely to be expecting.
Reference:
Try this.
Window > Preferences > Java > Code Style > Formatter > Edit > Line wrapping > Function Calls, set the 'Line wrapping policy' as 'Wrap all elements, every element on a new line'.
If found already then cool.
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