Bug 257111

Summary: [Formatter] Add option to allow multi-line expression to be aligned
Product: [Eclipse Project] JDT Reporter: Mike M <gubespam>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: NEW --- QA Contact:
Severity: enhancement    
Priority: P3 CC: daniel_megert
Version: 3.4.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Mike M CLA 2008-12-01 13:20:21 EST
Add the necessary additional settings to the formatter such that the following result can be achieved:

Currently, the formatter something like the follow when formatting expressions involving binary operators, and that expression is on the RHS of an assignment (line width = 40):

class Example extends AnotherClass
{
    int foo()
    {
        int sum =
                100 + 200 + 300 + 400 +
                        500 + 600 +
                        700 + 800;
        int product =
                1 * 2 * 3 * 4 * 5 * 6 *
                        7 * 8 * 9 * 10;
        boolean val =
                true && false && true &&
                        false && true;
        return product / sum;
    }
}

The desired result is something like the following:

class Example extends AnotherClass
{
    int foo()
    {
        int sum =
                100 + 200 + 300 + 400 +
                500 + 600 + 700 + 800;
        int product =
                1 * 2 * 3 * 4 * 5 * 6 *
                7 * 8 * 9 * 10;
        boolean val =
                true && false && true &&
                false && true;
        return product / sum;
    }
}

The key idea is that each line of the expression is indented the same amount as the first line (eg. the 500 lines up with the 100).

This setting would be very helpful when assignments must wrap multiple lines, and they are more readable when they line up. A specific example is SQL statements, where the SQL itself was formatting before being placed in multiple concatenated strings; the query is more readable when all of the lines line up.