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    /**
044     * Creates a new {@code NonEmptyAtclauseDescriptionCheck} instance.
045     */
046    public NonEmptyAtclauseDescriptionCheck() {
047        // no code by default
048    }
049
050    @Override
051    public int[] getDefaultJavadocTokens() {
052        return new int[] {
053            JavadocCommentsTokenTypes.PARAM_BLOCK_TAG,
054            JavadocCommentsTokenTypes.RETURN_BLOCK_TAG,
055            JavadocCommentsTokenTypes.THROWS_BLOCK_TAG,
056            JavadocCommentsTokenTypes.EXCEPTION_BLOCK_TAG,
057            JavadocCommentsTokenTypes.DEPRECATED_BLOCK_TAG,
058        };
059    }
060
061    /**
062     * Adds a set of tokens the check is interested in.
063     *
064     * @param strRep the string representation of the tokens interested in
065     * @propertySince 7.3
066     */
067    @Override
068    public void setJavadocTokens(String... strRep) {
069        super.setJavadocTokens(strRep);
070    }
071
072    @Override
073    public void visitJavadocToken(DetailNode ast) {
074        if (isEmptyTag(ast)) {
075            log(ast.getLineNumber(), MSG_KEY);
076        }
077    }
078
079    /**
080     * Tests if block tag is empty.
081     *
082     * @param tagNode block tag.
083     * @return true, if block tag is empty.
084     */
085    private static boolean isEmptyTag(DetailNode tagNode) {
086        final DetailNode tagDescription =
087                JavadocUtil.findFirstToken(tagNode, JavadocCommentsTokenTypes.DESCRIPTION);
088        return tagDescription == null;
089    }
090
091}