如何在 Eclipse 格式化程序中为二进制操作保留自定义缩进

How to keep custom indentation for binary operation in Eclipse formatter

我正在测试 eclipse 格式化程序,以尝试在 Java 中找到与我当前编码格式相匹配的内容。但是,我无法找到一个选项来保留字符串连接(二进制操作)的当前缩进。例如,如果我想写这个字符串(SQL查询):

// Current code, I want to keep this format
String query = "select "
            + "a, "
            + "b, "
            + "c, "
        + "from table "
        + "where "
            + "a = 1 "
            + "and b = 2 "
        + "order by c";

一切都将以相同的缩进换行(我选中了选项从不加入已经换行的行

// Formatted code
String query = "select "
        + "a, "
        + "b, "
        + "c, "
        + "from table "
        + "where "
        + "a = 1 "
        + "and b = 2 "
        + "order by c";

我觉得可读性较差。

我看到有一个选项可以关闭部分代码的格式化程序,但我想知道是否有一个内置选项可以满足我的需要。

从 Java 15 开始,“文本块”将是最易读的:

String query = """
    select
      a,
      b,
      c,
     from table
     where
      a = 1
      and b = 2
     order by c
     """.replace("\n", "");

产生:

select  a,  b,  c, from table where  a = 1  and b = 2 order by c

其中有一些额外的不重要的空白。