Bug 481143 - [formatter][parser] Parser missing some line comments
Summary: [formatter][parser] Parser missing some line comments
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.4   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: 4.5.2   Edit
Assignee: Mateusz Matela CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-30 15:07 EDT by James Styles CLA
Modified: 2016-01-18 11:18 EST (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 James Styles CLA 2015-10-30 15:07:59 EDT
As of 4.5.1 using any of the built-in formatter profiles, the formatter is capable of joining two lines even if the first line ends in a single-line comment.

Example
Before auto-formatting

public class AutoFormatTest {
	public AutoFormatTest subtest = new AutoFormatTest("Test1", // comment
			"Test2"){
		
	};

	public AutoFormatTest(String foo, String bar) {

	}
}

After auto-formatting

public class AutoFormatTest {
public class AutoFormatTest {
	public AutoFormatTest subtest = new AutoFormatTest("Test1", // comment"Test2") {

	};

	public AutoFormatTest(String foo, String bar) {

	}
}

This only seems to occur when the second line contains the opening brace to an anonymous class.
Comment 1 Mateusz Matela CLA 2015-11-01 15:31:16 EST
This is because the formatter doesn't get information about the comment from the parser. I can see in the ASTView that the comments list is empty with given code.

Another example I bumped into:
public enum Enum impelements //comment
Runnable {

}
The //comment doesn't show up in ASTView and the formatter joins this line.

I see this problem in 4.4 too, although it doesn't affect the formatter there.
Comment 2 Eclipse Genie CLA 2015-11-01 16:49:03 EST
New Gerrit change created: https://git.eclipse.org/r/59447
Comment 4 Manoj N Palat CLA 2015-12-17 03:54:22 EST
(In reply to Eclipse Genie from comment #3)
> Gerrit change https://git.eclipse.org/r/59447 was merged to [master].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/
> ?id=64a9849f02ddb4edcc4fd1f600d032fb0cfb2765

Thanks Mateusz. Please backport this to 4.5.2 as well
Comment 6 Mateusz Matela CLA 2015-12-17 16:34:51 EST
Somehow patch 3 in https://git.eclipse.org/r/#/c/59447 which got merged to master does not contain the copyright notice year update, even though it was there in patch 2.
The backport commit was a cherrypick of that, so it also doesn't update the year.

Manoj, did you do it intentionally? If not, is it important enough to fix it with subsequent commits?
Comment 7 Jay Arthanareeswaran CLA 2016-01-18 11:15:42 EST
(In reply to Mateusz Matela from comment #6)
> Manoj, did you do it intentionally? If not, is it important enough to fix it
> with subsequent commits?

I think its an oversight or an error arose out of merge conflicts. During the later milestones, we look for missing ones and update the copyrights that should include candidates like this.
Comment 8 Jay Arthanareeswaran CLA 2016-01-18 11:18:50 EST
Verified for 4.5.2 with build M20160113-1000.

and 

Verified for 4.6 M5 with build I20160112-1800.