001//////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code for adherence to a set of rules. 003// Copyright (C) 2001-2017 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.api.TokenTypes; 025import com.puppycrawl.tools.checkstyle.utils.JavadocUtils; 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 * @author maxvetrenko 036 * 037 */ 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.DEPRECATED_LITERAL, 053 }; 054 } 055 056 @Override 057 public int[] getAcceptableTokens() { 058 return new int[] {TokenTypes.BLOCK_COMMENT_BEGIN }; 059 } 060 061 @Override 062 public int[] getRequiredTokens() { 063 return getAcceptableTokens(); 064 } 065 066 @Override 067 public void visitJavadocToken(DetailNode ast) { 068 if (isEmptyTag(ast.getParent())) { 069 log(ast.getLineNumber(), MSG_KEY, ast.getText()); 070 } 071 } 072 073 /** 074 * Tests if at-clause tag is empty. 075 * @param tagNode at-clause tag. 076 * @return true, if at-clause tag is empty. 077 */ 078 private static boolean isEmptyTag(DetailNode tagNode) { 079 final DetailNode tagDescription = 080 JavadocUtils.findFirstToken(tagNode, JavadocTokenTypes.DESCRIPTION); 081 return tagDescription == null; 082 } 083}