How to use eclipse's code formatter to remove new lines after 'case'?

喜夏-厌秋 提交于 2019-12-12 18:41:20

问题


I looked in the eclipse Java formatter (Java / Code Style / Formatter) but could not find a way to not have a new line after case. Instead of

switch (a) {
    case 0:
        Other.doFoo();
        break;
    case 1:
        Other.doBaz();
}

I want

switch (a) {
    case 0: Other.doFoo();
            break;
    case 1: Other.doBaz();
}

Is there a way to do it and if so what is it?


回答1:


I found no way to resolve this. There is no way of refractoring existing code as you expected.

But you can avoid writing such switch statement now onwards by enabling off/on tags as explained here Eclipse Formatter Allow Multi Line ; and then changing the switch template in Windows > Preferences > Java > Editors > Templates as mentioned below

    //@formatter:off
        switch (${key}) {
            case ${value}:${cursor}
                          break;

            default:break;
        }
    //@formatter:on


来源:https://stackoverflow.com/questions/23277340/how-to-use-eclipses-code-formatter-to-remove-new-lines-after-case

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