001////////////////////////////////////////////////////////////////////////////////
002// checkstyle: Checks Java source code for adherence to a set of rules.
003// Copyright (C) 2001-2018 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.api.DetailNode;
023import com.puppycrawl.tools.checkstyle.api.JavadocTokenTypes;
024import com.puppycrawl.tools.checkstyle.utils.JavadocUtils;
025
026/**
027 * Checks that the at-clause tag is followed by description .
028 * Default configuration that will check {@code @param}, {@code @return},
029 * {@code @throws}, {@code @deprecated} to:
030 * <pre>
031 * &lt;module name=&quot;NonEmptyAtclauseDescription&quot;/&gt;
032 * </pre>
033 *
034 * @author maxvetrenko
035 *
036 */
037public class NonEmptyAtclauseDescriptionCheck extends AbstractJavadocCheck {
038
039    /**
040     * A key is pointing to the warning message text in "messages.properties"
041     * file.
042     */
043    public static final String MSG_KEY = "non.empty.atclause";
044
045    @Override
046    public int[] getDefaultJavadocTokens() {
047        return new int[] {
048            JavadocTokenTypes.PARAM_LITERAL,
049            JavadocTokenTypes.RETURN_LITERAL,
050            JavadocTokenTypes.THROWS_LITERAL,
051            JavadocTokenTypes.EXCEPTION_LITERAL,
052            JavadocTokenTypes.DEPRECATED_LITERAL,
053        };
054    }
055
056    @Override
057    public void visitJavadocToken(DetailNode ast) {
058        if (isEmptyTag(ast.getParent())) {
059            log(ast.getLineNumber(), MSG_KEY, ast.getText());
060        }
061    }
062
063    /**
064     * Tests if at-clause tag is empty.
065     * @param tagNode at-clause tag.
066     * @return true, if at-clause tag is empty.
067     */
068    private static boolean isEmptyTag(DetailNode tagNode) {
069        final DetailNode tagDescription =
070                JavadocUtils.findFirstToken(tagNode, JavadocTokenTypes.DESCRIPTION);
071        return tagDescription == null;
072    }
073
074}