如何使用eclipse的代码格式化程序在“case”之后删除新行? [英] How to use eclipse's code formatter to remove new lines after 'case'?

查看:155
本文介绍了如何使用eclipse的代码格式化程序在“case”之后删除新行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过eclipse Java格式化程序(Java / Code Style / Formatter),但是找不到一个方法,在 case 之后没有新的行。而不是

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

我想要

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

有没有办法,如果是这样做? p>

解决方案

我没有办法解决这个问题。没有办法按照预期折现现有代码



但是,您可以通过启用关闭/开启标签来避免编写此类切换语句,如下所述 Eclipse格式化程序允许多行; ,然后更改<$ c中的开关模板$ c> Windows>首选项> Java>编辑者>模板如下所述

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

默认值:break;
}
// @ formatter:on


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?

解决方案

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

这篇关于如何使用eclipse的代码格式化程序在“case”之后删除新行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆