问题
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