25

I have set the eclipse java formatter to wrap lines that exceed 120 characters to conform to our team's coding standard. However, when I have a long string that is wrapped I want the plus sign (+) to appear as the last character on the first line e.g.

String s = "Very long line that should be " +
"wrapped across several rows"; 

The default behaviour is that the plus sign is placed on its own line e.g.

String s = "Very long line that should be "
+
"wrapped across several rows";

So is it possible to specify where the plus sign should appear in the eclipse java formatter?

Mathias Åhsberg
  • 387
  • 1
  • 4
  • 13

1 Answers1

50
Preferences > Java > Code Style > Formatter > Line Wrapping > Binary Expressions > Wrap before Operator

The above controls where + is placed. (Though it should never be on a its own line)

Deepak Azad
  • 7,903
  • 2
  • 34
  • 49
  • Thanks. That partially did the trick. The new row after the sign was due to that the second row was already wrapped (manually). And that "Never join already wrapped lines" was checked. – Mathias Åhsberg Jul 03 '12 at 07:55
  • 2
    This doesn't seem to work (in Luna). A row with strings and + signs always wraps the + to the next line even though other binary operators are wrapped according to the setting. Although the "Never join..." keeps correct wrapping if wrapped correctly manually. – levsa Sep 09 '15 at 14:22
  • How come this didn't work when I pasted a very long string that already has lots of \n in it? – pete Oct 09 '15 at 16:41
  • What is recommended by Java Coding Standard "+" sign should be at the end of line or at the beginning of new line and why? – Zlelik Oct 21 '15 at 13:55
  • In 2020-06 this is enabled by default and the location of the setting changed: `Window - Preferences - Java - Code Style - Formatter - Edit - Line Wrapping - Wrapping settings - Binary expressions - Additive operators (+,-)` - the first icon to the right of it extends into a drop-down menu with "wrap before operators" and "wrap after operators". – Neph Jul 12 '21 at 13:00