java - Intellij 格式化程序链式方法调用

标签 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");

最佳答案

转到"file">“设置”>“编辑器”>“代码样式”>“Java”>“环绕和大括号”

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

enter image description here

关于java - Intellij 格式化程序链式方法调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33679768/

相关文章:

intellij-idea - IntelliJ IDEA 平面包 View

java - 包 redis.embedded 不存在

java - 使用不同的语言级别进行测试和生产

java - 发送 HL7 消息后何时关闭并重新打开套接字

java - 实例差异

javascript - Visual Studio Code 在多行上对齐函数参数

c++ - 在 "if"语句中格式化条件检查的最佳方法

Intellij-IDEA:如何按字母顺序对成员进行排序?

java - 以特定格式将数据存储在txt文件中

java - AspectJ 使用 around 建议和 ProceedingJoinPoint 时遇到问题