Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 349535

Summary: Code formatter does not wrap some long lines
Product: [Eclipse Project] JDT Reporter: Lauri Pekonen <larza>
Component: CoreAssignee: Ayushman Jain <amj87.iitr>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: amj87.iitr, daniel.hellsson, mateusz.matela, Olivier_Thomann, remy.suen
Version: 3.6.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Lauri Pekonen CLA 2011-06-16 04:52:27 EDT
Build Identifier: M20110210-1200

Code formatter does not wrap some long lines, can't pinpoint what causes it.

Reproducible: Always

Steps to Reproduce:
1. Set formatter line width to 120, indent 4 spaces only
2. Paste in the following code:

package test;

public class FormatterTest {

    void test() {
        if (true) {
            asdf.do1234567890123456(asdf.do12345678901234567890123456789012345().getTable().getSelectedRows().length == 1);
        }
    }

    static class asdf {
        static void do1234567890123456(boolean b) {

        }

        public static Foo do12345678901234567890123456789012345() {
            return null;
        }

    }

    static class Foo {

        public Bar getTable() {
            return null;
        }

    }

    static class Bar {

        public Object[] getSelectedRows() {
            return null;
        }

    }

}

3. The longest line here is 124 chars. On my Eclipse this line does not wrap. Wonder if this is reproducible. On 3.5 this works?
Comment 1 Remy Suen CLA 2011-06-16 05:06:40 EDT
Please open bugs with the Java tooling with the JDT team.
Comment 2 Ayushman Jain CLA 2011-06-16 09:38:22 EDT
I think this is the intended behaviour.

Please check the line wrapping options you have under Preferences>Java>Code style>Formatter> Line wrapping and for "Function calls>Qualified invocations" category, check the "Force split even if line shorter than maximum width" option. The call gets wrapped only if this option is checked, not otherwise.

Olivier, please correct me if i'm wrong.
Comment 3 Lauri Pekonen CLA 2011-06-17 03:23:44 EDT
Sorry, I don't understand. That solution will also wrap the shorter lines, which is not the desired behaviour.

Shouldn't "Wrap where necessary" just split the lines where they are longer than line width and leave others alone?
Comment 4 daniel.hellsson CLA 2011-11-17 09:29:17 EST
I have this problem in jdt_root 3.7.1 (Indigo Service Release 1), Build ID 20110916-0149.

With my example, line length set to 80 and "Wrap all arguments, each argument on a new line" and "Indent by one", the line is not indented!

Example code:
public class Foo
{
    private String this_is_the_alert_error_message = "Alert!";
    private String this_is_the_error_error_message = "Error!";

    public void testMethod()
    {
        final String messageInternalFailure =
            this_is_the_alert_error_message.concat( this_is_the_error_error_message );
        System.out.println( messageInternalFailure );
    }
}
Comment 5 Mateusz Matela CLA 2015-11-07 14:39:03 EST
This problem no longer occurs after the formatter redesign.

*** This bug has been marked as a duplicate of bug 303519 ***