Intellij 格式化程序链式方法调用
Intellij formatter chained method calls
如何强制 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");
转到文件 > 设置 > 编辑器 > 代码样式 > Java > 换行和大括号
将链式方法调用配置为始终包裹并标记多行时对齐:
如何强制 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");
转到文件 > 设置 > 编辑器 > 代码样式 > Java > 换行和大括号
将链式方法调用配置为始终包裹并标记多行时对齐: