Class JavadocRegexpCheck

All Implemented Interfaces:
Configurable, Contextualizable

public class JavadocRegexpCheck extends AbstractJavadocCheck
Checks that Javadoc comments do not match a configured regular expression.

The check can operate on raw Javadoc source or on the text visible to readers. Raw matching includes Javadoc tags, HTML tags, HTML attributes, and formatting characters. Visible-text matching ignores markup and matches only Javadoc text content.

Since:
13.10.0
  • Field Details

    • MSG_JAVADOC_REGEXP

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

      private final List<String> visibleText
      Text fragments visible to readers of the current Javadoc comment.
    • format

      private String format
      Specify the regular expression to match forbidden Javadoc content.
    • ignoreCase

      private boolean ignoreCase
      Control whether to ignore case when matching.
    • ignoreMarkup

      private boolean ignoreMarkup
      Control whether to ignore Javadoc and HTML markup when matching.
    • previousTextLineNumber

      private int previousTextLineNumber
      Line number of the previous collected text node.
  • Constructor Details

    • JavadocRegexpCheck

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

    • setFormat

      public void setFormat(String format)
      Setter to specify the regular expression to match forbidden Javadoc content.
      Parameters:
      format - regular expression to match forbidden Javadoc content.
      Since:
      13.10.0
    • setIgnoreCase

      public void setIgnoreCase(boolean ignoreCase)
      Setter to control whether to ignore case when matching.
      Parameters:
      ignoreCase - whether to ignore case when matching.
      Since:
      13.10.0
    • setIgnoreMarkup

      public void setIgnoreMarkup(boolean ignoreMarkup)
      Setter to control whether to ignore Javadoc and HTML markup when matching.
      Parameters:
      ignoreMarkup - whether to ignore Javadoc and HTML markup when matching.
      Since:
      13.10.0
    • 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:
    • 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:
    • 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
    • createRegexp

      private Pattern createRegexp()
      Creates the regexp based on format and ignoreCase.
      Returns:
      pattern used to find forbidden content.
    • appendVisibleText

      private void appendVisibleText(DetailNode textNode)
      Appends visible text from a Javadoc text node.
      Parameters:
      textNode - text node to append.
    • isIgnoredText

      private static boolean isIgnoredText(DetailNode textNode)
      Checks whether a text node belongs to a non-rendered HTML comment.
      Parameters:
      textNode - text node to check.
      Returns:
      true if the text node should be ignored.