如何使用eclipse的代码格式化程序在“case”之后删除新行? [英] How to use eclipse's code formatter to remove new lines after 'case'?
问题描述
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屋!