【发布时间】:2013-02-03 02:12:06
【问题描述】:
我们的项目中包含了很多方法链流式风格的语句:
int totalCount = ((Number) em
.createQuery("select count(up) from UserPermission up where " +
"up.database.id = :dbId and " +
"up.user.id <> :currentUserId ")
.setParameter("dbId", cmd.getDatabaseId())
.setParameter("currentUserId", currentUser.getId())
.getSingleResult())
.intValue();
我的 checkstyle 主要配置为与我们现有的代码样式相匹配,但现在它在这些 sn-ps 上失败了,而是更喜欢:
int totalCount = ((Number) em
.createQuery("select count(up) from UserPermission up where " +
"up.database.id = :dbId and " +
"up.user.id <> :currentUserId ")
.setParameter("dbId", cmd.getDatabaseId())
.setParameter("currentUserId", currentUser.getId())
.getSingleResult())
.intValue();
这完全不合适。无论如何配置 checkstyle 以接受方法链接样式?有没有我可以从 maven 运行的替代工具来强制执行这种缩进?
【问题讨论】:
-
我建议将当前的 checkstyle 配置添加到问题中。
-
另外,我发现以第二种方式格式化它是非常合理的。我发现第一个版本很难阅读。
-
@Martin 第二种方式对于消息链来说是不受欢迎的,因为看起来你总是在新返回的对象上做一些事情,而有问题的对象总是相同的。想象一下另外五个链接的方法,并且在每个新方法之前都有很多空白。在第一个版本中,很明显每个新方法都从同一级别开始。 +1 所需的配置。
-
从现在开始,我将否决任何不涉及 checkstyle 的答案。
标签: java maven checkstyle