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

Bug 313651

Summary: [formatter] format comments (differs between paste and save action)
Product: [Eclipse Project] JDT Reporter: Hajo Czub <Hajo>
Component: CoreAssignee: Frederic Fusier <frederic_fusier>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, jarthana, Olivier_Thomann
Version: 3.6   
Target Milestone: 3.6.1   
Hardware: PC   
OS: Windows XP   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=293300
https://bugs.eclipse.org/bugs/show_bug.cgi?id=305371
Whiteboard:
Attachments:
Description Flags
Formatter part for comments
none
Settings of save action
none
Proposed patch
none
New proposed patch none

Description Hajo Czub CLA 2010-05-20 01:59:01 EDT
Build Identifier: I20100429-1549

The result of the code format after the save action is not correct.

Reproducible: Always

Steps to Reproduce:
Settings see appendings.
1. create a function like:
	public void testMethod()
	{
		// Comment 1
		System.out.println("start");
		System.out.println("next");
		System.out.println("end");
	}

2. save -> result: no change
3. mark the "next" line an comment this by using "shift + control + C" -> result:
	public void testMethod()
	{
		// Comment 1
		System.out.println("start");
//		System.out.println("next");
		System.out.println("end");
	}

4. save -> result: no change
5. copy the comment line after the commented "next" line -> result:
	public void testMethod()
	{
		// Comment 1
		System.out.println("start");
//		System.out.println("next");
		// Comment 1
		System.out.println("end");
	}
6: save -> result:
	public void testMethod()
	{
		// Comment 1
		System.out.println("start");
//		System.out.println("next");
// Comment 1
		System.out.println("end");
	}

That's annoying. There is no workarround available
Comment 1 Hajo Czub CLA 2010-05-20 02:03:40 EDT
Created attachment 169270 [details]
Formatter part for comments
Comment 2 Hajo Czub CLA 2010-05-20 02:04:55 EDT
Created attachment 169271 [details]
Settings of save action
Comment 3 Frederic Fusier CLA 2010-05-20 12:58:01 EDT
(In reply to comment #0)
>...
> That's annoying. There is no workarround available

There's one workaround, not perfect but if you add an empty lines between the commented line and the comment, this issue does not occur.

For example:
class X {
    public void testMethod()
    {
        // Comment 1
        System.out.println("start");
//        System.out.println("next");

        // Comment 1
        System.out.println("end");
    }
}

The code is formatted properly, the line // Comment 1 is untouched.

This was already broken using 3.6M6. I guess this regression was introduced while fixing some instabilities of the formatter: see bug 293300 which was fixed in 3.6M4.

See also an already identified similar issue fixed in 3.6M7: bug 305371
Comment 4 Frederic Fusier CLA 2010-05-20 13:03:06 EDT
Created attachment 169376 [details]
Proposed patch

It seems that the fix made for bug 305371 got a problem... I do not understand why the preference comment_format_line_comment_starting_on_first_column was used to see whether the comments indentations were similar or not!

Anyway, removing this unexpected reference makes the formatter working properly.
Comment 5 Frederic Fusier CLA 2010-05-20 13:06:35 EDT
(In reply to comment #4)
> Created an attachment (id=169376) [details]
> Proposed patch
> 
> It seems that the fix made for bug 305371 got a problem... I do not understand
> why the preference comment_format_line_comment_starting_on_first_column was
> used to see whether the comments indentations were similar or not!
> 
> Anyway, removing this unexpected reference makes the formatter working
> properly.

Note that this fix shows me another really better workaround...

Before unchecking the preference 'Enable line comment formatting', also uncheck the dependent reference 'Format line comments on first column'. Then the formatter will behave correctly :-)
Comment 6 Olivier Thomann CLA 2010-05-20 13:29:33 EDT
Daniel,

Since the patch is so simple and it does fix the issue, I think this could be a good candidate for RC3. Formatting issues are painful as we learnt it the hard way for RC2.
So +1 for RC3?
Comment 7 Dani Megert CLA 2010-05-21 08:27:27 EDT
+1 for RC3.
Comment 8 Frederic Fusier CLA 2010-05-25 08:30:43 EDT
Olivier, Srikanth, please review, thanks
Comment 9 Frederic Fusier CLA 2010-05-26 08:02:23 EDT
Srikanth will be off next two days, hence Jay, could you review the proposed patch?
TIA
Comment 10 Olivier Thomann CLA 2010-05-26 09:47:30 EDT
+1
Comment 11 Olivier Thomann CLA 2010-05-26 10:13:48 EDT
A small problem has been discovered with this fix running the massive tests.
Differing to 3.6.1 to give more time to stabilize it.
Comment 12 Frederic Fusier CLA 2010-06-24 03:43:11 EDT
Created attachment 172574 [details]
New proposed patch

This new patch does not have any side effect while running the formatter massive tests.
Comment 13 Frederic Fusier CLA 2010-06-24 04:44:51 EDT
(In reply to comment #12)
> Created an attachment (id=172574) [details]
> New proposed patch
> 
Released for 3.6.1 in R3_6_maintenance stream.
Released for 3.7M1 in HEAD stream.
Comment 14 Jay Arthanareeswaran CLA 2010-08-27 01:41:22 EDT
Verified for 3.6.1 RC2 using build M20100825-0800.