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

Inconsistency between indent level in AOSP and non-aosp

Open blacksails opened this issue 1 year ago • 2 comments

I am not entirely sure wether this is the intended behavior, so here is an issue. The the continuation of the long string doesn't indent with 8 spaces from the previous line which I would expect in AOSP.

Test.java

public class Test {
    String s = "asdfasdfasdfasdf asdfasdfasdfasdfasdfasdffasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasd";
}
❯ java -jar ~/Downloads/google-java-format-1.24.0-all-deps.jar Test.java
public class Test {
  String s =
      "asdfasdfasdfasdf"
          + " asdfasdfasdfasdfasdfasdffasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasd";
}
❯ java -jar ~/Downloads/google-java-format-1.24.0-all-deps.jar --aosp Test.java
public class Test {
    String s =
            "asdfasdfasdfasdf"
                + " asdfasdfasdfasdfasdfasdffasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasd";
}

I would expect the following output using AOSP style

public class Test {
    String s =
            "asdfasdfasdfasdf"
                    + " asdfasdfasdfasdfasdfasdffasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasd";
}

I raised this issue in the spotless repo because I figured that spotless not indenting the same way as GJF would be a spotless bug.

If this is the intended behavior, please let me know, so that I can reraise the issue at spotless.

blacksails avatar Nov 18 '24 11:11 blacksails

Spotless issue for reference: https://github.com/diffplug/spotless/issues/2338

blacksails avatar Nov 18 '24 11:11 blacksails

Thanks for the report. The wrapping of long string literals is handled as a separate pass (--skip-reflowing-long-strings), and I think it's making non-AOSP assumptions instead of passing in the configuration.

I haven't double-checked if this is the exact culprit, but this comment looks suspicious:

https://github.com/google/google-java-format/blob/20c526c79799c2f4a986bd2df621b022aa4c875e/core/src/main/java/com/google/googlejavaformat/java/StringWrapper.java#L414

cushon avatar Nov 19 '24 17:11 cushon