IntelliJ 2019.3.1:Java代码格式化意外换行问题求助
Fixing Unexpected Line Wrapping in IntelliJ 2019.3.1 Java Formatting
Hey there! Let's troubleshoot why your line of code is getting wrapped even with a hard wrap set to 140. Here are the key settings to check in your IntelliJ 2019.3.1 instance:
- Open the Java Code Style Settings: Go to
File > Settings(or pressCtrl+Alt+S), then navigate toEditor > Code Style > Java, and switch to the Wrapping and Braces tab. - Check Assignment Line Wrapping: Look for the Assignments section. If the option is set to
Wrap alwaysorWrap if longwith a threshold lower than 140, that could be forcing the line to break. Set it toDo not wrapif you want to keep assignments on a single line, or ensureWrap if longuses your global hard wrap value of 140. - Verify Method Call Wrapping: Under the Method calls section, check the settings for
Wrap call arguments. If this is set to wrap arguments prematurely, it might split yourgetOrDefaultcall. Ensure it's set toWrap if long(using the 140 margin) orDo not wrapif you prefer arguments stay inline. - Check for Custom Line Break Rules: Scroll down to the Line breaks section and make sure there's no rule forcing line breaks after specific operators (like
=or method call dots) that would affect your line. - Invalidate Caches (If All Else Fails): Sometimes IntelliJ's cached settings can cause odd behavior. Go to
File > Invalidate Caches / Restart, select "Invalidate and Restart" to clear any stale cache data that might be overriding your settings.
After adjusting these, reformat your file with Ctrl+Alt+L again—your line List<Something> somethings = somethingsMap.getOrDefault(key, Collections.emptyList()); should stay on a single line as expected.
内容的提问来源于stack exchange,提问作者Konrad Konrad
相关产品推荐
相关产品推荐

