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

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


Yes.

Eclipse menu: Source -> Clean Up...

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


In Eclipse Oxygen (2017+), that option is now at:

Window -> Preferences -> Java -> Code Style -> Clean Up -> Edit -> second tab "Code Style"

After changing, select the corresponding parts of your code and run the "Clean Up" option.