Brian Deacon
Brian Deacon

Reputation: 21962

An autoformat tool to automatically insert braces around single-line clauses?

So assuming that in our work environment we've decided that the One True Faith forbids this:

if (something) 
    doSomething();

And instead we want:

if (something) {
    doSomething();
}

Is there a tool that will do that automagically? Awesomest would be to have eclipse just do it, but since we're really just recovering from one ex-employee that thought he was too pretty for coding conventions, a less-friendly tool that would do it right just once would suffice.

Upvotes: 2

Views: 2360

Answers (3)

Andrew Coleson
Andrew Coleson

Reputation: 10320

I think you can set this in Eclipse's formatting rules and run the built-in formatter.. e.g. the "Use blocks" option:

Code Style Tab
(source: ibm.com)

Of course, you need the rest of the formatting options to be set how you want them, since I don't think you can selectively apply only a single rule/option..

Upvotes: 3

Luciano
Luciano

Reputation: 1601

I believe that GreatCode can do this for you (along with a ton of other options)

Upvotes: 0

Brian Deacon
Brian Deacon

Reputation: 21962

Ah, it's actually not a formatter, but a "Clean Up": Preferences -> Java -> Code Style -> Clean Up

And then to execute. Source -> Clean Up As opposed to Source -> Format

Upvotes: 3

Related Questions