Java 是否为方法链接配置checkstyle?

Java 是否为方法链接配置checkstyle?,java,maven,checkstyle,Java,Maven,Checkstyle,我们的项目包含许多方法链接fluent样式的语句: int totalCount = ((Number) em .createQuery("select count(up) from UserPermission up where " + "up.database.id = :dbId and " + "up.user.id <> :currentUserId ") .setParameter("

我们的项目包含许多方法链接fluent样式的语句:

    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();
inttotalcount=((数字)em
.createQuery(“从UserPermission向上选择count(向上)where”+
“up.database.id=:dbId和”+
“up.user.id:currentUserId”)
.setParameter(“dbId”,cmd.getDatabaseId())
.setParameter(“currentUserId”,currentUser.getId())
.getSingleResult())
.intValue();
我已经将checkstyle大部分配置为与我们现有的代码样式相匹配,但现在它在这些代码段上失败了,而倾向于:

    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();
inttotalcount=((数字)em
.createQuery(“从UserPermission向上选择count(向上)where”+
“up.database.id=:dbId和”+
“up.user.id:currentUserId”)
.setParameter(“dbId”,cmd.getDatabaseId())
.setParameter(“currentUserId”,currentUser.getId())
.getSingleResult())
.intValue();

这是完全不合适的。是否要配置checkstyle以接受方法链接样式?我可以从maven运行另一个工具来强制执行这种缩进吗?

我在Eclipse中从来没有这样做过,所以我们很少使用格式源。最后,通常最好是扩展。我们努力了,但失败了。那是一年半以前。最后,我们只在Eclipse中使用格式化文本,方法是在手动格式化之前选择行或预格式化

通常,由工程师进行的格式化具有一定的意义。所以自动格式化永远不会起作用。特别是如果你做了类似的事情

publicstaticvoidmymethod(
int值、字符串值2、字符串值3)

如果您自动格式化此文件,它将失败,类似于您的示例


因此,在以人工方式格式化之前,请随意加入不使用自动格式化的俱乐部。

对于intellij,在“方法链调用”的情况下,可以通过选择“多行时对齐”来完成,因此我猜此属性在配置中配置错误

我建议将当前的checkstyle配置添加到问题中。而且我发现用第二种方式格式化它是相当合理的。我发现第一个版本很难阅读。@Martin第二种方式不适合用于消息链接,因为似乎您总是对新返回的对象执行某些操作,而所涉及的对象总是相同的。想象一下还有五种链式方法,每种新方法之前都有很多空白。在第一个版本中,很明显,每个新方法都从同一级别开始+1用于所需的配置。从现在起,我将投票否决任何不涉及checkstyle的答案。如果您从未加入行,这是Eclipse中的一个设置,则可以正常工作。虽然我不知道有一个方法链接。虽然这是一篇有趣的文章,但它似乎不是关于配置checkstyle的。