0

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.

6
  • does it help ? stackoverflow.com/questions/1601793/… Commented Jun 19, 2017 at 7:00
  • 3
    When you have worked more with streams the formatting convention of one per line will make a lot more sense. Commented Jun 19, 2017 at 7: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, Commented Jun 19, 2017 at 9: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. Commented Jun 19, 2017 at 9: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. Commented Jun 19, 2017 at 9:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.