简体   繁体   English

如何配置 IntelliJ 的 Java 代码样式以便在长时间优先于链式方法调用时包装分配的右手

[英]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.我在根据自己的喜好配置 IntelliJ 的 Java 代码样式时遇到了问题。 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.当 class 名称和变量名称很长时,如果代码非常嵌套,则整个代码块会因我的喜好而向右移动太多。

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?有没有办法配置 Java 代码样式,以便当行太长时赋值的右手被换行到下一行,或者赋值规则优先于方法调用规则?

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有没有办法配置 Java 代码样式,以便当行太长时赋值的右手被换行到下一行

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 |使用 60 的“Hard Ctrl+Alt+L ”和您的代码示例,我能够使用File | Settings |设置 | Editor |编辑 | Code Style |代码风格 | Java > Wrapping and Braces : Java > 包装和大括号

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

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.但您始终可以在 YouTrack 上向 IntelliJ IDEA 开发人员提交新功能请求

暂无
暂无

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

相关问题 在Java中格式化代码时,Intellij仅包装链式方法[如果不少于3个] - Intellij only wrap chained methods [if no shorter than 3] when formatting code in Java IntelliJ IDEA 代码检查 - 外部使用 - 花了这么长时间 - IntelliJ IDEA code inspection - external usages of - taking so long intellij Idea中的Java代码格式化(链式方法调用) - Java code formatting in intellij Idea (chained method calls) 在调试流利的样式代码时,如何查找哪个链接方法失败? - When debugging fluent style code, how to find which chained method fails? 如何配置Gradle进行代码生成,以便IntelliJ识别生成的Java源代码? - How to configure Gradle for code generation so that IntelliJ recognises generated java source? 初始化 Spring 应用程序时如何确定哪种方法花费了这么长时间 - How to determine which method is taking so long when initializing a Spring application 如何将对Master的方法调用移交给n个Worker并返回? - How to hand over a method call on a Master to n Workers and return? Java中有没有办法交出HashSet <Class> 方法的参数,以便该方法将接受Class子类的HashSets? - Is there a way in Java to hand over HashSet<Class> arguments to a method so that the method will accept HashSets of subclasses of Class? 如何使用Mockito对链式方法调用进行单元测试 - How to unit test chained method call(s) using Mockito 在Java中更改线程的优先级需要多长时间? - How long does it take to change a thread's priority in Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM