AtclauseOrder

Description

Since Checkstyle 6.0

Checks the order of javadoc block-tags or javadoc tags.
Note: Google used term "at-clauses" for block tags in his guide till 2017-02-28.

Properties

name description type default value since
violateExecutionOnNonTightHtml If turned on, will print violations if the Javadoc being examined by this check violates the tight html rules defined at Tight-HTML Rules. Boolean false 8.3
target allows to specify targets to check at-clauses. subset of tokens TokenTypes CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF 6.0
tagOrder allows to specify the order by tags. String Set @author, @version, @param, @return, @throws, @exception, @see, @since, @serial, @serialField, @serialData, @deprecated 6.0

Examples

Default configuration

<module name="AtclauseOrder">
    <property name="tagOrder" value="@author, @version, @param,
    @return, @throws, @exception, @see, @since, @serial,
    @serialField, @serialData, @deprecated"/>
    <property name="target" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF,
    METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
</module>
        

Error Messages

All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.javadoc

Parent Module

TreeWalker

JavadocMethod

Description

Since Checkstyle 3.0

Checks the Javadoc of a method or constructor. By default, does not check for unused throws. To allow documented java.lang.RuntimeExceptions that are not declared, set property allowUndeclaredRTE to true. The scope to verify is specified using the Scope class and defaults to Scope.PRIVATE. To verify another scope, set property scope to a different scope.

Error messages about parameters and type parameters for which no param tags are present can be suppressed by defining property allowMissingParamTags. Error messages about exceptions which are declared to be thrown, but for which no throws tag is present can be suppressed by defining property allowMissingThrowsTags. Error messages about methods which return non-void but for which no return tag is present can be suppressed by defining property allowMissingReturnTag.

Javadoc is not required on a method that is tagged with the @Override annotation. However under Java 5 it is not possible to mark a method required for an interface (this was corrected under Java 6). Hence Checkstyle supports using the convention of using a single {@inheritDoc} tag instead of all the other tags.

Note that only inheritable items will allow the {@inheritDoc} tag to be used in place of comments. Static methods at all visibilities, private non-static methods and constructors are not inheritable.

For example, if the following method is implementing a method required by an interface, then the Javadoc could be done as:

/** {@inheritDoc} */
public int checkReturnTag(final int aTagIndex,
                          JavadocTag[] aTags,
                          int aLineNo)

The classpath may need to be configured to locate the class information. The classpath configuration is dependent on the mechanism used to invoke Checkstyle.

Properties

name description type default value since
minLineCount Minimal amount of lines in method to allow no documentation. Integer -1 6.0
allowedAnnotations List of annotations that could allow missed documentation. String Set Override 6.0
validateThrows Allows validating throws tags. Boolean false 6.0
scope visibility scope where Javadoc comments are checked Scope private 3.0
excludeScope visibility scope where Javadoc comments are not checked Scope null 3.4
allowUndeclaredRTE whether to allow documented exceptions that are not declared if they are a subclass of java.lang.RuntimeException Boolean false 3.0
allowThrowsTagsForSubclasses whether to allow documented exceptions that are subclass of one of declared exception. Boolean false 3.1
allowMissingParamTags whether to ignore errors when a method has parameters but does not have matching param tags in the javadoc. Boolean false 3.1
allowMissingThrowsTags whether to ignore errors when a method declares that it throws exceptions but does not have matching throws tags in the javadoc. Boolean false 3.1
allowMissingReturnTag whether to ignore errors when a method returns non-void type and does not have a return tag in the javadoc. Boolean false 3.1
allowMissingJavadoc whether to ignore errors when a method javadoc is missed. Boolean false 4.0
allowMissingPropertyJavadoc Whether to allow missing Javadoc on accessor methods for properties (setters and getters). The setter and getter methods must match exactly the structures below.
public void setNumber(final int number)
{
    mNumber = number;
}

public int getNumber()
{
    return mNumber;
}

public boolean isSomething()
{
    return false;
}
              
Boolean false 4.0
logLoadErrors This check may need to load exception classes mentioned in the @throws tag to check whether they are RuntimeExceptions. If loading the class fails, this property allows to control checkstyle's error handling. If set to false a classpath configuration problem is assumed and the TreeWalker stops operating on the class completely. If set to true (the default) , checkstyle assumes a typo or refactoring problem in the javadoc and logs the problem in the normal checkstyle report (potentially masking a configuration error). Boolean true 4.2
suppressLoadErrors When logLoadErrors is set to true, the TreeWalker completely processes a class and displays any problems with loading exceptions as checkstyle violations. When this property is set to true, the violations generated when logLoadErrors is set true are suppressed from being reported as violations in the checkstyle report. Boolean false 4.2
ignoreMethodNamesRegex ignore method whose names are matching specified regex Regular Expression null 6.3
tokens tokens to check subset of tokens METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF. METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF. 3.0

Examples

To configure the default check:

<module name="JavadocMethod"/>
        

To configure the check for public scope and to allow documentation of undeclared RuntimeExceptions:

<module name="JavadocMethod">
   <property name="scope" value="public"/>
   <property name="allowUndeclaredRTE" value="true"/>
</module>
        

To configure the check for for public scope, to allow documentation of undeclared RuntimeExceptions, while ignoring any missing param tags is:

<module name="JavadocMethod">
  <property name="scope" value="public"/>
  <property name="allowUndeclaredRTE" value="true"/>
  <property name="allowMissingParamTags" value="true"/>
</module>
        

To configure the check for methods which are in private, but not in protected scope:

<module name="JavadocMethod">
   <property name="scope" value="private"/>
   <property name="excludeScope" value="protected"/>
</module>
        

To configure the check for ignoring methods named foo(),foo1(),foo2(), etc.:

<module name="JavadocMethod">
   <property name="ignoreMethodNamesRegex" value="^foo.*$"/>
</module>
        

Package

com.puppycrawl.tools.checkstyle.checks.javadoc

Parent Module

TreeWalker

JavadocPackage

Description

Since Checkstyle 5.0

Checks that each Java package has a Javadoc file used for commenting. By default it only allows a package-info.java file, but can be configured to allow a package.html file.

An error will be reported if both files exist as this is not allowed by the Javadoc tool.

Properties

name description type default value since
allowLegacy If set then allow the use of a package.html file. Boolean false 5.0
fileExtensions file type extension of files to process String Set .java 5.0

Examples

To configure the check:

<module name="JavadocPackage"/>
        

Example of Usage

Error Messages

All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.javadoc

Parent Module

Checker

JavadocParagraph

Description

Since Checkstyle 6.0

Checks that:

  • There is one blank line between each of two paragraphs and one blank line before the at-clauses block if it is present.
  • Each paragraph but the first has <p> immediately before the first word, with no space after.

Properties

name description type default value since
violateExecutionOnNonTightHtml If turned on, will print violations if the Javadoc being examined by this check violates the tight html rules defined at Tight-HTML Rules. Boolean false 8.3
allowNewlineParagraph whether the <p> tag should be placed immediately before the first word Boolean true 6.9

Examples

Default configuration:

<module name="JavadocParagraph"/>
        

To allows to place text of a paragraph not immediately after a <p> tag:

<module name="JavadocParagraph">
    <property name="allowNewlineParagraph" value="true"/>
</module>
        

In case of tagImmediatelyBeforeFirstWord set to false the following example will not have any violations:

/**
 * Some Javadoc.
 *
 * <p>
 * Some Javadoc.
 *
 * <p>  Some Javadoc.
 *
 * <p>
 * <pre>
 * Some preformatted Javadoc.
 * </pre>
 *
 */
        

Package

com.puppycrawl.tools.checkstyle.checks.javadoc

Parent Module

TreeWalker

JavadocStyle

Description

Since Checkstyle 3.2

Validates Javadoc comments to help ensure they are well formed. The following checks are performed:

  • Ensures the first sentence ends with proper punctuation (That is a period, question mark, or exclamation mark, by default). Javadoc automatically places the first sentence in the method summary table and index. Without proper punctuation the Javadoc may be malformed. All items eligible for the {@inheritDoc} tag are exempt from this requirement.
  • Check text for Javadoc statements that do not have any description. This includes both completely empty Javadoc, and Javadoc with only tags such as @param and @return.
  • Check text for incomplete HTML tags. Verifies that HTML tags have corresponding end tags and issues an "Unclosed HTML tag found:" error if not. An "Extra HTML tag found:" error is issued if an end tag is found without a previous open tag.
  • Check that a package Javadoc comment is well-formed (as described above) and NOT missing from any package-info.java files.
  • Check for allowed HTML tags. The list of allowed HTML tags is "a", "abbr", "acronym", "address", "area", "b", "bdo", "big", "blockquote", "br", "caption", "cite", "code", "colgroup", "dd", "del", "div", "dfn", "dl", "dt", "em", "fieldset", "font", "h1" to "h6", "hr", "i", "img", "ins", "kbd", "li", "ol", "p", "pre", "q", "samp", "small", "span", "strong", "sub", "sup", "table", "tbody", "td", "tfoot", "th", "thread", "tr", "tt", "u", "ul".

These checks were patterned after the checks made by the DocCheck doclet available from Sun. Note: Original Sun's DocCheck tool does not exist anymore.

Properties

name description type default value since
scope visibility scope where Javadoc comments are checked Scope private 3.2
excludeScope visibility scope where Javadoc comments are not checked Scope null 3.4
checkFirstSentence Whether to check the first sentence for proper end of sentence. Boolean true 3.2
endOfSentenceFormat Format for matching the end of a sentence. Regular Expression "([.?!][ \t\n\r\f<])|([.?!]$)" 5.0
checkEmptyJavadoc Whether to check if the Javadoc is missing a describing text. Boolean false 3.4
checkHtml Whether to check for incomplete HTML tags. Boolean true 3.2
tokens tokens to check subset of tokens ANNOTATION_DEF, ANNOTATION_FIELD_DEF, CLASS_DEF, CTOR_DEF, ENUM_CONSTANT_DEF, ENUM_DEF, INTERFACE_DEF, METHOD_DEF, PACKAGE_DEF, VARIABLE_DEF. ANNOTATION_DEF, ANNOTATION_FIELD_DEF, CLASS_DEF, CTOR_DEF, ENUM_CONSTANT_DEF, ENUM_DEF, INTERFACE_DEF, METHOD_DEF, PACKAGE_DEF, VARIABLE_DEF. 3.2

Examples

To configure the default check:

<module name="JavadocStyle"/>
        

To configure the check for public scope:

<module name="JavadocStyle">
   <property name="scope" value="public"/>
</module>
        

To configure the check for javadoc which is in private, but not in package scope:

<module name="JavadocStyle">
   <property name="scope" value="private"/>
   <property name="excludeScope" value="package"/>
</module>
        

To configure the check to turn off first sentence checking:

<module name="JavadocStyle">
   <property name="checkFirstSentence" value="false"/>
</module>
        

Example of Usage

Error Messages

All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.javadoc

Parent Module

TreeWalker

JavadocTagContinuationIndentation

Description

Since Checkstyle 6.0

Checks the indentation of the continuation lines in at-clauses.

Properties

name description type default value since
violateExecutionOnNonTightHtml If turned on, will print violations if the Javadoc being examined by this check violates the tight html rules defined at Tight-HTML Rules. Boolean false 8.3
offset How many spaces to use for new indentation level. Integer 4 6.0

Examples

Default configuration

<module name="JavadocTagContinuationIndentation">
    <property name="offset" value="4"/>
</module>
        

Error Messages

All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.javadoc

Parent Module

TreeWalker

JavadocType

Description

Since Checkstyle 3.0

Checks Javadoc comments for class and interface definitions. By default, does not check for author or version tags. The scope to verify is specified using the Scope class and defaults to Scope.PRIVATE. To verify another scope, set property scope to one of the Scope constants. To define the format for an author tag or a version tag, set property authorFormat or versionFormat respectively to a regular expression.

Does not perform checks for author and version tags for inner classes, as they should be redundant because of outer class.

Error messages about type parameters for which no param tags are present can be suppressed by defining property allowMissingParamTags.

Properties

name description type default value since
scope visibility scope where Javadoc comments are checked Scope private 3.0
excludeScope visibility scope where Javadoc comments are not checked Scope null 3.4
authorFormat pattern for @author tag Regular Expression null 3.0
versionFormat pattern for @version tag Regular Expression null 3.0
allowMissingParamTags whether to ignore errors when a class has type parameters but does not have matching param tags in the javadoc. Boolean false 4.0
allowUnknownTags whether to ignore errors when a Javadoc tag is not recognised. Boolean false 5.1
tokens tokens to check subset of tokens INTERFACE_DEF, CLASS_DEF, ENUM_DEF, ANNOTATION_DEF. INTERFACE_DEF, CLASS_DEF, ENUM_DEF, ANNOTATION_DEF. 3.0

Examples

To configure the default check:

<module name="JavadocType"/>
        

To configure the check for public scope:

<module name="JavadocType">
   <property name="scope" value="public"/>
</module>
        

To configure the check for an @author tag:

<module name="JavadocType">
   <property name="authorFormat" value="\S"/>
</module>
        

To configure the check for a CVS revision version tag:

<module name="JavadocType">
   <property name="versionFormat" value="\$Revision.*\$"/>
</module>
        

To configure the check for private classes only:

<module name="JavadocType">
   <property name="scope" value="private"/>
   <property name="excludeScope" value="package"/>
</module>
        

Example of Usage

Error Messages

All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.javadoc

Parent Module

TreeWalker

JavadocVariable

Description

Since Checkstyle 3.0

Checks that variables have Javadoc comments. Ignores serialVersionUID fields.

Properties

name description type default value since
scope visibility scope where Javadoc comments are checked Scope private 3.0
excludeScope visibility scope where Javadoc comments are not checked Scope null 3.4
ignoreNamePattern regexp to define variable names to ignore Regular Expression null 5.8
tokens tokens to check subset of tokens ENUM_CONSTANT_DEF. ENUM_CONSTANT_DEF. 3.0

Examples

To configure the default check:

<module name="JavadocVariable"/>
        

To configure the check for public scope:

<module name="JavadocVariable">
   <property name="scope" value="public"/>
</module>
        

To configure the check for members which are in private, but not in protected scope:

<module name="JavadocVariable">
   <property name="scope" value="private"/>
   <property name="excludeScope" value="protected"/>
</module>
        

To ignore absence of Javadoc comments for variables with names log or logger:

<module name="JavadocVariable">
    <property name="ignoreNamePattern" value="log|logger"/>
</module>
        

Example of Usage

Error Messages

All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.javadoc

Parent Module

TreeWalker

NonEmptyAtclauseDescription

Description

Since Checkstyle 6.0

Checks that the at-clause tag is followed by description.

Properties

name description type default value since
violateExecutionOnNonTightHtml If turned on, will print violations if the Javadoc being examined by this check violates the tight html rules defined at Tight-HTML Rules. Boolean false 8.3
javadocTokens javadoc tokens to check subset of javadoc tokens PARAM_LITERAL, RETURN_LITERAL, THROWS_LITERAL, EXCEPTION_LITERAL, DEPRECATED_LITERAL. PARAM_LITERAL, RETURN_LITERAL, THROWS_LITERAL, EXCEPTION_LITERAL, DEPRECATED_LITERAL. 7.3

Examples

Default configuration that will check @param, @return, @throws, @deprecated:

<module name="NonEmptyAtclauseDescription"/>
        

Error Messages

All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.javadoc

Parent Module

TreeWalker

SingleLineJavadoc

Description

Since Checkstyle 6.0

Checks that a JavaDoc block can fit in a single line and doesn't contain at-clauses. Javadoc comment that contains at least one at-clause should be formatted in a few lines.

Properties

name description type default value since
violateExecutionOnNonTightHtml If turned on, will print violations if the Javadoc being examined by this check violates the tight html rules defined at Tight-HTML Rules. Boolean false 8.3
ignoredTags allows to specify at-clauses which are ignored by the check. String Set {} 6.8
ignoreInlineTags whether inline tags must be ignored. Boolean true 6.8

Examples

Default configuration:

<module name="SingleLineJavadoc"/>
        

To specify a list of ignored at-clauses and make inline at-clauses not ignored:

<module name="SingleLineJavadoc">
    <property name="ignoredTags" value="@inheritDoc, @see"/>
    <property name="ignoreInlineTags" value="false"/>
</module>
        

Error Messages

All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.javadoc

Parent Module

TreeWalker

SummaryJavadoc

Description

Since Checkstyle 6.0

Checks that Javadoc summary sentence does not contain phrases that are not recommended to use. Summaries that contain only the {@inheritDoc} tag are skipped. Check also violate javadoc that does not contain first sentence.

Properties

name description type default value since
violateExecutionOnNonTightHtml If turned on, will print violations if the Javadoc being examined by this check violates the tight html rules defined at Tight-HTML Rules. Boolean false 8.3
forbiddenSummaryFragments forbidden summary fragments Regular Expression "^$" 6.0
period period symbol at the end of first javadoc sentence String "." 6.2

Examples

By default Check validate that first sentence is not empty and first sentence is not missing:

<module name="SummaryJavadocCheck"/>
        

Example of {@inheritDoc} without summary.

          
  public class Test extends Exception {
  //Valid
    /**
     * {@inheritDoc}
     */
    public String ValidFunction(){
      return "";
    }
    //Violation
    /**
     *
     */
    public String InvalidFunction(){
      return "";
    }
  }
        
        

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:

<module name="SummaryJavadocCheck">
    <property name="period" value="。"/>
</module>
        

Example of period property.

public class TestClass {
   /**
    * This is invalid java doc.
    */
    void invalidJavaDocMethod() {
    }
   /**
    * This is valid java doc。
    */
    void validJavaDocMethod() {
    }
}
        

Error Messages

All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.javadoc

Parent Module

TreeWalker

WriteTag

Description

Since Checkstyle 4.2

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.

Properties

name description type default value since
tag Name of tag String null 4.2
tagFormat Format of tag Regular Expression null 4.2
tagSeverity Severity level when tag is found and printed Severity info 4.2
tokens tokens to check subset of tokens INTERFACE_DEF, CLASS_DEF, ENUM_DEF, ANNOTATION_DEF, METHOD_DEF, CTOR_DEF, ENUM_CONSTANT_DEF, ANNOTATION_FIELD_DEF. INTERFACE_DEF, CLASS_DEF, ENUM_DEF, ANNOTATION_DEF. 4.2

Examples

An example of how to configure the check for printing author name is:

<module name="WriteTag">
   <property name="tag" value="@author"/>
   <property name="tagFormat" value="\S"/>
</module>
        

An example of how to configure the check to print warnings if an "@incomplete" tag is found, and not print anything if it is not found:

<module name="WriteTag">
   <property name="tag" value="@incomplete"/>
   <property name="tagFormat" value="\S"/>
   <property name="severity" value="ignore"/>
   <property name="tagSeverity" value="warning"/>
</module>
        

Example of Usage

Error Messages

All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.javadoc

Parent Module

TreeWalker