user2249516
user2249516

Reputation: 281

Eclipse - Auto insert braces with different brace style

There is a feature in eclipse that you can enable to automatically insert curly brackets and semicolons into the right location. (More info in the top reply here)

Recently I started picking up the habit of adding the curly brace on the next line so that the braces end up lining up. I find that it makes the code nicer to look at. Is it possible to still use this auto positioning feature with curly braces, but instead of inserting the curly brace at the end, insert it on the next line like this:

for (int i = 0; i < 10; i++)
{

I have my eclipse formatter set to use this format, but unfortunately the auto position curly bracket doesn't appear to follow these rules. Anyone know how to fix this or a workaround without having to highlight all the code and format constantly?

Edit: I guess I wasn't really clear in my original post. I do have my formatter set to having braces on the next line, but eclipse's awesome insert at correct location feature doesn't seem to follow the formatters rules. I was trying to figure out if there was a way to solve this issue so that (like the link I posted above), typing a brace on the line will bring me to the next line instead of placing the brace at the end of the current line. Maybe eclipse has a macro plugin I can use for this?

Upvotes: 3

Views: 1401

Answers (2)

Christian Tapia
Christian Tapia

Reputation: 34146

Window > Preferences > Java > Code Style > Formatter > Select a profile > [Edit...] > Braces

There you can configure it.

Edit

Try this:

Window > Preferences > Java > Editor > Templates

Select the appropriate for > [Edit...]

Configure it as you want

Upvotes: 4

Infinite Recursion
Infinite Recursion

Reputation: 6557

From the Menu Bar, open Windows -> Preferences
Then in the options table select Java -> Code Style -> Formatter, then configure the braces in the sample code as you want.

Upvotes: 2

Related Questions