Coverage Report - com.puppycrawl.tools.checkstyle.checks.javadoc.NonEmptyAtclauseDescriptionCheck
 
Classes in this File Line Coverage Branch Coverage Complexity
NonEmptyAtclauseDescriptionCheck
100%
8/8
100%
4/4
1.333
 
 1  
 ////////////////////////////////////////////////////////////////////////////////
 2  
 // checkstyle: Checks Java source code for adherence to a set of rules.
 3  
 // Copyright (C) 2001-2017 the original author or authors.
 4  
 //
 5  
 // This library is free software; you can redistribute it and/or
 6  
 // modify it under the terms of the GNU Lesser General Public
 7  
 // License as published by the Free Software Foundation; either
 8  
 // version 2.1 of the License, or (at your option) any later version.
 9  
 //
 10  
 // This library is distributed in the hope that it will be useful,
 11  
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
 // Lesser General Public License for more details.
 14  
 //
 15  
 // You should have received a copy of the GNU Lesser General Public
 16  
 // License along with this library; if not, write to the Free Software
 17  
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18  
 ////////////////////////////////////////////////////////////////////////////////
 19  
 
 20  
 package com.puppycrawl.tools.checkstyle.checks.javadoc;
 21  
 
 22  
 import com.puppycrawl.tools.checkstyle.api.DetailNode;
 23  
 import com.puppycrawl.tools.checkstyle.api.JavadocTokenTypes;
 24  
 import com.puppycrawl.tools.checkstyle.utils.JavadocUtils;
 25  
 
 26  
 /**
 27  
  * Checks that the at-clause tag is followed by description .
 28  
  * Default configuration that will check {@code @param}, {@code @return},
 29  
  * {@code @throws}, {@code @deprecated} to:
 30  
  * <pre>
 31  
  * &lt;module name=&quot;NonEmptyAtclauseDescription&quot;/&gt;
 32  
  * </pre>
 33  
  *
 34  
  * @author maxvetrenko
 35  
  *
 36  
  */
 37  12
 public class NonEmptyAtclauseDescriptionCheck extends AbstractJavadocCheck {
 38  
 
 39  
     /**
 40  
      * A key is pointing to the warning message text in "messages.properties"
 41  
      * file.
 42  
      */
 43  
     public static final String MSG_KEY = "non.empty.atclause";
 44  
 
 45  
     @Override
 46  
     public int[] getDefaultJavadocTokens() {
 47  8
         return new int[] {
 48  
             JavadocTokenTypes.PARAM_LITERAL,
 49  
             JavadocTokenTypes.RETURN_LITERAL,
 50  
             JavadocTokenTypes.THROWS_LITERAL,
 51  
             JavadocTokenTypes.EXCEPTION_LITERAL,
 52  
             JavadocTokenTypes.DEPRECATED_LITERAL,
 53  
         };
 54  
     }
 55  
 
 56  
     @Override
 57  
     public void visitJavadocToken(DetailNode ast) {
 58  43
         if (isEmptyTag(ast.getParent())) {
 59  18
             log(ast.getLineNumber(), MSG_KEY, ast.getText());
 60  
         }
 61  43
     }
 62  
 
 63  
     /**
 64  
      * Tests if at-clause tag is empty.
 65  
      * @param tagNode at-clause tag.
 66  
      * @return true, if at-clause tag is empty.
 67  
      */
 68  
     private static boolean isEmptyTag(DetailNode tagNode) {
 69  43
         final DetailNode tagDescription =
 70  43
                 JavadocUtils.findFirstToken(tagNode, JavadocTokenTypes.DESCRIPTION);
 71  43
         return tagDescription == null;
 72  
     }
 73  
 }