Java formatting: Indentation of conditions inside if (...)

I have code like this:


        if (a = b && c == d
                && (e == f
                        || g == h)
                || i == j) {
            k = l;
        }

        while (a = b && c == d
                && (e == f
                        || g == h)
                || i == j) {
            k = l;
        }


I haven't been able to find settings that make the code formatting indent the code as above.

If I enabled Wrapping & Braces -> Binary Expressions -> Align Parenthesized when multiline, the result is

        if (a = b && c == d
                && (e == f
                            || g == h)
                || i == j) {
            k = l;
        }

        while (a = b && c == d
                && (e == f
                            || g == h)
                || i == j) {
            k = l;
        }


This is close but the line with g == h gets indented 12 spaces instead of 8. Somehow seems that IDEA combines indentations settings a bit too much here.

If I enabled Wrapping & Braces -> Binary Expressions -> Align when multiline, the result is

        if (a = b && c == d
                && (e == f
                    || g == h)
                || i == j) {
            k = l;
        }

        while (a = b && c == d
                   && (e == f
                       || g == h)
                   || i == j) {
            k = l;
        }
Which makes indentations relative to the open parenthesis and indentation changes between if and while which is not what I wanted.

Tabs & Indents -> Use indents relative to expressions start also makes different indentation with if & while because start of expression is actually the opening parenthesis.

I want continuation expression on row with e == f to be intended 8 and the g == h continuation to be indented 8 spaces more.

Any ideas?
3 comments
Comment actions Permalink

You know that Eclipse can do this and apparently Idea cannot?

0
Comment actions Permalink

If's and while's do not have 'align when multiline' which is my curse too.

 

2

Please sign in to leave a comment.