001///////////////////////////////////////////////////////////////////////////////////////////////
002// checkstyle: Checks Java source code and other text files for adherence to a set of rules.
003// Copyright (C) 2001-2025 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     * @noinspection RedundantMethodOverride
060     * @noinspectionreason Display module's unique property version
061     */
062    @Override
063    public void setJavadocTokens(String... strRep) {
064        super.setJavadocTokens(strRep);
065    }
066
067    @Override
068    public void visitJavadocToken(DetailNode ast) {
069        if (isEmptyTag(ast)) {
070            log(ast.getLineNumber(), MSG_KEY);
071        }
072    }
073
074    /**
075     * Tests if block tag is empty.
076     *
077     * @param tagNode block tag.
078     * @return true, if block tag is empty.
079     */
080    private static boolean isEmptyTag(DetailNode tagNode) {
081        final DetailNode tagDescription =
082                JavadocUtil.findFirstToken(tagNode, JavadocCommentsTokenTypes.DESCRIPTION);
083        return tagDescription == null;
084    }
085
086}