View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2026 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.StatelessCheck;
23  import com.puppycrawl.tools.checkstyle.api.DetailNode;
24  import com.puppycrawl.tools.checkstyle.api.JavadocCommentsTokenTypes;
25  import com.puppycrawl.tools.checkstyle.utils.JavadocUtil;
26  
27  /**
28   * <div>
29   * Checks that the block tag is followed by description.
30   * </div>
31   *
32   * @since 6.0
33   */
34  @StatelessCheck
35  public class NonEmptyAtclauseDescriptionCheck extends AbstractJavadocCheck {
36  
37      /**
38       * A key is pointing to the warning message text in "messages.properties"
39       * file.
40       */
41      public static final String MSG_KEY = "non.empty.atclause";
42  
43      /**
44       * Creates a new {@code NonEmptyAtclauseDescriptionCheck} instance.
45       */
46      public NonEmptyAtclauseDescriptionCheck() {
47          // no code by default
48      }
49  
50      @Override
51      public int[] getDefaultJavadocTokens() {
52          return new int[] {
53              JavadocCommentsTokenTypes.PARAM_BLOCK_TAG,
54              JavadocCommentsTokenTypes.RETURN_BLOCK_TAG,
55              JavadocCommentsTokenTypes.THROWS_BLOCK_TAG,
56              JavadocCommentsTokenTypes.EXCEPTION_BLOCK_TAG,
57              JavadocCommentsTokenTypes.DEPRECATED_BLOCK_TAG,
58              JavadocCommentsTokenTypes.SINCE_BLOCK_TAG,
59          };
60      }
61  
62      /**
63       * Adds a set of tokens the check is interested in.
64       *
65       * @param strRep the string representation of the tokens interested in
66       * @propertySince 7.3
67       */
68      @Override
69      public void setJavadocTokens(String... strRep) {
70          super.setJavadocTokens(strRep);
71      }
72  
73      @Override
74      public void visitJavadocToken(DetailNode ast) {
75          if (isEmptyTag(ast)) {
76              log(ast.getLineNumber(), MSG_KEY);
77          }
78      }
79  
80      /**
81       * Tests if block tag is empty.
82       *
83       * @param tagNode block tag.
84       * @return true, if block tag is empty.
85       */
86      private static boolean isEmptyTag(DetailNode tagNode) {
87          final DetailNode tagDescription =
88                  JavadocUtil.findFirstToken(tagNode, JavadocCommentsTokenTypes.DESCRIPTION);
89          return tagDescription == null;
90      }
91  
92  }