1

I'm using IntelliJ IDEA Ultimate 2019.

Thanks to this question, I was able to put the binary operator on the next line when code reformatting breaks lines. However, I do not find how to prevent the comma from braking like this:

String someWords = "sentence";
int someName = 1;
String m = String.format("A very long long long %s with information but too long for %s line.", someWords
    , someName);

Expected behavior:

String someWords = "sentence";
int someName = 1;
String m = String.format("A very long long long %s with information but too long for %s line.", 
    someWords, someName);

If I change the variable name someWords by someWord (shorter by 1 character) then it seems to work as expected... Is it a wrapping bug or did I miss something in the CodeStyle settings?

Edit: to make the example work, 3 indents of size 4 are needed, with max length at 120.

public class Test {

    public static void test() {
        if (true) {
            String someWords = "sentence";
            int someName = 1;
            String m = String.format("A very long long long %s with information but too long for %s line.", someWords
                    , someName);
        }
    }
}
fidekild
  • 161
  • 3
  • 13
  • 1
    Please clarify if you have "Ensure right margin is not exceeded" (Preferences | Editor | Code Style | Java | Wrapping and Braces) option enabled? Thanks – Olga Klisho Oct 30 '20 at 13:13
  • @OlgaKlisho yes it is enabled, is it the cause of the issue? – fidekild Oct 30 '20 at 16:21
  • @OlgaKlisho After checking what it does, I do want this behavior. However, I want the list wrapped with commas at the end of a line, not starting a new line. And this is the behavior in the general case, it just seems to break if the sentence is exactly of the size of my example. – fidekild Oct 30 '20 at 16:27
  • Do I get it right that ", someName);" part is moved to a separate line when you do the code formatting? If yes, can you please file an issue at the YouTrack (https://youtrack.jetbrains.com/issue) sharing your settings. Thanks – Olga Klisho Nov 03 '20 at 17:27
  • @OlgaKlisho yes, exactly. I'll file an issue then. – fidekild Nov 04 '20 at 16:50

0 Answers0