Bug 443447 - [save actions] Save actions: Automatic brace insertion/removal not enough options
Summary: [save actions] Save actions: Automatic brace insertion/removal not enough opt...
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-06 07:20 EDT by Mark Jeronimus CLA
Modified: 2014-10-03 09:55 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Jeronimus CLA 2014-09-06 07:20:11 EDT
In Window→Preferences→Java→Editor→Save Actions→Configure→Code Style→Control Statements→Use blocks in if/while/for/do statements

Actual behavior (for each of the three settings):

* "Always":
	for (int i = 0; i < 10; i++) {
		if (i < 5) {
			System.out.println(i);
		} else {
			System.out.println(i / 2);
		}
	}

	for (int i = 0; i < 10; i++) {
		if (i < 5) {
			System.out.println(i);
		}
	}

	for (int i = 0; i < 10; i++) {
		System.out.println(i);
	}


	for (int i = 0; i < 10; i++) {
		throw new RuntimeException();
	}

* "Always except on single 'return' or 'throws' statements":
	for (int i = 0; i < 10; i++) {
		if (i < 5) {
			System.out.println(i);
		} else {
			System.out.println(i / 2);
		}
	}

	for (int i = 0; i < 10; i++) {
		if (i < 5) {
			System.out.println(i);
		}
	}

	for (int i = 0; i < 10; i++) {
		System.out.println(i);
	}

	for (int i = 0; i < 10; i++)
		throw new RuntimeException();

* "Never":
	for (int i = 0; i < 10; i++)
		if (i < 5)
			System.out.println(i);
		else
			System.out.println(i / 2);

	for (int i = 0; i < 10; i++)
		if (i < 5)
			System.out.println(i);

	for (int i = 0; i < 10; i++)
		System.out.println(i);

	for (int i = 0; i < 10; i++)
		throw new RuntimeException();


Expected (missing) behavior:
* "Except on 'simple' statements":
	for (int i = 0; i < 10; i++) {
		if (i < 5) {
			System.out.println(i);
		} else {
			System.out.println(i / 2);
		}
	}

	for (int i = 0; i < 10; i++)
		if (i < 5)
			System.out.println(i);

	for (int i = 0; i < 10; i++)
		System.out.println(i);


	for (int i = 0; i < 10; i++)
		throw new RuntimeException();

I would either like this behavior as a fourth option or in stead of the middle option.

For lack of a better word, I call every single-line statements and statement that had it's braces removed because of this rule, a 'simple statement'. A better, but less user-friendly, term would be 'statement tree without any splits'.