Removing new lines before empty blocks in Eclipse

大兔子大兔子 提交于 2019-12-10 12:28:24

问题


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:


回答1:


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.




回答2:


You can also use AnyEdit plugin: http://andrei.gmxhome.de/anyedit/

It's a very flexible plugin which allows to set a variety of conversions and filters to better format your file.

Worth a look :-)



来源:https://stackoverflow.com/questions/5871670/removing-new-lines-before-empty-blocks-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!