Class JavadocMethodCheck

    • Field Detail

      • MSG_JAVADOC_MISSING

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

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

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

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

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

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

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

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

        private static final java.util.regex.Pattern MATCH_JAVADOC_ARG
        Compiled regexp to match Javadoc tags that take an argument.
      • MATCH_JAVADOC_ARG_MULTILINE_START

        private static final java.util.regex.Pattern MATCH_JAVADOC_ARG_MULTILINE_START
        Compiled regexp to match first part of multilineJavadoc tags.
      • MATCH_JAVADOC_MULTILINE_CONT

        private static final java.util.regex.Pattern MATCH_JAVADOC_MULTILINE_CONT
        Compiled regexp to look for a continuation of the comment.
      • END_JAVADOC

        private static final java.lang.String END_JAVADOC
        Multiline finished at end of comment.
        See Also:
        Constant Field Values
      • NEXT_TAG

        private static final java.lang.String NEXT_TAG
        Multiline finished at next Javadoc.
        See Also:
        Constant Field Values
      • MATCH_JAVADOC_NOARG

        private static final java.util.regex.Pattern MATCH_JAVADOC_NOARG
        Compiled regexp to match Javadoc tags with no argument.
      • MATCH_JAVADOC_NOARG_MULTILINE_START

        private static final java.util.regex.Pattern MATCH_JAVADOC_NOARG_MULTILINE_START
        Compiled regexp to match first part of multilineJavadoc tags.
      • MATCH_JAVADOC_NOARG_CURLY

        private static final java.util.regex.Pattern MATCH_JAVADOC_NOARG_CURLY
        Compiled regexp to match Javadoc tags with no argument and {}.
      • DEFAULT_MIN_LINE_COUNT

        private static final int DEFAULT_MIN_LINE_COUNT
        Default value of minimal amount of lines in method to demand documentation presence.
        See Also:
        Constant Field Values
      • scope

        private Scope scope
        The visibility scope where Javadoc comments are checked.
      • excludeScope

        private Scope excludeScope
        The visibility scope where Javadoc comments shouldn't be checked.
      • minLineCount

        private int minLineCount
        Minimal amount of lines in method to demand documentation presence.
      • allowUndeclaredRTE

        private boolean allowUndeclaredRTE
        Controls whether to allow documented exceptions that are not declared if they are a subclass of java.lang.RuntimeException.
      • validateThrows

        private boolean validateThrows
        Allows validating throws tags.
      • allowThrowsTagsForSubclasses

        private boolean allowThrowsTagsForSubclasses
        Controls whether to allow documented exceptions that are subclass of one of declared exception. Defaults to false (backward compatibility).
      • allowMissingParamTags

        private boolean allowMissingParamTags
        Controls whether to ignore errors when a method has parameters but does not have matching param tags in the javadoc. Defaults to false.
      • allowMissingThrowsTags

        private boolean allowMissingThrowsTags
        Controls whether to ignore errors when a method declares that it throws exceptions but does not have matching throws tags in the javadoc. Defaults to false.
      • allowMissingReturnTag

        private boolean allowMissingReturnTag
        Controls whether to ignore errors when a method returns non-void type but does not have a return tag in the javadoc. Defaults to false.
      • allowMissingJavadoc

        private boolean allowMissingJavadoc
        Controls whether to ignore errors when there is no javadoc. Defaults to false.
      • allowMissingPropertyJavadoc

        private boolean allowMissingPropertyJavadoc
        Controls whether to allow missing Javadoc on accessor methods for properties (setters and getters).
      • allowedAnnotations

        private java.util.List<java.lang.String> allowedAnnotations
        List of annotations that could allow missed documentation.
      • ignoreMethodNamesRegex

        private java.util.regex.Pattern ignoreMethodNamesRegex
        Method names that match this pattern do not require javadoc blocks.
    • Constructor Detail

      • JavadocMethodCheck

        public JavadocMethodCheck()
    • Method Detail

      • setIgnoreMethodNamesRegex

        public void setIgnoreMethodNamesRegex​(java.util.regex.Pattern pattern)
        Set regex for matching method names to ignore.
        Parameters:
        pattern - a pattern.
      • setMinLineCount

        public void setMinLineCount​(int value)
        Sets minimal amount of lines in method.
        Parameters:
        value - user's value.
      • setValidateThrows

        public void setValidateThrows​(boolean value)
        Allow validating throws tag.
        Parameters:
        value - user's value.
      • setAllowedAnnotations

        public void setAllowedAnnotations​(java.lang.String... userAnnotations)
        Sets list of annotations.
        Parameters:
        userAnnotations - user's value.
      • setScope

        public void setScope​(Scope scope)
        Set the scope.
        Parameters:
        scope - a scope.
      • setExcludeScope

        public void setExcludeScope​(Scope excludeScope)
        Set the excludeScope.
        Parameters:
        excludeScope - a scope.
      • setAllowUndeclaredRTE

        public void setAllowUndeclaredRTE​(boolean flag)
        Controls whether to allow documented exceptions that are not declared if they are a subclass of java.lang.RuntimeException.
        Parameters:
        flag - a Boolean value
      • setAllowThrowsTagsForSubclasses

        public void setAllowThrowsTagsForSubclasses​(boolean flag)
        Controls whether to allow documented exception that are subclass of one of declared exceptions.
        Parameters:
        flag - a Boolean value
      • setAllowMissingParamTags

        public void setAllowMissingParamTags​(boolean flag)
        Controls whether to allow a method which has parameters to omit matching param tags in the javadoc. Defaults to false.
        Parameters:
        flag - a Boolean value
      • setAllowMissingThrowsTags

        public void setAllowMissingThrowsTags​(boolean flag)
        Controls whether to allow a method which declares that it throws exceptions to omit matching throws tags in the javadoc. Defaults to false.
        Parameters:
        flag - a Boolean value
      • setAllowMissingReturnTag

        public void setAllowMissingReturnTag​(boolean flag)
        Controls whether to allow a method which returns non-void type to omit the return tag in the javadoc. Defaults to false.
        Parameters:
        flag - a Boolean value
      • setAllowMissingJavadoc

        public void setAllowMissingJavadoc​(boolean flag)
        Controls whether to ignore errors when there is no javadoc. Defaults to false.
        Parameters:
        flag - a Boolean value
      • setAllowMissingPropertyJavadoc

        public void setAllowMissingPropertyJavadoc​(boolean flag)
        Controls whether to ignore errors when there is no javadoc for a property accessor (setter/getter methods). Defaults to false.
        Parameters:
        flag - a Boolean value
      • 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.
        Specified by:
        getDefaultTokens in class AbstractCheck
        Returns:
        the default tokens
        See Also:
        TokenTypes
      • 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.
        Specified by:
        getAcceptableTokens in class AbstractCheck
        Returns:
        the token set this check is designed for.
        See Also:
        TokenTypes
      • isCommentNodesRequired

        public boolean isCommentNodesRequired()
        Description copied from class: AbstractCheck
        Whether comment nodes are required or not.
        Overrides:
        isCommentNodesRequired in class AbstractCheck
        Returns:
        false as a default value.
      • hasAllowedAnnotations

        private boolean hasAllowedAnnotations​(DetailAST methodDef)
        Some javadoc.
        Parameters:
        methodDef - Some javadoc.
        Returns:
        Some javadoc.
      • getMethodsNumberOfLine

        private static int getMethodsNumberOfLine​(DetailAST methodDef)
        Some javadoc.
        Parameters:
        methodDef - Some javadoc.
        Returns:
        Some javadoc.
      • isMissingJavadocAllowed

        protected boolean isMissingJavadocAllowed​(DetailAST ast)
        The JavadocMethodCheck is about to report a missing Javadoc. This hook can be used by derived classes to allow a missing javadoc in some situations. The default implementation checks allowMissingJavadoc and allowMissingPropertyJavadoc properties, do not forget to call super.isMissingJavadocAllowed(ast) in case you want to keep this logic.
        Parameters:
        ast - the tree node for the method or constructor.
        Returns:
        True if this method or constructor doesn't need Javadoc.
      • isContentsAllowMissingJavadoc

        private boolean isContentsAllowMissingJavadoc​(DetailAST ast)
        Checks if the Javadoc can be missing if the method or constructor is below the minimum line count or has a special annotation.
        Parameters:
        ast - the tree node for the method or constructor.
        Returns:
        True if this method or constructor doesn't need Javadoc.
      • matchesSkipRegex

        private boolean matchesSkipRegex​(DetailAST methodDef)
        Checks if the given method name matches the regex. In that case we skip enforcement of javadoc for this method
        Parameters:
        methodDef - METHOD_DEF
        Returns:
        true if given method name matches the regex.
      • shouldCheck

        private boolean shouldCheck​(DetailAST ast,
                                    Scope nodeScope)
        Whether we should check this node.
        Parameters:
        ast - a given node.
        nodeScope - the scope of the node.
        Returns:
        whether we should check a given node.
      • checkComment

        private void checkComment​(DetailAST ast,
                                  TextBlock comment)
        Checks the Javadoc for a method.
        Parameters:
        ast - the token for the method
        comment - the Javadoc comment
      • hasShortCircuitTag

        private boolean hasShortCircuitTag​(DetailAST ast,
                                           java.util.List<JavadocTag> tags)
        Validates whether the Javadoc has a short circuit tag. Currently this is the inheritTag. Any errors are logged.
        Parameters:
        ast - the construct being checked
        tags - the list of Javadoc tags associated with the construct
        Returns:
        true if the construct has a short circuit tag.
      • calculateScope

        private static Scope calculateScope​(DetailAST ast)
        Returns the scope for the method/constructor at the specified AST. If the method is in an interface or annotation block, the scope is assumed to be public.
        Parameters:
        ast - the token of the method/constructor
        Returns:
        the scope of the method/constructor
      • getMethodTags

        private static java.util.List<JavadocTag> getMethodTags​(TextBlock comment)
        Returns the tags in a javadoc comment. Only finds throws, exception, param, return and see tags.
        Parameters:
        comment - the Javadoc comment
        Returns:
        the tags found
      • calculateTagColumn

        private static int calculateTagColumn​(java.util.regex.Matcher javadocTagMatcher,
                                              int lineNumber,
                                              int startColumnNumber)
        Calculates column number using Javadoc tag matcher.
        Parameters:
        javadocTagMatcher - found javadoc tag matcher
        lineNumber - line number of Javadoc tag in comment
        startColumnNumber - column number of Javadoc comment beginning
        Returns:
        column number
      • getMultilineArgTags

        private static java.util.List<JavadocTag> getMultilineArgTags​(java.util.regex.Matcher argMultilineStart,
                                                                      int column,
                                                                      java.lang.String[] lines,
                                                                      int lineIndex,
                                                                      int tagLine)
        Gets multiline Javadoc tags with arguments.
        Parameters:
        argMultilineStart - javadoc tag Matcher
        column - column number of Javadoc tag
        lines - comment text lines
        lineIndex - line number that contains the javadoc tag
        tagLine - javadoc tag line number in file
        Returns:
        javadoc tags with arguments
      • getMultilineNoArgTags

        private static java.util.List<JavadocTag> getMultilineNoArgTags​(java.util.regex.Matcher noargMultilineStart,
                                                                        java.lang.String[] lines,
                                                                        int lineIndex,
                                                                        int tagLine)
        Gets multiline Javadoc tags with no arguments.
        Parameters:
        noargMultilineStart - javadoc tag Matcher
        lines - comment text lines
        lineIndex - line number that contains the javadoc tag
        tagLine - javadoc tag line number in file
        Returns:
        javadoc tags with no arguments
      • getParameters

        private static java.util.List<DetailAST> getParameters​(DetailAST ast)
        Computes the parameter nodes for a method.
        Parameters:
        ast - the method node.
        Returns:
        the list of parameter nodes for ast.
      • getThrows

        private java.util.List<JavadocMethodCheck.ExceptionInfo> getThrows​(DetailAST ast)
        Computes the exception nodes for a method.
        Parameters:
        ast - the method node.
        Returns:
        the list of exception nodes for ast.
      • checkParamTags

        private void checkParamTags​(java.util.List<JavadocTag> tags,
                                    DetailAST parent,
                                    boolean reportExpectedTags)
        Checks a set of tags for matching parameters.
        Parameters:
        tags - the tags to check
        parent - the node which takes the parameters
        reportExpectedTags - whether we should report if do not find expected tag
      • searchMatchingTypeParameter

        private static boolean searchMatchingTypeParameter​(java.util.List<DetailAST> typeParams,
                                                           java.lang.String requiredTypeName)
        Returns true if required type found in type parameters.
        Parameters:
        typeParams - list of type parameters
        requiredTypeName - name of required type
        Returns:
        true if required type found in type parameters.
      • removeMatchingParam

        private static boolean removeMatchingParam​(java.util.List<DetailAST> params,
                                                   java.lang.String paramName)
        Remove parameter from params collection by name.
        Parameters:
        params - collection of DetailAST parameters
        paramName - name of parameter
        Returns:
        true if parameter found and removed
      • checkReturnTag

        private void checkReturnTag​(java.util.List<JavadocTag> tags,
                                    int lineNo,
                                    boolean reportExpectedTags)
        Checks for only one return tag. All return tags will be removed from the supplied list.
        Parameters:
        tags - the tags to check
        lineNo - the line number of the expected tag
        reportExpectedTags - whether we should report if do not find expected tag
      • checkThrowsTags

        private void checkThrowsTags​(java.util.List<JavadocTag> tags,
                                     java.util.List<JavadocMethodCheck.ExceptionInfo> throwsList,
                                     boolean reportExpectedTags)
        Checks a set of tags for matching throws.
        Parameters:
        tags - the tags to check
        throwsList - the throws to check
        reportExpectedTags - whether we should report if do not find expected tag
      • isInThrows

        private boolean isInThrows​(java.util.List<JavadocMethodCheck.ExceptionInfo> throwsList,
                                   AbstractTypeAwareCheck.AbstractClassInfo documentedClassInfo,
                                   java.util.Set<java.lang.String> foundThrows)
        Verifies that documented exception is in throws.
        Parameters:
        throwsList - list of throws
        documentedClassInfo - documented exception class info
        foundThrows - previously found throws
        Returns:
        true if documented exception is in throws.