How to force the Eclipse Mars 4.5 formatter not to join already wrapped lines?
Asked Answered
L

2

16

I've just moved from eclipse Kepler to eclipse Mars and my Java formatter seems not to behave the same way anymore.

I used to be able to do the following:

object
    .method1()
    .method2()
    .method3();

The formatter would keep my code like that. However since I changed to eclipse mars, everything is wrapped to one line.

I've verified the formatter and I still have the option "Never join already wrapped lines" checked. My project doesn't use specific settings regarding the eclipse formatter. I tried recreating a formatter from scratch and the result is the same.

How can I force eclipse not to join those lines ?

Thanks

Lick answered 25/6, 2015 at 10:40 Comment(1)
Have you tried the new release 4.5.2? It seems to be last major release for Mars and next release would be 4.6 Neon. Bugs mentioned by @ojap is fixed.Gerent
L
9

I found solution: I selected all specific elements (Annotations, Class Declarations, ...) and defined Wrap where necessary instead of my usual Do not wrap. I then set the maximum line width to a high value so that Wrap when necessary never actually wraps anything. That seems to be sufficient for my already wrapped lines not to be joined and keep the default behavior of the formatter to "do not wrap".

EDIT: Even though that's a solution for the problem at hand, I've faced many more problems with Eclipse Mars's formatter that made me got back to Kepler. I tried Luna and it seems not to have the same problems. I'll probably be switching to Luna.

EDIT: I switched to Luna and everything works fine

EDIT: I tried the new Mars.1 and even though I do not have the exact same formatting, a lot of bugs have been fixed and it was enough for me to start using it for some projects. I'll probably be switching all my projects there in due time.

Lick answered 25/6, 2015 at 14:49 Comment(7)
I've also noticed Mars working differently with a formatter that I used in Luna. Seems like the formatter has had many changes (bugs.eclipse.org/bugs/show_bug.cgi?id=303519) with Mars. Switching back to Luna for now.Lockett
I really want to keep using Mars, but there really are a lot of issues with the formatter. It seems to be ignoring rules such as line wrapping for enum constant declarations. If set to 'Wrap all elements, every element on a new line', it doesn't wrap and all constants remain on one line...Philter
I'm also having this problem with Mars, especially around wrapping throws indentation on a new line.Oconner
In this blog post the author has put the old (Luna) formatting code into a plugin that can be added to the new (Mars) plugin directory and you can switch to it to have all the other benefits of Mars but the old formatter behaviour.Inositol
Thanks, this worked for me. But note that at the moment you should probably leave Do not wrap for Method Declarations > Declaration because of Bug 471364 (Method declarations in interfaces are indented too much if they follow a non-empty line and the formatter is configured to wrap method declarations where necessary.)Butcher
@Lockett Mars 4.5.2 is released in Feb. bugs.eclipse.org/bugs/show_bug.cgi?id=303519 is fixed. Does 4.5.2 fix your problem?Gerent
@pacoalcacer I'm not using Eclipse as much currently, good to know it's being fixed.Lockett
C
3

Add this line to your profile.xml or set the property to false if it already exists.

<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="false"/>

Sample xml could be found here.

Cooncan answered 25/6, 2017 at 7:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.