001/////////////////////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code and other text files for adherence to a set of rules. 003// Copyright (C) 2001-2026 the original author or authors. 004// 005// This library is free software; you can redistribute it and/or 006// modify it under the terms of the GNU Lesser General Public 007// License as published by the Free Software Foundation; either 008// version 2.1 of the License, or (at your option) any later version. 009// 010// This library is distributed in the hope that it will be useful, 011// but WITHOUT ANY WARRANTY; without even the implied warranty of 012// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013// Lesser General Public License for more details. 014// 015// You should have received a copy of the GNU Lesser General Public 016// License along with this library; if not, write to the Free Software 017// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 018/////////////////////////////////////////////////////////////////////////////////////////////// 019 020package com.puppycrawl.tools.checkstyle.checks.javadoc; 021 022import com.puppycrawl.tools.checkstyle.StatelessCheck; 023import com.puppycrawl.tools.checkstyle.api.DetailNode; 024import com.puppycrawl.tools.checkstyle.api.JavadocCommentsTokenTypes; 025import com.puppycrawl.tools.checkstyle.utils.JavadocUtil; 026 027/** 028 * <div> 029 * Checks that the block tag is followed by description. 030 * </div> 031 * 032 * @since 6.0 033 */ 034@StatelessCheck 035public class NonEmptyAtclauseDescriptionCheck extends AbstractJavadocCheck { 036 037 /** 038 * A key is pointing to the warning message text in "messages.properties" 039 * file. 040 */ 041 public static final String MSG_KEY = "non.empty.atclause"; 042 043 @Override 044 public int[] getDefaultJavadocTokens() { 045 return new int[] { 046 JavadocCommentsTokenTypes.PARAM_BLOCK_TAG, 047 JavadocCommentsTokenTypes.RETURN_BLOCK_TAG, 048 JavadocCommentsTokenTypes.THROWS_BLOCK_TAG, 049 JavadocCommentsTokenTypes.EXCEPTION_BLOCK_TAG, 050 JavadocCommentsTokenTypes.DEPRECATED_BLOCK_TAG, 051 }; 052 } 053 054 /** 055 * Adds a set of tokens the check is interested in. 056 * 057 * @param strRep the string representation of the tokens interested in 058 * @propertySince 7.3 059 */ 060 @Override 061 public void setJavadocTokens(String... strRep) { 062 super.setJavadocTokens(strRep); 063 } 064 065 @Override 066 public void visitJavadocToken(DetailNode ast) { 067 if (isEmptyTag(ast)) { 068 log(ast.getLineNumber(), MSG_KEY); 069 } 070 } 071 072 /** 073 * Tests if block tag is empty. 074 * 075 * @param tagNode block tag. 076 * @return true, if block tag is empty. 077 */ 078 private static boolean isEmptyTag(DetailNode tagNode) { 079 final DetailNode tagDescription = 080 JavadocUtil.findFirstToken(tagNode, JavadocCommentsTokenTypes.DESCRIPTION); 081 return tagDescription == null; 082 } 083 084}