1

I'm using eclipse as my IDE of choice (or my company's choice) and can't figure out how to adjust the source code formatting settings to make usage of basic lambda expressions on stream not look totally awkward.

For example take a look at the following snippet:

final Map<String, FieldInformation> fieldInformations = fieldDescriptions
    .values()
    .stream()
    .collect(
        Collectors.toMap(f -> f.fieldId().fieldName(),
            f -> new FieldInformation(f.fieldId(), f.dataType())));

This is the way eclipse decides to format the code (we enforce line breaks at 111 characters). But I want it to look more like this

final Map<String, FieldInformation> fieldInformations = fieldDescriptions
    .values().stream().collect(Collectors.toMap(f -> f.fieldId().fieldName(),
        f -> new FieldInformation(f.fieldId(), f.dataType())));

I just can't figure out how to change the line-break or whitespace settings in eclipse to format it this way automatically.

Scott Hutchinson
  • 1,703
  • 12
  • 22
dpr
  • 10,591
  • 3
  • 41
  • 71
  • does it help ? https://stackoverflow.com/questions/1601793/how-do-i-modify-eclipse-code-formatting – Ori Marko Jun 19 '17 at 07:00
  • 3
    When you have worked more with streams the formatting convention of one per line will make a lot more sense. – Thorbjørn Ravn Andersen Jun 19 '17 at 07:01
  • @user7294900 No, I know where to find the formatting settings, but I can't figure out the setting that changes the formatting as desired, – dpr Jun 19 '17 at 09:03
  • @ThorbjørnRavnAndersen I've been working with streams for some time now and don't share your opinion :-) If I use the first formatting I can simply write a loop which takes exactly the same amount of code lines and is easier to read. – dpr Jun 19 '17 at 09:05
  • @dpr I suggest you discuss this with those who will maintain your code. It is not the amount of lines on screen but the readability. Not having to mentally parse the source to clearly see what belongs together may be more important than you think. – Thorbjørn Ravn Andersen Jun 19 '17 at 09:09
  • @ThorbjørnRavnAndersen, thanks for your suggestion. Actually I'm maintaining the code and I'm pretty fine with the desired formatting. – dpr Jun 19 '17 at 09:12

0 Answers0