Bug 203699 - [clean up] remove unnecessary blocks is too aggressive
Summary: [clean up] remove unnecessary blocks is too aggressive
Status: RESOLVED DUPLICATE of bug 185669
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Benno Baumgartner CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-09-18 05:00 EDT by NoName CLA
Modified: 2007-09-18 05:21 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 NoName CLA 2007-09-18 05:00:51 EDT
Build ID: I20070809-1105

Steps To Reproduce:
1. Paste the code "Before" in a java file
2. Choose Source -> Clean up...
3. Create/Use a profile which only have:
   * Remove unnecessary blocks
4. Apply, you should get the code "After"


More information:
The clean up remove the else block but leave the if block. It make sense from an AST point of view, but not from a programmer-trying-to-have-clear-code point of view.

Before ====================================
public class ElseBlock {

	public int foo(boolean b1, boolean b2) {
		if (b1) {
			if (b2)
				return 0;
			else
				return 1;
		} else {
			if (b2)
				return -1;
			else
				return -2;
		}
	}
}

After ====================================
public class ElseBlock {

	public int foo(boolean b1, boolean b2) {
		if (b1) {
			if (b2)
				return 0;
			else
				return 1;
		} else if (b2)
			return -1;
		else
			return -2;
	}
}

I think the clean up is too aggressive. A difference should be made between "simple single statement" and "complex single statement".

Simple statement would be function call, assignement, etc.
Complex statement would be loops, if, switch...

It could be an option in the clean up dialog:
Use blocks in if/while/for/do statements
* Always
* No block for single 'return' or 'throw' statments (spell error ?)
* No block for single simple statements  (Added)
* No block for single statments (spell error?)

I hope you like the idea.
Comment 1 Benno Baumgartner CLA 2007-09-18 05:21:56 EDT

*** This bug has been marked as a duplicate of bug 185669 ***