Class PreferLiteralJavadocInlineTagCheck

All Implemented Interfaces:
Configurable, Contextualizable

public class PreferLiteralJavadocInlineTagCheck extends AbstractJavadocCheck
Checks that Javadoc inline tags are preferred over escaping entities. According to OpenJDK Style Guidelines v6 Javadoc inline tags should be preferred over their HTML equivalents. Entities that are flagged by the check are:
  • <
  • >
  • &
  • "
  • '

Reason of only these entities are flagged is given here : Predefined Entities

Not flagged:

  • Content inside <pre> and <code> blocks (code examples)
  • Content inside {@code}, {@literal}, {@snippet} inline tags
Since:
13.11.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:
    • HTML_ENTITIES

      private static final List<String> HTML_ENTITIES
      HTML entities to be replaced with {@literal ...}.
  • Constructor Details

    • PreferLiteralJavadocInlineTagCheck

      public PreferLiteralJavadocInlineTagCheck()
      Creates a new PreferJavadocInlineTagsCheck 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:
    • 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
    • checkForHtmlEntities

      private void checkForHtmlEntities(DetailNode textNode)
      Checks Javadoc TEXT nodes for HTML entities that should be replaced with {@literal ...}.
      Parameters:
      textNode - the TEXT node to check
    • getHtmlTagName

      @Nullable private static String getHtmlTagName(DetailNode htmlElement)
      Gets the tag name from an HTML_ELEMENT node.
      Parameters:
      htmlElement - the HTML_ELEMENT node
      Returns:
      the tag name (e.g., "code", "a")
    • isInsidePreOrCodeTag

      private static boolean isInsidePreOrCodeTag(DetailNode node)
      Checks if the node is inside a pre or code tag.
      Parameters:
      node - the node to check
      Returns:
      true if inside a pre or code block
    • isInsideInlineTag

      private static boolean isInsideInlineTag(DetailNode node)
      Checks if the node is inside a {@code}, {@literal} or {@snippet} inline tag. Content inside these tags is meant to be displayed literally, so HTML patterns within them are intentional examples and should not be flagged.
      Parameters:
      node - the node to check
      Returns:
      true if inside a code, literal or snippet inline tag