简体   繁体   English

您知道将链接调用放在单独行中的 Java 8 格式化程序吗?

[英]Do you know Java 8 formatter which puts chained calls in separate lines?

Does someone know a good Java formatter which can automatically format Java code in a way that chained method calls are split in new lines.有人知道一个好的 Java 格式化程序,它可以自动格式化 Java 代码,以将链式方法调用拆分为新行。

I would like to find formatter which formats Java 8+ code like following:我想找到格式化 Java 8+ 代码的格式化程序,如下所示:

properties
    .getEndpoints()
    .stream()
    .map(UriTemplate::new)
    .collect(Collectors.toList());

Instead of this:取而代之的是:

properties.getEndpoints().stream().map(UriTemplate::new).collect(Collectors.toList());

I need to find formatter which can be run from command line because not all developers in the team are using the same IDE.我需要找到可以从命令行运行的格式化程序,因为并非团队中的所有开发人员都使用相同的 IDE。

I have already tried google java formatter and spring java formatter and they both format code in way I would like to avoid (chained method calls in same line).我已经尝试过 google java formatter 和 spring java formatter,它们都以我希望避免的方式格式化代码(在同一行中调用链式方法)。

Thank you!谢谢!

You generally have to tweak the defaults of any formatter (which is what you've found as well).您通常必须调整任何格式化程序的默认值(这也是您发现的)。

We looked into that five-six years ago and found that it was almost impossible to have IntelliJ and Eclipse behave exactly the same.我们在五六年前调查过这个问题,发现让 IntelliJ 和 Eclipse 表现得完全相同几乎是不可能的。 I would go for spending time on a suitable configuration for each (may take quite some time) and then require people to use that configuration.我会花时间为每个人选择合适的配置(可能需要相当长的时间),然后要求人们使用该配置。

I would advise against any automatic reformatting of sources, but you could consider checking if the sources were equivalent to their formatted versions as part of the quality measurement of the sources in your build engine.我建议不要对源进行任何自动重新格式化,但您可以考虑检查源是否与其格式化版本等效,作为构建引擎中源质量测量的一部分。

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

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