Bug 246372 - [formatter] Width setting for comments appears to be off-by-one
Summary: [formatter] Width setting for comments appears to be off-by-one
Status: VERIFIED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4.1   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.6 M1   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-09-05 09:45 EDT by Andrew Cowie CLA
Modified: 2009-08-04 05:00 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Cowie CLA 2008-09-05 09:45:40 EDT
Build ID: M20080903-2000

Set comment line width to 78, and run formatter on something with some paragraph length JavaDoc. Comments will be wrapped, but with some lines will have a maximum width of 79 columns, not 78.

This appears to be an off-by-one error. The formatter is working, and well. We use the code formatter to normalize a largish code base both in development in Eclipse and via the command line for others. Suddenly, everything wants to reformat, and careful investigation shows it to now be wrapping at column 79 instead of 78.

(we use 78 so that when documentation is in a diff it doesn't wrap in an 80 column wide terminal. Quite handy, actually)

Obviously I could try setting the width to 77 as a workaround, but then if this is fixed everything will break again.

AfC
Comment 1 Frederic Fusier CLA 2008-09-05 10:54:13 EDT
Can you provide a small code snippet showing the issue to help me to figure out what happen exactly in your case?
Comment 2 Frederic Fusier CLA 2008-09-05 11:21:00 EDT
Note that I cannot reproduce the problem using the same build...

Consider the following test case:

public interface Test1 {
	/** Maximum line width for comments = 69: this___word_ends_at_68 */
	void unchanged();
	/** Maximum line width for comments = 69: this___word_ends_at__69 */
	void splitCommentNotLine();
	/** Maximum line width for comments = 69: this___word_ends_at___70 */
	void splitCommentAndLine();
}

Format it using profile 'Eclipse [built-in]' + Max line width for comments=69
+ Tab policy=Spaces only (that helps to make the snippet more readable in bugzilla comments...), and you'll get:

public interface Test1 {
    /** Maximum line width for comments = 68: this___word_ends_at_68 */
    void unchanged();

    /**
     * Maximum line width for comments = 68: this___word_ends_at__69
     */
    void splitCommentNotLine();

    /**
     * Maximum line width for comments = 68:
     * this___word_ends_at___70
     */
    void splitCommentAndLine();
}

The first comment is not split as it text is not over the max width (same as 3.3). The second comment is split but the line is not as after the comment split, the line does not exceed the max width. The third comment is split and the line as well because even after the comment split the line exceeds the max width from 1 char.


Here's another similar test case:

public interface Test2 {
    /** 
     * Maximum line width for comments = 68: this____word_ends_at_68
     */
    void unchanged();
    /** 
     * Maximum line width for comments = 68: this____word_ends_at__69
     */
    void splitLine();
}

Format it using the same profile than previous test case. You'll get:
public interface Test2 {
    /**
     * Maximum line width for comments = 68: this____word_ends_at_68
     */
    void unchanged();

    /**
     * Maximum line width for comments = 68:
     * this____word_ends_at__69
     */
    void splitLine();
}
Comment 3 Frederic Fusier CLA 2008-09-05 11:27:38 EDT
(In reply to comment #2)
Sorry, first test case should be:

public interface Test1 {
    /** Maximum line width for comments = 68: this___word_ends_at_68 */
    void unchanged();
    /** Maximum line width for comments = 68: this___word_ends_at__69 */
    void splitCommentNotLine();
    /** Maximum line width for comments = 68: this___word_ends_at___70 */
    void splitCommentAndLine();
}
Comment 4 Frederic Fusier CLA 2009-06-25 07:45:33 EDT
Without failing snippet, I consider this bug as WORKSFORME based on given comment 2 and comment 3 tests cases...
Comment 5 Ayushman Jain CLA 2009-08-04 04:40:25 EDT
Verified for 3.6M1 using build I20090802-2000