Bromide Bromide - 1 year ago 54
Java Question

How to make eclipse automatically add braces to an IF statement?

In Java the following is completely valid:

if (x == null)

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

if (x == null) {
} else {

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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download