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

Bug 407250

Summary: [cleanup] add braces in a statement followed by a comment - wrong formatting
Product: [Eclipse Project] JDT Reporter: Oliver Kopp <oliver.kopp>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: minor    
Priority: P3 CC: mateusz.matela, oliver.kopp
Version: 4.2.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows 8   
Whiteboard: stalebug

Description Oliver Kopp CLA 2013-05-06 03:15:39 EDT
The @formatter:off setting is now always honored correctly

Example:
	public static void test() {
		// @formatter:off
		if ("".equals("")) { return; }
		if (1==1) return;
		// @formatter:on
	}

leads to

	public static void test() {
		// @formatter:off
		if ("".equals("")) { return; }
		if (1==1)
		 {
			return;
			// @formatter:on
		}
	}

While enabling the formatter leads to

	public static void test() {
		// @formatter:on
		if ("".equals("")) {
			return;
		}
		if (1 == 1) {
			return;
			// @formatter:on
		}
	}

Note the correctly placed braces.
I assume that the wrong placement of "// @formatter:on" cannot be fixed, can it?
Comment 1 Eclipse Genie CLA 2019-09-27 16:37:39 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 2 Mateusz Matela CLA 2019-09-28 17:06:24 EDT
The formatter is not responsible for adding braces, it must be a cleanup action. The effect in code is the same whether the off/on tags are enabled or not (that is until you invoke the formatter directly).

What is your expected behavior? Do you want to keep the if-return without braces even though the cleanup profile (or save action) uses the "Convert control statement bodies to block" setting? I guess we'd need to add something like //cleanup:off tags in addition to //formatter:off
Comment 3 Oliver Kopp CLA 2019-09-29 23:19:33 EDT
No need for cleanup:on/off for me.

I just expect following result:

	public static void test() {
		// @formatter:on
		if ("".equals("")) {
			return;
		}
		if (1 == 1) {
			return;
		}
                // @formatter:on
	}

Meaning: If pairs @formatter:on/off were aligned in the same column, the alignment should be kept. 

Simple heuristics: If the column of one tag changed, the former column of @formatter:on takes priority.