How do I configure autoformatting in Eclipse?
Asked Answered
S

1

15

I dislike how auto format messes up empty cycle body, like:

Before

for (int i = 0; isTest(i); i++); 

After

for (int i = 0; isTest(i); i++)
    ;

How to configure eclipse not to do this?

Sociability answered 8/9, 2009 at 8:38 Comment(5)
Just out of curiosity, why on earth would you want a loop that does nothing?Karelia
That loop might do something. The isTest method can have almost any side effect ;)Pique
Urgh. Then it should be a while loop so the "isTest(i)" is in the body. In my opinion "for" loops should only contain iteration steps between the parenthesis.Bort
I suggest a custom compiler warning rather than a custom formatting for this special case :-PMagree
@Thorbjørn: I agree, I'm just saying it's possiblePique
S
26

Go to Windows -> Preferences, and in the options table select Java -> Code Style -> Formatter, then configure to your hearts content.

For future reference, in the Preferences menu you can just type in a search term to find all options for that term - so just going onto the Preferences menu and typing "format" will show you all options

Seabury answered 8/9, 2009 at 8:53 Comment(2)
& "new lines" -> "empty statements" uncheck "Put empty statements on new line"Sociability
This is in the current workspace, not in the Eclipse installation, hence you need to export and import your preferences to have this available in other workspaces.Bort

© 2022 - 2024 — McMap. All rights reserved.