google-java-format icon indicating copy to clipboard operation
google-java-format copied to clipboard

Text blocks should be indented

Open anthonyvdotbe opened this issue 5 years ago • 0 comments

To reproduce:

  • build 2ddcfd392cc5e45eaa5fb30c723b7e024f5caabb with mvn clean verify
  • create Foo.java in core\target, containing 2 identical strings:
class Foo {

    private static final String FMT_B = "........ .. . ........ .. ....     . .... . .. .          ...................\n" +
".. . .. . . .. .. . ......... . .. . .. .. . .. . . .. . . .. ........ ......\n" +
".. . .. . . .. .. . ......... . .. . ........ ....... .. .. . . . .. . ......\n" +
".............. ..... .. . . .. . . . .. . . . . . .. . . . . .. . . .. .. . .\n";

    private static final String FMT_C = """
........ .. . ........ .. ....     . .... . .. .          ...................
.. . .. . . .. .. . ......... . .. . .. .. . .. . . .. . . .. ........ ......
.. . .. . . .. .. . ......... . .. . ........ ....... .. .. . . . .. . ......
.............. ..... .. . . .. . . . .. . . . . . .. . . . . .. . . .. .. . .
""";

}
  • in core\target, run java -jar google-java-format-1.9-SNAPSHOT-all-deps.jar Foo.java
  • I'd expect 2 things here:
    • the text block is indented the same as the multi-line string
    • the opening """ is on the same line as the declaration

Expected output:

class Foo {

  private static final String FMT_B =
      "........ .. . ........ .. ....     . .... . .. .          ...................\n"
          + ".. . .. . . .. .. . ......... . .. . .. .. . .. . . .. . . .. ........ ......\n"
          + ".. . .. . . .. .. . ......... . .. . ........ ....... .. .. . . . .. . ......\n"
          + ".............. ..... .. . . .. . . . .. . . . . . .. . . . . .. . . .. .. . .\n";

  private static final String FMT_C = """
      ........ .. . ........ .. ....     . .... . .. .          ...................
      .. . .. . . .. .. . ......... . .. . .. .. . .. . . .. . . .. ........ ......
      .. . .. . . .. .. . ......... . .. . ........ ....... .. .. . . . .. . ......
      .............. ..... .. . . .. . . . .. . . . . . .. . . . . .. . . .. .. . .
      """;
}

Actual output:

class Foo {

  private static final String FMT_B =
      "........ .. . ........ .. ....     . .... . .. .          ...................\n"
          + ".. . .. . . .. .. . ......... . .. . .. .. . .. . . .. . . .. ........ ......\n"
          + ".. . .. . . .. .. . ......... . .. . ........ ....... .. .. . . . .. . ......\n"
          + ".............. ..... .. . . .. . . . .. . . . . . .. . . . . .. . . .. .. . .\n";

  private static final String FMT_C =
      """
........ .. . ........ .. ....     . .... . .. .          ...................
.. . .. . . .. .. . ......... . .. . .. .. . .. . . .. . . .. ........ ......
.. . .. . . .. .. . ......... . .. . ........ ....... .. .. . . . .. . ......
.............. ..... .. . . .. . . . .. . . . . . .. . . . . .. . . .. .. . .
""";
}

anthonyvdotbe avatar Jun 01 '20 05:06 anthonyvdotbe