tags:

views:

1109

answers:

3

Is there a quick way to make Eclipse put curly brace on the next line (by itself) on a block of code?

+5  A: 

Yes, edit your active profile (Java...Code Style...Formatter), and change the brace positions to the next line. Also, in Java..Editor..Typing, you can have it automatically insert your braces at the correct position.

Don Branson
I suppose I meant on a highlighted pre-written block of code to having the curly braces on the next line
srand
Gotcha. Yeah, the formatting suggested by the others should do the trick. I'm a ctrl-shift-f fan myself, but the menus have their place, too. ;)
Don Branson
+3  A: 

For pre-written block of code, first do the settings as suggested by Don and then select that piece of code and right click Source Code->Format and the formatting would take place as per the settings done in the preferences.

techzen
You can also use the keyboard shortcut for this, Ctrl+Shift+F, instead of the menus. When there is a selection it only formats the selection - without a selection it will format the whole file.
Joshua McKinnon
and you can add a save action that automatically formats the file on every save.
Michael Wiles
+1  A: 

In addition to the methods of changing the settings and ctrl-shift-f to apply, these settings can be done on a per project basis. Simply right-click on your project, choose properties, Java Code Style, and enable the checkbox for "enable project specific settings."

I find this invaluable for use between projects I work on to configure it to match a particular client style, along with other settings to try to match code formatting of existing code. This way, you won't upset other people but can still use your own style on other code bases. :)

lilbyrdie
Good tidbit, thanks! :)
srand