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

Bug 423949

Summary: [code formatting] if clause jumps into previous line in if statement followed by else
Product: [Eclipse Project] JDT Reporter: Palmer Eldritch <the.ubik>
Component: CoreAssignee: Mateusz Matela <mateusz.matela>
Status: VERIFIED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: markus.kell.r, mateusz.matela, Vikas.Chandra
Version: 4.3   
Target Milestone: 4.9 M2   
Hardware: All   
OS: All   
Whiteboard: To be verified for 4.9 M2
Attachments:
Description Flags
formatter profile none

Description Palmer Eldritch CLA 2013-12-12 13:34:37 EST
Created attachment 238298 [details]
formatter profile

Reproducer :

public class Snippet {

	public class Editor {

		public void apply() {}

		public void commit() {}
	}

	{
		final Editor ed = new Editor();
		int android_os_Build_VERSION_SDK_INT = 0;
		int Build_VERSION_CODES_GINGERBREAD = 0;
		if (android_os_Build_VERSION_SDK_INT >= Build_VERSION_CODES_GINGERBREAD)
			ed.apply();
		// else ed.commit();
	}
}

All fine.

Now uncomment // else ed.commit(); - select all - hit Ctrl+shift+F

get :

-		if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD)
-			ed.apply();
+		if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) ed
+			.apply();


Notice that GINGERBREAD) ends exactly at column 80 - maybe a fencepost error ? Have seen something similar - will try to dig it up

Related probably to my formatter profile requiring simple if statements to be on the same line
Comment 1 Palmer Eldritch CLA 2013-12-28 20:44:19 EST
Another example

	void instanceMethod(int intExtra) {
		String msg = null;
		int WifiManager_WIFI_STATE_DISABLING = 0;
		int WifiManager_WIFI_STATE_DISABLED = 0;
		if (intExtra == WifiManager_WIFI_STATE_DISABLING) msg = "Wireless disabling";
		else if (intExtra == WifiManager_WIFI_STATE_DISABLED)
			msg = "Wireless disabled";
	}

Notice else is just right
Comment 2 Mateusz Matela CLA 2018-07-18 17:16:46 EDT
This problem no longer occurs, probably after the formatter redesign.

*** This bug has been marked as a duplicate of bug 303519 ***
Comment 3 Vikas Chandra CLA 2018-08-01 09:43:59 EDT
verified
Version: 4.9
Build id: I20180731-1305