简体   繁体   中英

How to configure IntelliJ's Java Code Style so to wrap right hand of the assigment when long taking priority over chained method call

I've been having an issue to configure IntelliJ's Java code style to my liking. When I type some operation with streams I have something like this:

    VeryVeryVeryLongNamedClazz instance = container.getList()
                                                   .stream()
                                                   .filter(element -> element.getRole()
                                                                             .equals("CFG"))
                                                   .findFirst()
                                                   .get();

When class names and variable names are quite long, and if the code is quite nested, the whole code block gets shifted far too right to the right for my liking.

Something like this would be much more to my liking:

    VeryVeryVeryLongNamedClazz instance = 
            container.getList()
                     .stream()
                     .filter(element -> element.getRole()
                                               .equals("CFG"))
                     .findFirst()
                     .get();

Is there a way to configure the Java code style so that right hand of the assignment gets wrapped to the next line when the line is too long, or that the assignment rule takes priority over method call rule?

EDIT: To be more clear, what I'm looking for is that on wrapping, the assignment rule is done before chained method rule.

Is there a way to configure the Java code style so that right hand of the assignment gets wrapped to the next line when the line is too long

With 'Hard Wrap' at 60 and your code sample, I was able to achieve the desired result on hitting Ctrl+Alt+L using the following settings under File | Settings | Editor | Code Style | Java > Wrapping and Braces :

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

I would prefer that chained method calls are wrapped always only for streams, and that other methods are allowed to exist in the same line until end of line is reached

Don't think it's possible with current settings. But you can always submit a new feature request to the IntelliJ IDEA developers on YouTrack.

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