Bug 52283 - do <single-statement> while(<condition>) is ill-formatted
Summary: do <single-statement> while(<condition>) is ill-formatted
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 M2   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-02-17 14:29 EST by Rafael Chaves CLA
Modified: 2005-09-20 12:41 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rafael Chaves CLA 2004-02-17 14:29:51 EST
3.0 M7

A do-while controling a single statement (no braces) is not properly formatted
(the "while" part ends up in the same line as the controled statement):

class Foo {
	void m1() {
		int x;
		do
			x = 1; while (true);
	}
}
Comment 1 Olivier Thomann CLA 2004-02-17 22:44:17 EST
Should be easy to fix.
Comment 2 Olivier Thomann CLA 2004-02-23 13:34:45 EST
Fixed and released in HEAD.
Regression test added.
Comment 3 Frederic Fusier CLA 2004-03-25 08:02:44 EST
Verified for 3.0 using build I200403250010.
Comment 4 Olivier Thomann CLA 2005-09-09 17:33:56 EDT
In fact the fix was wrong.
If the option to insert a new line before the while is off, then the formatting
was ok.
Comment 5 Olivier Thomann CLA 2005-09-11 20:18:07 EDT
However we can decide that when there is only one statement that is not a block,
the while should be on a new line.
Comment 6 Olivier Thomann CLA 2005-09-12 12:15:17 EDT
When only one statement is the do statement action and this statement is not a
block, the most natural formatting is:
class Foo {
	void m1() {
		int x;
		do
			x = 1;
		while (true);
	}
}

This is also do for a try statement.
Fixed and resolved in HEAD.
Updated org.eclipse.jdt.core.tests.formatter.FormatterRegressionTests.test119.
Change in
org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.visit(DoStatement,BlockScope)
Comment 7 David Audel CLA 2005-09-20 12:41:45 EDT
Verified in I20050920-0010 for 3.2M2