Question

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?

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top