More or less exactly what the title says. When I cmd + f, it formats the code according to the settings for the project. One of those settings is the right margin. The problem is it will split string literals also to avoid over running the margin. So this:
stringBldr.append("some text that's more than 80 characters");
Becomes this:
stringBldr.append("some text that's more " +
"than 80 characters");
Which completely defeats the purpose of using the StringBuilder in the first place. In Eclipse, I could tell it to ignore String literals when formatting. Is there a way to do this in IntelliJ without manually disabling the code formatter for that section (e.g. @formatter:off)?
In your case, try to set
Editor > Code Style > Java > Wrapping and Braces > Method call arguments
to Wrap if long. And potentially with New line after '('. It would put the start of the String on the next line and unless the string is too long on it's own (+ indent), it won't be cut into two.
Here is before formatting (my hard wrap limit is at 120 characters and the lorem is 100 characters long making second line 125 characters long)
StringBuilder stringBldr = new StringBuilder();
stringBldr.append("Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...");
Here is with Method call arguments set at Wrap if long and New line after '(' selected
StringBuilder stringBldr = new StringBuilder();
stringBldr.append(
"Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...");
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