Formatting Java code in intellij Idea (chain calls)

I have a little problem with formatting java code in Intellij Idea 14.1.4. I have a piece of code manually formatted by me that looks good to me:

public class Test { private static final ImmutableMap<String, String> map = new ImmutableMap.Builder<String, String>() .put("key", "value") .put("key", "value") .put("key", "value") .put("key", "value") .put("key", "value") .put("key", "value") .build() } 

but when I reformatted this code (Ctrl + Alt + L), I got:

 public class Test { private static final ImmutableMap<String, String> map = new ImmutableMap.Builder<String, String>().put("key", "value") .put("key", "value") .put("key", "value") .put("key", "value") .put("key", "value") .put("key", "value") .build() } 

Expected Result: Intellij will not reformat anything because the code is formatted well.

I have a scheme (code style settings can be downloaded here ) with the following settings: enter image description here

Can someone explain how I can achieve the expected result?

+6
source share
2 answers

The problem was resolved when I noted the property

"save when reformatting" / "Line break"

It helps format the code yourself, with custom line breaks.

+4
source

IntelliJ IDEA 2017.3 has another option called "Wrap first call" (I'm not sure when they added it for sure):

Enable first call

0
source

All Articles