Formatter mistakes one-line foreach loops for ongoing blocks [message #714161] |
Tue, 09 August 2011 23:45 |
rezecib 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 #714221 is a reply to message #714217] |
Wed, 10 August 2011 05:21 |
rezecib 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
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03408 seconds