7

我们的项目在方法链流式风格中包含许多语句:

    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 主要配置为匹配我们现有的代码样式,但现在它在这些片段上失败了,而是更喜欢:

    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 运行的替代工具来强制执行这种缩进?

4

2 回答 2

-2

我从来没有在 Eclipse 中完成这项工作,所以我们几乎不使用 Format Source。最后,通常最好延长。我们很努力,但失败了。那是一年半前的事了。最后,我们仅在 Eclipse 中通过选择行或在手动格式化之前预格式化来使用格式化文本。

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

public static void myMethod( int value, String value2, String value3)

如果您自动格式化它,它会与您的示例类似地失败。

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

于 2015-02-23T20:54:06.470 回答
-4

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

于 2015-02-24T15:05:05.730 回答