Bug 257111 - [Formatter] Add option to allow multi-line expression to be aligned
Summary: [Formatter] Add option to allow multi-line expression to be aligned
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4.1   Edit
Hardware: PC Windows XP
: P3 enhancement with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-01 13:20 EST by Mike M CLA
Modified: 2008-12-02 02:53 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.