Bug 258801 - [formatter] Java formater trangresses line length limit
Summary: [formatter] Java formater trangresses line length limit
Status: VERIFIED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4.1   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 3.6 M6   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-15 07:20 EST by benson margulies CLA
Modified: 2010-03-08 05:21 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 benson margulies CLA 2008-12-15 07:20:18 EST
Build ID: M20080911-1700

Steps To Reproduce:
1. Set maximum line length in formatter preferences
2. Enable wrapping
3. Apply source/format to for-loop to be supplied below.
4. Resulting line is too long.


More information:
            for (Element el = XDOMUtil.getFirstChildElementNS(constraintEl, XmlSchema.SCHEMA_NS); 
                 el != null; el = XDOMUtil.getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) {
}


Note that this is a problem for those of us who use checkstyle, or a related tool, to enforce a maximum line length.

It would be really good if the formatter could produce 

  for (term a;
       term b;
       term c) {

but I'll take anything that respects the line length.
Comment 1 Frederic Fusier CLA 2009-01-05 11:38:57 EST
The Eclipse built-in profile already set the maximum line length to 80, did you change this default value while formatting your snippet?
Comment 2 benson margulies CLA 2009-01-05 13:10:10 EST
Yes we changed it. However, the point is this, for any length we set it to, the formatter will make lines longer than that length.
Comment 3 Frederic Fusier CLA 2009-06-23 04:46:02 EDT
Hmm, using 3.5.0 and I format the following snippet using Eclipse built-in profile:

public class X {

    void foo() {
            for (Element el = XDOMUtil.getFirstChildElementNS(constraintEl, XmlSchema.SCHEMA_NS); 
                el != null; el = XDOMUtil.getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) {
            }
    }
}

And I get the following output:

public class X {

>>  void foo() {
>>  >> for (Element el = XDOMUtil.getFirstChildElementNS(constraintEl,
>>  >>  >>  >>  XmlSchema.SCHEMA_NS); el != null; el = XDOMUtil
>>  >>  >>  >>  .getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) {
>>  >>  }
>>  }
}

I've replaced the tabulation character with '>>  ' and space with '.' to make lines fit into the bugzilla comment...

I observed that the max line length of 80 characters is honored in this peculiar case. Is it the split of the lines which does not fit your expectation or is there something I'm missing?
Comment 4 Frederic Fusier CLA 2010-02-02 05:49:02 EST
As there is no answer on my last comment, I close this bug as worksforme for the while. Feel free to reopen if you have more information about this, thx
Comment 5 Srikanth Sankaran CLA 2010-03-08 05:21:38 EST
Verified for 3.6M6