Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing new lines before empty blocks in Eclipse

I prefer Allman-style braces, for example:

if (foo)
{
    // magical prancing unicorn stuff
}

rather than:

if (foo) {
    // unmagical boring pony things
}

The Java formatter in Eclipse handles this pretty well, except for empty code blocks, which it formats like this:

SomeDefaultCtor()
{}

I'd like to use this special format for empty blocks instead:

SomeDefaultCtor() {}

Is there any way to tell Eclipse to leave braces on the same line when the braces surround an empty code block? So far, I can't see one:

screenshot 1

screenshot 2

like image 883
Matt Ball Avatar asked May 03 '11 15:05

Matt Ball


1 Answers

As far as I can tell this is not (yet) possible in eclipse; you can specify when new lines should be inserted or not but the configuration on the braces takes priority. If you feel strongly about this and do not despise IDE annotations for this you could use:

@formatter:off
SomeDefaultCtor() {}
@formatter:on

These must be enabled in the eclipse formatter.

like image 197
Stijn Geukens Avatar answered Nov 14 '22 18:11

Stijn Geukens