Bug 44036 - Java code formatter wraps line too much.
Summary: Java code formatter wraps line too much.
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.0 M4   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-10-01 16:13 EDT by Adalbert Homa CLA
Modified: 2003-10-14 07:49 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Adalbert Homa CLA 2003-10-01 16:13:45 EDT
When the Java code formatter decides the line needs to wrapped, it will create
very long and ugly lines. See the following example:

This line formatted (from in a method) with line length 80:
  String s ="alfa" + "beta" + "gamma" + "delta" + "alfa" + "beta" + "alfa";
will be wrapped as:
        String s =
            "alfa" + "beta" + "gamma" + "delta" + "alfa" + "beta" + "alfa";

Adding + "beta" to the previous line will wrapped as:

        String s =
            "alfa"
                + "beta"
                + "gamma"
                + "delta"
                + "alfa"
                + "beta"
                + "alfa"
                + "beta";

Wrapping of a very long method declaration looks even more uggly.

Here is suggestion. Most people do not want care too much about wrapping, they
care more about indenting (this is how Emacs works). Can we have this as an
alternative formatting ?
Comment 1 Philipe Mulet CLA 2003-10-02 04:43:39 EDT
The new formatter can perform compact line split.

        String s =
            "alfa" + "beta" + "gamma" + "delta"
                + "alfa" + "beta" + "alfa" + "beta";
Comment 2 Adalbert Homa CLA 2003-10-02 09:14:05 EDT
In what release ?
This format is a little bit better, but why is there an new line after '=' ?
Why are we not following Sun's conventions ? I found them quite clear.
Here is the link for line wrapping:
http://java.sun.com/docs/codeconv/html/CodeConventions.doc3.html#248
Comment 3 Olivier Thomann CLA 2003-10-02 10:43:08 EDT
The new formatter is not activated yet.
The result for your input will be:
String s = "alfa" + "beta" + "gamma" + "delta" + "alfa" + "beta" + "alfa"
        + "beta";

You will be able to change this formatting according to preferences. It is not 
sure that the preferences wizard will be available when the new formatter is 
activated.
Comment 4 Olivier Thomann CLA 2003-10-03 10:43:51 EDT
This is addressed in the new formatter.
Fixed and released in HEAD.
Regression test added.
Comment 5 Adalbert Homa CLA 2003-10-08 16:18:46 EDT
I am checking this bug in I20031008, and does not appear fixed.
Comment 6 Olivier Thomann CLA 2003-10-08 17:04:28 EDT
Did you activate the new formatter?
Comment 7 Olivier Thomann CLA 2003-10-08 17:14:38 EDT
By default the new formatter is not activated. You have to go to:
Preferences>Java>Work in progress and check the last checkbox.
Let me know if it works as expected.
Be careful when you change the formatter options. You might end up with the bug
44425.
Comment 8 Adalbert Homa CLA 2003-10-09 09:59:52 EDT
The new formatter is wrapping lines much better. I think we can close this bug.
Comment 9 David Audel CLA 2003-10-14 07:49:41 EDT
Verified.