简体   繁体   English

Intellij 2022.2.3:缩进 Java Lambok 和 Stream 代码

[英]Intellij 2022.2.3 : Indent Java Lambok and Stream Code

    TestDTO.builder().date(Date.from(Instant.now())).productName("product " + i).total(new BigDecimal(i)).purchaseType(1).sourceAppId("sourceAppId" + i).numberOfLicense(i).build();
List.of("a", "bb", "cccc").stream().filter(Objects::nonNull).filter(s -> s.length() > 1).collect(Collectors.toList());

Above is my Java in which am trying to indent it to have each method in a new line as below, I'm wondering if this is doable with IntelliJ Java code format config changes or not?上面是我的 Java,其中我试图缩进它以将每个方法都放在一个新行中,如下所示,我想知道这是否适用于 IntelliJ Java 代码格式配置更改或不更改? I tried ctrl+shift+L and its not doing what I expected我试过 ctrl+shift+L 但它没有按照我的预期进行

TestDTO.builder()
          .date(Date.from(Instant.now()))
          .productName("product " + i)
          .total(new BigDecimal(i)).purchaseType(1)
          .sourceAppId("sourceAppId" + i)
          .numberOfLicense(i)
          .build();
List.of("a", "bb", "cccc").stream()
            .filter(Objects::nonNull)
            .filter(s -> s.length() > 1)
            .collect(Collectors.toList());

From the comments: You can setup this behaviour in the IntelliJ-settings.来自评论:您可以在 IntelliJ 设置中设置此行为。
It is under Preferences | Editor | Code Style | Java它在Preferences | Editor | Code Style | Java Preferences | Editor | Code Style | Java Preferences | Editor | Code Style | Java in the tab Wrapping and braces and it is called Chained method calls . Preferences | Editor | Code Style | JavaWrapping and braces选项卡中,它被称为Chained method calls

But be aware: Sometimes you might dislike this.但请注意:有时您可能不喜欢这个。 In your example, you want that List.of("a", "bb", "cccc").stream() is in one line.在您的示例中,您希望List.of("a", "bb", "cccc").stream()位于一行中。 But it is a chained method call and IntelliJ do this:但它是一个链式方法调用,IntelliJ 这样做:

List.of("a", "bb", "cccc")
    .stream()
    .filter(Objects::nonNull)
    .filter(s -> s.length() > 1)
    .collect(Collectors.toList());

If want you that setting, then it is properly a good idea to put it into a EditorConfig .如果你想要那个设置,那么将它放入EditorConfig中是个好主意。

.editorconfig .editorconfig

[*.java]
ij_java_method_call_chain_wrap = always

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM