1

I have this line showing the problem:

Which setting in the Eclipse Java formatter do I have to change so the line will break like

return this.data.getNumberOfGenerationsWithoutSignificantImprovementPassed()
            > MAX_NUMBER_OF_GENERATIONS_WITHOUT_SIGNIFICANT_IMPROVEMENT;

or like

return this.data.getNumberOfGenerationsWithoutSignificantImprovementPassed() >
            MAX_NUMBER_OF_GENERATIONS_WITHOUT_SIGNIFICANT_IMPROVEMENT;

? If both is possible, I prefer the former.

UTF-8
  • 575
  • 1
  • 5
  • 23

1 Answers1

0

On Mac, go to Eclipse -> preferences. On Windows, I believe it is Windows -> preferences... but don't quote me on that!

  • Expand Java -> Code Style -> Formatter
  • To the right of the "Active profile" bar, choose edit.
  • A new window will open- choose the "Line Wrapping" tab.
  • Scroll down to "Expressions" and choose conditionals. Pick your favorite!

Bonus points: This is where you can set all sorts of different styles, if you have not before, like number of spaces per tab character. Once you get everything set up just right, name your profile and export it. I use the same theme on 3 different computers and the consistency is nice!

BRasmussen
  • 350
  • 2
  • 15
  • I don't want to wrap the line at every `>` but only if it's necessary because the line is too long and has to be wrapped **somewhere**. Then it should break the line on `>` rather than at `.`. It was set to "Wrap when necessary" and doesn't work in this specific case. The line (the second one as it's currently wrapped) is 133 characters long in total and the maximum line length was set to 120. Nothing happened. I set it to 90 just in case indentation is ignored but it still does nothing. – UTF-8 Jan 29 '16 at 16:27
  • Are you making sure to change the General Settings value of the width, rather than just the test width value for the Formatter screen? Also, once you apply those changes, did you hit cmd + shift + F while clicked in your file to format the file? – BRasmussen Jan 29 '16 at 17:16
  • Yes, I changed the actual width value, not just the preview one. I made very sure to press `Ctrl + F` and to press the "apply" button so the change will be written to the disk (which I checked using git). Furthermore I made sure that the formatter isn't blocked by any syntax violations (I changed a line before and after the line I want to change so I see whether they get wrapped when I press `Ctrl + F` and they do) and by now I even have restarted not only Eclipse but also my entire machine. – UTF-8 Jan 29 '16 at 20:47
  • According to http://stackoverflow.com/questions/2378258/what-is-the-auto-alignment-shortcut-key-in-eclipse it should be ctrl + shift + F on Windows. – BRasmussen Jan 29 '16 at 21:36
  • Thanks, but nope. I'm a Linux user and was simply too sloppy to write the word "Shift". `Ctrl + F` is of course searching but I pressed the correct key combination (`Ctrl + Shift + F`). As I said: The the other lines get formatted as they should, so formatting definitely works. I also have auto-formatting on save enabled, so my files are always formatted properly when I save them without me having to press any key combination other than `Ctrl + S` for saving. – UTF-8 Jan 29 '16 at 22:50