Class WriteTagCheck

All Implemented Interfaces:
Configurable, Contextualizable

public class WriteTagCheck extends AbstractJavadocCheck
Requires user defined Javadoc tag to be present in Javadoc comment with defined format. To define the format for a tag, set property tagFormat to a regular expression. Property tagSeverity is used for severity of events when the tag exists. No violation reported in case there is no javadoc.
Since:
4.2
  • Field Details

    • MSG_MISSING_TAG

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

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

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

      private Pattern tagFormat
      Specify the regexp to match tag content.
    • tag

      private String tag
      Specify the name of tag.
    • tagSeverity

      private SeverityLevel tagSeverity
      Specify the severity level when tag is found and printed.
    • tagFound

      private boolean tagFound
      Whether the target tag was found in the current Javadoc tree.
    • parentLineNo

      private int parentLineNo
      Parent line number for the missing tag report in the current Javadoc tree.
  • Constructor Details

    • WriteTagCheck

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

    • setTag

      public void setTag(String tag)
      Setter to specify the name of tag.
      Parameters:
      tag - tag to check
      Since:
      4.2
    • setTagFormat

      public void setTagFormat(Pattern pattern)
      Setter to specify the regexp to match tag content.
      Parameters:
      pattern - a String value
      Since:
      4.2
    • setTagSeverity

      public final void setTagSeverity(SeverityLevel severity)
      Setter to specify the severity level when tag is found and printed.
      Parameters:
      severity - The new severity level
      Since:
      4.2
      See Also:
    • setViolateExecutionOnNonTightHtml

      public void setViolateExecutionOnNonTightHtml(boolean shouldReportViolation)
      Setter to control when to print violations if the Javadoc being examined by this check violates the tight html rules defined at Tight-HTML Rules.
      Overrides:
      setViolateExecutionOnNonTightHtml in class AbstractJavadocCheck
      Parameters:
      shouldReportViolation - value to which the field shall be set to
      Since:
      8.3
    • getRequiredTokens

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

      public int[] getDefaultTokens()
      Description copied from class: AbstractCheck
      Returns the default token a check is interested in. Only used if the configuration for a check does not define the tokens.
      Overrides:
      getDefaultTokens in class AbstractJavadocCheck
      Returns:
      the default tokens
      See Also:
    • getAcceptableTokens

      public int[] getAcceptableTokens()
      Description copied from class: AbstractCheck
      The configurable token set. Used to protect Checks against malicious users who specify an unacceptable token set in the configuration file. The default implementation returns the check's default tokens.
      Overrides:
      getAcceptableTokens in class AbstractJavadocCheck
      Returns:
      the token set this check is designed 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:
    • 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:
    • visitToken

      public void visitToken(DetailAST ast)
      Description copied from class: AbstractCheck
      Called to process a token.
      Overrides:
      visitToken in class AbstractJavadocCheck
      Parameters:
      ast - the token to process
    • 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
    • getTagContent

      private static String getTagContent(DetailNode javadocBlockTagNode)
      Returns the raw content of the tag.
      Parameters:
      javadocBlockTagNode - The node representing a Javadoc block tag. This node must be of type JavadocCommentsTokenTypes.JAVADOC_BLOCK_TAG
      Returns:
      The raw content of the tag.
    • findJavadoc

      @Nullable private static DetailAST findJavadoc(DetailAST ast)
      Finds the Javadoc comment associated with a structural AST node.
      Parameters:
      ast - the structural node (e.g., CLASS_DEF, METHOD_DEF)
      Returns:
      the Javadoc block comment if found, or null
    • logTag

      private void logTag(int line, String tagName, String tagValue)
      Log a message.
      Parameters:
      line - the line number where the violation was found
      tagName - the Javadoc tag to be logged
      tagValue - the contents of the tag
      See Also: