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