View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2025 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      @Override
44      public int[] getDefaultJavadocTokens() {
45          return new int[] {
46              JavadocCommentsTokenTypes.PARAM_BLOCK_TAG,
47              JavadocCommentsTokenTypes.RETURN_BLOCK_TAG,
48              JavadocCommentsTokenTypes.THROWS_BLOCK_TAG,
49              JavadocCommentsTokenTypes.EXCEPTION_BLOCK_TAG,
50              JavadocCommentsTokenTypes.DEPRECATED_BLOCK_TAG,
51          };
52      }
53  
54      /**
55       * Adds a set of tokens the check is interested in.
56       *
57       * @param strRep the string representation of the tokens interested in
58       * @propertySince 7.3
59       * @noinspection RedundantMethodOverride
60       * @noinspectionreason Display module's unique property version
61       */
62      @Override
63      public void setJavadocTokens(String... strRep) {
64          super.setJavadocTokens(strRep);
65      }
66  
67      @Override
68      public void visitJavadocToken(DetailNode ast) {
69          if (isEmptyTag(ast)) {
70              log(ast.getLineNumber(), MSG_KEY);
71          }
72      }
73  
74      /**
75       * Tests if block tag is empty.
76       *
77       * @param tagNode block tag.
78       * @return true, if block tag is empty.
79       */
80      private static boolean isEmptyTag(DetailNode tagNode) {
81          final DetailNode tagDescription =
82                  JavadocUtil.findFirstToken(tagNode, JavadocCommentsTokenTypes.DESCRIPTION);
83          return tagDescription == null;
84      }
85  
86  }