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

greg-449
  • 109,219
  • 232
  • 102
  • 145
Crystark
  • 3,693
  • 5
  • 40
  • 61
  • 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. – paco alcacer Mar 18 '16 at 09:16

2 Answers2

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.

Crystark
  • 3,693
  • 5
  • 40
  • 61
  • 1
    I've also noticed Mars working differently with a formatter that I used in Luna. Seems like the formatter has had many changes (https://bugs.eclipse.org/bugs/show_bug.cgi?id=303519) with Mars. Switching back to Luna for now. – ojap Jun 27 '15 at 11:36
  • 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... – Jon McPherson Jun 30 '15 at 15:20
  • I'm also having this problem with Mars, especially around wrapping throws indentation on a new line. – b1nd Jul 06 '15 at 00:01
  • 7
    In [this blog post](http://eclipse-n-mati.blogspot.ch/2015/06/eclipse-mars-how-to-switch-back-to.html) 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. – Daniel Widdis Jul 14 '15 at 06:31
  • 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.`) – msa Jul 14 '15 at 13:05
  • 1
    @ojap Mars 4.5.2 is released in Feb. https://bugs.eclipse.org/bugs/show_bug.cgi?id=303519 is fixed. Does 4.5.2 fix your problem? – paco alcacer Mar 18 '16 at 09:12
  • @pacoalcacer I'm not using Eclipse as much currently, good to know it's being fixed. – ojap Mar 19 '16 at 12:39
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.

Gayan Weerakutti
  • 11,904
  • 2
  • 71
  • 68