Class SummaryJavadocCheck

  • All Implemented Interfaces:
    Configurable, Contextualizable

    public class SummaryJavadocCheck
    extends AbstractJavadocCheck

    Checks that Javadoc summary sentence does not contain phrases that are not recommended to use. By default Check validate that first sentence is not empty:


     <module name="SummaryJavadocCheck"/>
     

    To ensure that summary do not contain phrase like "This method returns", use following config:

     <module name="SummaryJavadocCheck">
         <property name="forbiddenSummaryFragments"
         value="^This method returns.*"/>
     </module>
     

    To specify period symbol at the end of first javadoc sentence - use following config:

     <module name="SummaryJavadocCheck">
         <property name="period"
         value="period"/>
     </module>
     
    • Field Detail

      • MSG_SUMMARY_FIRST_SENTENCE

        public static final java.lang.String MSG_SUMMARY_FIRST_SENTENCE
        A key is pointing to the warning message text in "messages.properties" file.
        See Also:
        Constant Field Values
      • MSG_SUMMARY_JAVADOC

        public static final java.lang.String MSG_SUMMARY_JAVADOC
        A key is pointing to the warning message text in "messages.properties" file.
        See Also:
        Constant Field Values
      • JAVADOC_MULTILINE_TO_SINGLELINE_PATTERN

        private static final java.util.regex.Pattern JAVADOC_MULTILINE_TO_SINGLELINE_PATTERN
        This regexp is used to convert multiline javadoc to single line without stars.
      • SKIP_TOKENS

        private static final java.util.Set<java.lang.Integer> SKIP_TOKENS
        Stores allowed values in document for inherit doc literal.
      • forbiddenSummaryFragments

        private java.util.regex.Pattern forbiddenSummaryFragments
        Regular expression for forbidden summary fragments.
      • period

        private java.lang.String period
        Period symbol at the end of first javadoc sentence.
    • Constructor Detail

      • SummaryJavadocCheck

        public SummaryJavadocCheck()
    • Method Detail

      • setForbiddenSummaryFragments

        public void setForbiddenSummaryFragments​(java.util.regex.Pattern pattern)
        Sets custom value of regular expression for forbidden summary fragments.
        Parameters:
        pattern - a pattern.
      • setPeriod

        public void setPeriod​(java.lang.String period)
        Sets value of period symbol at the end of first javadoc sentence.
        Parameters:
        period - period's value.
      • isOnlyInheritDoc

        private static boolean isOnlyInheritDoc​(DetailNode ast)
        Finds if inheritDoc is placed properly in java doc.
        Parameters:
        ast - Javadoc root node.
        Returns:
        true if inheritDoc is valid or false.
      • getFirstSentence

        private static java.lang.String getFirstSentence​(DetailNode ast)
        Finds and returns first sentence.
        Parameters:
        ast - Javadoc root node.
        Returns:
        first sentence.
      • containsForbiddenFragment

        private boolean containsForbiddenFragment​(java.lang.String firstSentence)
        Tests if first sentence contains forbidden summary fragment.
        Parameters:
        firstSentence - String with first sentence.
        Returns:
        true, if first sentence contains forbidden summary fragment.