Class JavadocLeadingAsteriskAlignCheck

  • All Implemented Interfaces:
    Configurable, Contextualizable

    public class JavadocLeadingAsteriskAlignCheck
    extends AbstractJavadocCheck

    Checks the alignment of leading asterisks in a Javadoc comment. The Check ensures that leading asterisks are aligned vertically under the first asterisk ( * ) of opening Javadoc tag. The alignment of closing Javadoc tag ( */ ) is also checked. If a closing Javadoc tag contains non-whitespace character before it then it's alignment will be ignored. If the ending javadoc line contains a leading asterisk, then that leading asterisk's alignment will be considered, the closing Javadoc tag will be ignored.

    If you're using tabs then specify the the tab width in the tabWidth property.

    • Property violateExecutionOnNonTightHtml - Control when to print violations if the Javadoc being examined by this check violates the tight html rules defined at Tight-HTML Rules. Type is boolean. Default value is false.

    Parent is com.puppycrawl.tools.checkstyle.TreeWalker

    Violation Message Keys:

    • javadoc.asterisk.indentation
    • javadoc.missed.html.close
    • javadoc.parse.rule.error
    • javadoc.unclosedHtml
    • javadoc.wrong.singleton.html.tag
    Since:
    10.18.0
    • Method Detail

      • expandedTabs

        private int expandedTabs​(String line,
                                 int columnNumber)
        Processes and returns the column number of leading asterisk with tabs expanded. Also sets 'expectedColumnNumberWithoutExpandedTabs' if the leading asterisk is present.
        Parameters:
        line - javadoc comment line
        columnNumber - column number of leading asterisk
        Returns:
        column number of leading asterisk with tabs expanded
      • getAsteriskColumnNumber

        private static Optional<IntegergetAsteriskColumnNumber​(String line)
        Processes and returns an OptionalInt containing the column number of leading asterisk without tabs expanded.
        Parameters:
        line - javadoc comment line
        Returns:
        asterisk's column number
      • logViolation

        private void logViolation​(int lineNumber,
                                  int asteriskColNumber,
                                  int expectedColNumber)
        Checks alignment of asterisks and logs violations.
        Parameters:
        lineNumber - line number of current comment line
        asteriskColNumber - column number of leading asterisk
        expectedColNumber - column number of javadoc starting token
      • hasValidAlignment

        private static boolean hasValidAlignment​(int expectedColNumber,
                                                 int asteriskColNumber)
        Checks the column difference between expected column number and leading asterisk column number.
        Parameters:
        expectedColNumber - column number of javadoc starting token
        asteriskColNumber - column number of leading asterisk
        Returns:
        true if the asterisk is aligned properly, false otherwise