Bug 233011 - [formatter] Formatting edited lines has problems (esp. with comments)
Summary: [formatter] Formatting edited lines has problems (esp. with comments)
Status: VERIFIED DUPLICATE of bug 232768
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.4 RC3   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-05-20 12:42 EDT by Dani Megert CLA
Modified: 2008-05-30 10:49 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dani Megert CLA 2008-05-20 12:42:23 EDT
3.4 RC1.

According to Benno's findings (see bug 232768 and the attached JUnit test case) there are some regressions when formatting edited lines on save.

Benno, please add more details here i.e. what worked and what's now broken.

We either need to do something in JDT Core or in JDT Text to get more accurate results.
Comment 1 Benno Baumgartner CLA 2008-05-21 09:57:20 EDT
I20080520-2000

Given:
package test;
public class E01 {
	/**
	 * Javadoc
	 * comment
	 */
	/*
	 * block
	 * comment
	 */
	// single    line comment
}
1. Enable 'Format edited lines' on the Save Actions preference page, use the Eclipse built-in formatter profile
2. Add a space somewhere inside Javadoc, Save
  Is: Javadoc is formatted into one line
3. Add a space somewhere inside block comment, Save
  Is: No formatting
  Should and was in M6: Block comment is formatted into one line
4. Add a space somewhere inside single line comment, Save
  Is: No formatting
  Should and was in M6: format comment
Comment 2 Benno Baumgartner CLA 2008-05-21 10:15:36 EDT
Frederic? I've verified, that I'm passing in the correct regions (size of the comment partitions) to the formatter. I'm calling the formatter in CodeFormatFix line 82 with
CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS
complete source of compilation unit
0 indentation
\r\n as line delimiter



Comment 3 Frederic Fusier CLA 2008-05-21 10:39:31 EDT
(In reply to comment #2)
> Frederic? I've verified, that I'm passing in the correct regions (size of the
> comment partitions) to the formatter. I'm calling the formatter in
> CodeFormatFix line 82 with
> CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS
> complete source of compilation unit
> 0 indentation
> \r\n as line delimiter
> 
Are the regions limited to the modified text only or do they include the entire text of the modified comments?

If the former answer is true, then this explains the bug as the current comment formatter cannot handle such a case (see detailed explanation in bug 231093 comment 2). In this case, I would consider this bug as a duplicate of bug 232054.

If the latter answer is true, then I have to investigate further...
Comment 4 Benno Baumgartner CLA 2008-05-21 11:00:02 EDT
(In reply to comment #3)
> (In reply to comment #2)
> > Frederic? I've verified, that I'm passing in the correct regions (size of the
> > comment partitions) to the formatter. I'm calling the formatter in
> > CodeFormatFix line 82 with
> > CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS
> > complete source of compilation unit
> > 0 indentation
> > \r\n as line delimiter
> > 
> Are the regions limited to the modified text only or do they include the entire
> text of the modified comments?

They include the entire text of the modified comment (the size of the comment partition).

> If the former answer is true, then this explains the bug as the current comment
> formatter cannot handle such a case (see detailed explanation in bug 231093
> comment 2). In this case, I would consider this bug as a duplicate of bug
> 232054.

I'm aware of the bug 232054, and I do work around it in CodeFormatFix.adaptRegions(IRegion[], ICompilationUnit)

> If the latter answer is true, then I have to investigate further...

Thank you. You can easily try this out with the format selection action, if your selection _starts outside a comment region_ then the entire cu is formatted with F_INCLUDE_COMMENTS. In order to format the block and single line comment in the example from comment 1 it is required to select the class body including { and }. Any smaller selection does not seem to format the block and single line comment. 
Comment 5 Frederic Fusier CLA 2008-05-24 16:54:25 EDT
We can consider this bug as a duplicate of bug 232768 as the patch applied for that bug also fixes this one...


*** This bug has been marked as a duplicate of bug 232768 ***
Comment 6 David Audel CLA 2008-05-30 10:49:58 EDT
Verified for 3.4RC4 using build I20080530-0100