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

No empty line before method with Javadoc

Open Stephan202 opened this issue 6 years ago • 1 comments

Consider the following code:

class Dummy {
    void method1() {}
    void method2() {}

    void method3() {}
    /** Documentation. */
    void method4() {}

    class Inner1 {}
    void method5() {}

    class Inner2 {}
    // Comment
    void method6() {}
}

Running java -jar google-java-format-1.7-all-deps.jar Dummy.java produces:

class Dummy {
  void method1() {}

  void method2() {}

  void method3() {}
  /** Documentation. */
  void method4() {}

  class Inner1 {}

  void method5() {}

  class Inner2 {}
  // Comment
  void method6() {}
}

Note how a newline is inserted before method2 and method5, but not before method4 and method6. Based on all occurrences I found in our private code base (using Checkstyle's EmptyLineSeparatorCheck) the issue seems to happen:

  • only when there is a comment (//**, /* or //) on the method.
  • but irrespective of the syntactic construct (another method, a field, a class, ....) that precedes it.

Based on section 4.6.1 of the style guide I do think such empty lines should be introduced.

Stephan202 avatar Sep 15 '19 14:09 Stephan202

I would also add that if you add extra blank lines before the methods with comments, it reduces these to a single blank line so it's inconsistent with the formatting.

pmantyla avatar Feb 21 '20 04:02 pmantyla