I have a small problem with java code formatting in Intellij Idea 14.1.4. I have a piece of code formatted manually by me, that looks good for 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 won't reformat anything because the code is already well-formatted.
I have a scheme (code style settings can be downloaded here) with the next settings:
Could anybody explain how I can reach expected result?
Sometimes code formatting can get out of sync, but there's an easy fix in IntelliJ IDEA. You can use ⌘⌥L (macOS), or Ctrl+Alt+L (Windows/Linux) to reformat a selection of code according to your reformat settings.
Open the required file. Go to Source | Format Document or press Ctrl+Shift+F.
Open a file in the editor and place the caret at the declaration or usage of the desired method or a field. Alternatively, select the desired method or the field in the Project tool window. From the main menu, select Navigate | Call Hierarchy or press Ctrl+Alt+H .
The problem was resolved when I ticked property
"keep when reformatting"/"Line breaks"
it helps to format code on my own, with custom line breaks.
There is another one option called "Wrap first call" in IntelliJ IDEA 2017.3 (I'm not sure when they exactly added it):
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With