Intellij formatter链式方法调用

时间:2015-11-12 19:33:41

标签: java intellij-idea code-formatting auto-indent

如何强制IntellJ代码格式化程序在不同级别上自动包含的参数列表,而不是包装的链式方法调用:

编辑:有关更好的问题说明,请参阅更新的示例。如果我将每个连续方法调用包装到新行,则默认格式化程序按预期工作。只有当我想在每行留下一个或多个点时才会出现问题:

包装:

new Something()
    .chained("arg1", "arg2", "very long arg I want to see in new line")
    .chained("arg1", "arg2", "very long arg I want to see in new line")
    .extra().chained("arg1", "arg2", "very long arg I want to see in new line")
    .extra().chained("arg1", "arg2", "very long arg I want to see in new line");

我希望这样的事情:

new Something()
    .chained("arg1", "arg2", 
        "very long arg I want to see in new line")
    .chained("arg1", "arg2", 
        "very long arg I want to see in new line")
    .extra().chained("arg1", "arg2", 
        "very long arg I want to see in new line")
    .extra().chained("arg1", "arg2", 
        "very long arg I want to see in new line");

但结果是:

new Something()
    .chained("arg1", "arg2", 
        "very long arg I want to see in new line")
    .chained("arg1", "arg2", 
        "very long arg I want to see in new line")
    .extra().chained("arg1", "arg2", 
    "very long arg I want to see in new line")
    .extra().chained("arg1", "arg2", 
    "very long arg I want to see in new line");

1 个答案:

答案 0 :(得分:2)

转到文件>设置>编辑器>代码样式> Java>包装和花括号

链式方法调用配置为总是换行,并标记多行时对齐

enter image description here