001//////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code for adherence to a set of rules. 003// Copyright (C) 2001-2014 Oliver Burn 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//////////////////////////////////////////////////////////////////////////////// 019package com.puppycrawl.tools.checkstyle.checks.javadoc; 020 021import com.puppycrawl.tools.checkstyle.api.DetailNode; 022import com.puppycrawl.tools.checkstyle.api.JavadocTokenTypes; 023 024/** 025 * Checks that the at-clause tag is followed by description . 026 * Default configuration that will check <code>@param</code>, <code>@return</code>, 027 * <code>@throws</code>, <code>@deprecated</code> to: 028 * <pre> 029 * <module name="NonEmptyAtclauseDescription"/> 030 * </pre> 031 * <p> 032 * To check non-empty at-clause description for tags <code>@throws</code>, 033 * <code>@deprecated</code>, use following configuration: 034 * </p> 035 * <pre> 036 * <module name="NonEmptyAtclauseDescription"> 037 * <property name="target" value="JAVADOC_TAG_THROWS_LITERAL, 038 * JAVADOC_TAG_DEPRECATED_LITERAL"/> 039 * </module> 040 * </pre> 041 * 042 * @author maxvetrenko 043 * 044 */ 045public class NonEmptyAtclauseDescriptionCheck extends AbstractJavadocCheck 046{ 047 048 @Override 049 public int[] getDefaultJavadocTokens() 050 { 051 return new int[] { 052 JavadocTokenTypes.PARAM_LITERAL, 053 JavadocTokenTypes.RETURN_LITERAL, 054 JavadocTokenTypes.THROWS_LITERAL, 055 JavadocTokenTypes.DEPRECATED_LITERAL, 056 }; 057 } 058 059 @Override 060 public void visitJavadocToken(DetailNode ast) 061 { 062 if (isEmptyTag(ast.getParent())) { 063 log(ast.getLineNumber(), "non.empty.atclause", ast.getText()); 064 } 065 } 066 067 /** 068 * Tests if at-clause tag is empty. 069 * @param tagNode at-clause tag. 070 * @return true, if at-clause tag is empty. 071 */ 072 private boolean isEmptyTag(DetailNode tagNode) 073 { 074 final DetailNode tagDescription = 075 JavadocUtils.findFirstToken(tagNode, JavadocTokenTypes.DESCRIPTION); 076 return tagDescription == null; 077 } 078}