如何为Java多行换行配置IntelliJ代码格式?

时间:2019-03-21 09:32:45

标签: intellij-idea configuration code-formatting

我正在寻找一种配置Java的IntelliJ Ulitmate代码格式化程序的方法。我正在寻找一种在多捕获语句中处理的异常列表之间强制换行的选项,例如这样

} catch(IOException | IllegalArgumentException ex) {
    ...
}

验证失败,并且

} catch(IOException
        | IllegalArgumentException ex) {
    ...
}

通过。

属性中的

enter image description here enter image description here

和示例代码

/*
 * This is a sample file.
 */

public class ThisIsASampleClass
        extends C1
        implements I1, I2, I3, I4,
        I5 {

    private int f1 = 1;

    private String field2 = "";

    public void foo1(int i1, int i2,
            int i3, int i4, int i5,
            int i6, int i7) {
    }

    public static void longerMethod()
            throws Exception1,
            Exception2, Exception3 {
        // todo something
        int i = 0;
        int[] a = new int[] { 1, 2,
                0x0052, 0x0053,
                0x0054 };
        int[] empty = new int[] {};
        int var1 = 1;
        int var2 = 2;
        foo1(0x0051, 0x0052, 0x0053,
                0x0054, 0x0055,
                0x0056, 0x0057);
        int x = (3 + 4 + 5 + 6) * (7
                + 8 + 9 + 10) * (11
                + 12 + 13 + 14
                + 0xFFFFFFFF);
        String s1, s2, s3;
        s1 = s2 = s3 =
                "012345678901456";
        assert i + j + k + l + n + m
                <= 2 : "assert description";
        int y = 2 > 3 ? 7 + 8 + 9 :
                11 + 12 + 13;
        super.getFoo()
                .foo()
                .getBar()
                .bar();

        label:
        if (2 < 3) {
            return;
        } else if (2 > 3) {
            return;
        } else {
            return;
        }
        for (int i = 0;
             i < 0xFFFFFF; i += 2) {
            System.out.println(i);
        }
        while (x < 50000) {
            x++;
        }
        do {
            x++;
        } while (x < 10000);
        switch (a) {
            case 0:
                doCase0();
                break;
            default:
                doDefault();
        }
        try (MyResource r1 = getResource();
                MyResource r2 = null) {
            doSomething();
        } catch (Exception e) {
            processException(e);
        } finally {
            processFinally();
        }
        do {
            x--;
        } while (x > 10);
        try (MyResource r1 = getResource();
                MyResource r2 = null) {
            doSomething();
        }
        Runnable r = () -> {
        };
    }

    public static void test()
            throws Exception {
        foo.foo()
                .bar("arg1", "arg2");
        new Object() {

        };
    }

    class TestInnerClass {

    }

    interface TestInnerInterface {

    }
}

enum Breed {
    Dalmatian(),
    Labrador(),
    Dachshund()
}

@Annotation1
@Annotation2
@Annotation3(param1 = "value1", param2 = "value2")
@Annotation4
class Foo {

    @Annotation1
    @Annotation3(param1 = "value1", param2 = "value2")
    public static void foo() {
    }

    @Annotation1
    @Annotation3(param1 = "value1", param2 = "value2")
    public static int myFoo;

    public void method(@Annotation1
    @Annotation3(param1 = "value1", param2 = "value2")
    final int param) {
        @Annotation1
        @Annotation3(param1 = "value1", param2 = "value2")
        final int localVariable;
    }
}

我什至看不到该功能的意识。格式化程序是否还有第二种隐藏的配置?

我正在Ubuntu 18.10上使用IntelliJ IDEA 2018.3.5(Ultimate Edition)。

1 个答案:

答案 0 :(得分:2)

当前不可能。随时为YouTrack上的相关请求投票:https://youtrack.jetbrains.com/issue/IDEA-178941