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

google-java-format-eclipse-plugin-1.11.0.jar does not format the same as command line

Open deckrider opened this issue 4 years ago • 3 comments

Here is a test:

package some.test;

public class Test {
  String myLongString =
      "The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.";
}

Eclipse formats it just as above. google-java-format-1.11.0-all-deps.jar on the comamnd line formats it as follows:

package some.test;

public class Test {
  String myLongString =
      "The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog."
          + " The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy"
          + " dog.";
}

deckrider avatar Aug 10 '21 19:08 deckrider

Possibly related to #566

cies avatar Aug 30 '21 08:08 cies

The CLI has a separate pass that reflows long strings literals (corresponding to --skip-reflowing-long-strings):

https://github.com/google/google-java-format/blob/5104d0b27888f3bfab7113f5606374cda5632102/core/src/main/java/com/google/googlejavaformat/java/FormatFileCallable.java#L48

The plugin currently just runs the core formatter logic, not the string reflowing part.

cushon avatar Aug 30 '21 23:08 cushon

Most likely related, the CLI formats short comments like

  /**
   * @return Optional qualifier with more details.
   */
  public String getCustomQualifier() {
    return qualifier;
  }

while the Eclipse plugin formats it like

  /** @return Optional qualifier with more details. */
  public String getCustomQualifier() {
    return qualifier;
  }

blutorange avatar Mar 21 '22 22:03 blutorange