简体   繁体   中英

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.

I would like to find formatter which formats Java 8+ code like following:

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.

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).

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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