views:

75

answers:

2

In Java the following is completely valid:

if (x == null)
    Y();
else
    Z();

I personally don't like it at all. I like all my IF statements to have braces:

if (x == null) {
    Y();
} else {
    Z();
}

The eclipse formatter is wonderful and can beautify my code in many other ways. Is there a way to have it add the braces to IF statements?

+3  A: 

Under "Preferences": Java > Editor > Save Actions

1) Check "Additional actions"

2) Click "Configure…"

3) Go to the "Code Style" tab

4) Check "Use blocks in if/while/for/do statements" and configure to your preferences

gk5885
Perfect! I knew there had to be a way :-)
Bromide
+2  A: 

Yes.

Eclipse menu: Source -> Clean Up...

Configure... -> Code Style -> Use blocks in if/while/for/do statements.

ChrisH