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.

Since:
10.18.0
  • Field Details

    • MSG_KEY

      public static final String MSG_KEY
      A key is pointing to the warning message text in "messages.properties" file.
      See Also:
    • javadocStartLineNumber

      private int javadocStartLineNumber
      Specifies the line number of starting block of the javadoc comment.
    • expectedColumnNumberTabsExpanded

      private int expectedColumnNumberTabsExpanded
      Specifies the column number of starting block of the javadoc comment with tabs expanded.
    • fileLines

      private String[] fileLines
      Specifies the lines of the file being processed.
  • Constructor Details

    • JavadocLeadingAsteriskAlignCheck

      public JavadocLeadingAsteriskAlignCheck()
      Creates a new JavadocLeadingAsteriskAlignCheck instance.
  • Method Details

    • getDefaultJavadocTokens

      public int[] getDefaultJavadocTokens()
      Description copied from class: AbstractJavadocCheck
      Returns the default javadoc token types a check is interested in.
      Specified by:
      getDefaultJavadocTokens in class AbstractJavadocCheck
      Returns:
      the default javadoc token types
      See Also:
    • getRequiredJavadocTokens

      public int[] getRequiredJavadocTokens()
      Description copied from class: AbstractJavadocCheck
      The javadoc tokens that this check must be registered for.
      Overrides:
      getRequiredJavadocTokens in class AbstractJavadocCheck
      Returns:
      the javadoc token set this must be registered for.
      See Also:
    • beginJavadocTree

      public void beginJavadocTree(DetailNode rootAst)
      Description copied from class: AbstractJavadocCheck
      Called before the starting to process a tree.
      Overrides:
      beginJavadocTree in class AbstractJavadocCheck
      Parameters:
      rootAst - the root of the tree
    • visitJavadocToken

      public void visitJavadocToken(DetailNode ast)
      Description copied from class: AbstractJavadocCheck
      Called to process a Javadoc token.
      Specified by:
      visitJavadocToken in class AbstractJavadocCheck
      Parameters:
      ast - the token to process
    • finishJavadocTree

      public void finishJavadocTree(DetailNode rootAst)
      Description copied from class: AbstractJavadocCheck
      Called after finished processing a tree.
      Overrides:
      finishJavadocTree in class AbstractJavadocCheck
      Parameters:
      rootAst - the root of the tree
    • getAsteriskColumnNumber

      private static Optional<Integer> getAsteriskColumnNumber(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
    • getColumnNumberTabsExpanded

      private int getColumnNumberTabsExpanded(DetailNode ast)
      Returns the tab-expanded, one-based column number of the leading asterisk node.
      Parameters:
      ast - leading asterisk node
      Returns:
      tab-expanded column number
    • 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