Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Formatter mistakes one-line foreach loops for ongoing blocks(thus, indentation gets messed up)
Formatter mistakes one-line foreach loops for ongoing blocks [message #714161] Tue, 09 August 2011 23:45 Go to next message
rezecib  is currently offline rezecib Friend
Messages: 6
Registered: August 2011
Junior Member
I noticed when shifting a method that contained nested foreach loops that it messed up the indentation. It compiles and runs normally, but it's clearly being recognized as an ongoing block by the formatter despite there not being any braces.

Examples:

If I use for loops, it formats correctly:
for(int r = 0; r < 9; r++)
	for(int c = 0; c < 9; c++)
		if(p[r][c] == 0)
			return false;
return true;


If I use foreach loops, it formats as if the statement afterwards were part of the last block:
for(int[] row : p)
	for(int el : row)
		if(el == 0)
			return false;
			return true;


Has anyone else encountered this, and if so, have you found a solution other than avoiding foreach loops entirely?

Background information that may/may not be of use:
I'm running Indigo, Version: 3.7.0 Build id: I20110613-1736
on Mac OS X 10.7 (Lion)

[Updated on: Tue, 09 August 2011 23:52]

Report message to a moderator

Re: Formatter mistakes one-line foreach loops for ongoing blocks [message #714217 is a reply to message #714161] Wed, 10 August 2011 04:33 Go to previous messageGo to next message
Satyam Kandula is currently offline Satyam KandulaFriend
Messages: 444
Registered: July 2009
Senior Member
Have you modified any formatter options? I am unable to reproduce with the default options.
Re: Formatter mistakes one-line foreach loops for ongoing blocks [message #714221 is a reply to message #714217] Wed, 10 August 2011 05:21 Go to previous messageGo to next message
rezecib  is currently offline rezecib Friend
Messages: 6
Registered: August 2011
Junior Member
I've tried it with all of the built-in formatters (Java Conventions [built-in], Eclipse [built-in], and Eclipse 2.1 [built-in]), as well as a custom one based on "Eclipse [built-in]".

I just replicated it by making a new file, contents following:

public class Bork
{
	public static void method()
	{
		int sum = 0;
		int[][] grid = new int[9][9];
		
		for(int r = 0; r < 9; r++)
			for(int c = 0; c < 9; c++)
				sum++;
		sum = 0;
		
		for(int[] row : grid)
			for(int el : row)
				sum++;
					sum = 0;
	}
}


However, it seems with the Java formatter that it sticks with the indentation of the previous line, while the other ones seem to be indenting further...

[Updated on: Wed, 10 August 2011 05:25]

Report message to a moderator

Re: Formatter mistakes one-line foreach loops for ongoing blocks [message #714223 is a reply to message #714221] Wed, 10 August 2011 05:40 Go to previous messageGo to next message
Satyam Kandula is currently offline Satyam KandulaFriend
Messages: 444
Registered: July 2009
Senior Member
I see that the formatter works fine but the indenter fails here. Formatter is kicked in when you do a Ctrl+Shift+F. Indenter is kicked in when you press enter in the editor. Please file a bug.
Re: Formatter mistakes one-line foreach loops for ongoing blocks [message #714230 is a reply to message #714223] Wed, 10 August 2011 05:55 Go to previous messageGo to next message
rezecib  is currently offline rezecib Friend
Messages: 6
Registered: August 2011
Junior Member
It doesn't get fixed when I use the ctrl+I command to fix indentation, so I guess that's also handled by the indenter and not the formatter. I didn't realize they were distinct, as indentation options are under the formatter options...
Anyway, the bug has been filed. Thanks for the help.
Re: Formatter mistakes one-line foreach loops for ongoing blocks [message #714289 is a reply to message #714230] Wed, 10 August 2011 08:36 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
On 10.08.2011 07:55, rezecib wrote:
> It doesn't get fixed when I use the ctrl+I command to fix indentation,
> so I guess that's also handled by the indenter and not the formatter.
> I didn't realize they were distinct, as indentation options are under
> the formatter options...
> Anyway, the bug has been filed. Thanks for the help.
FYI: This has already been fixed in 3.8 M1 and 3.7 maintenance.

Dani
Re: Formatter mistakes one-line foreach loops for ongoing blocks [message #714436 is a reply to message #714289] Wed, 10 August 2011 14:13 Go to previous message
rezecib  is currently offline rezecib Friend
Messages: 6
Registered: August 2011
Junior Member
Augh, I'm sorry for the duplicate bug. I tried searching for it but didn't find it...

Thanks for the swift reply, though!
Previous Topic:Sudo Execution inside Eclipse
Next Topic:(no subject)
Goto Forum:
  


Current Time: Thu Apr 25 07:41:33 GMT 2024

Powered by FUDForum. Page generated in 0.03408 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top