![](/img/trans.png)
[英]Wrapping chained method calls on a separate line in Intellij for Java
[英]Spring Java Format + IntelliJ + chain method call wrapping
我正在使用 IntelliJ 的 Spring Java Format 插件来标准化我的代码风格。 我也使用 Save Action Plugin 来格式化代码。 我正在尝试找到哪个规则使链方法调用被加入。
例如,如果我像这样格式化我的代码:
method()
.call1()
.call2()
.call3()
保存后,格式如下:
method().call1().call2()
.call3()
------------------------^ right margin limit
假设第三个方法调用转置右边距限制。
我想保留没有自动加入的包装版本。 有没有人遇到同样的问题?
编辑1:
我刚刚意识到编码是由mvn spring-javaformat:apply
连接在一起的。 所以问题与 IntelliJ Spring Java Format Plugin 无关。
我仍在尝试确定 Checkstyle 规则在做什么。
您看到的是 Spring Java Format 的默认代码样式。 虽然它“通常不可配置”,但有一个转义舱可以完全禁用格式化。 此处的文档中提到了此功能: 禁用代码块的格式设置。
对齐链式方法为此调用了一个理想的用例:
// @formatter:off
method()
.call1()
.call2()
.call3()
// @formatter:on
许多官方 Spring 项目也这样做。 例如:
@Bean
SecurityFilterChain configure(HttpSecurity http) throws Exception {
// @formatter:off
http.authorizeRequests()
.requestMatchers(EndpointRequest.to("health", "info")).permitAll()
.requestMatchers(EndpointRequest.toAnyEndpoint().excluding(MappingsEndpoint.class)).hasRole("ACTUATOR")
.antMatchers("/**").hasRole("USER")
.and()
.httpBasic();
return http.build();
// @formatter:on
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.