score:82

Accepted answer

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

score:-7

I usually do it by creating a code formatter by copying the built in eclipse formatter, here:

Windows > Preferences > Java > Code Style > Formatter 

Select the profile that you have just created. and click on Edit and go to "Braces" tab.

Change the braces placement as you like (it's a WYSIWYG kind of editor, makes it easy) .

When I need to format, I just select all the text and Ctrl+Shift+F and it works fine for me.

score:0

This is what I did: Eclipse -Preferences-Java-Code Style-Formatter-Edit-Braces Select next line as desired in each box then save as a different name (your choice).

score:8

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.

score:22

Yes.

Eclipse menu: Source -> Clean Up...

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


Related Query

More Query from same tag