
com.puppycrawl.tools.checkstyle.checks.javadoc.NonEmptyAtclauseDescriptionCheck Maven / Gradle / Ivy
///////////////////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code and other text files for adherence to a set of rules.
// Copyright (C) 2001-2024 the original author or authors.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
///////////////////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.checks.javadoc;
import com.puppycrawl.tools.checkstyle.StatelessCheck;
import com.puppycrawl.tools.checkstyle.api.DetailNode;
import com.puppycrawl.tools.checkstyle.api.JavadocTokenTypes;
import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
import com.puppycrawl.tools.checkstyle.utils.JavadocUtil;
/**
*
* Checks that the block tag is followed by description.
*
*
*
* -
* Property {@code violateExecutionOnNonTightHtml} - Control when to print violations
* if the Javadoc being examined by this check violates the tight html rules defined at
* Tight-HTML Rules.
* Type is {@code boolean}.
* Default value is {@code false}.
*
* -
* Property {@code javadocTokens} - javadoc tokens to check
* Type is {@code java.lang.String[]}.
* Validation type is {@code tokenSet}.
* Default value is
*
* PARAM_LITERAL,
*
* RETURN_LITERAL,
*
* THROWS_LITERAL,
*
* EXCEPTION_LITERAL,
*
* DEPRECATED_LITERAL.
*
*
*
*
* Parent is {@code com.puppycrawl.tools.checkstyle.TreeWalker}
*
*
*
* Violation Message Keys:
*
*
* -
* {@code javadoc.missed.html.close}
*
* -
* {@code javadoc.parse.rule.error}
*
* -
* {@code javadoc.unclosedHtml}
*
* -
* {@code javadoc.wrong.singleton.html.tag}
*
* -
* {@code non.empty.atclause}
*
*
*
* @since 6.0
*/
@StatelessCheck
public class NonEmptyAtclauseDescriptionCheck extends AbstractJavadocCheck {
/**
* A key is pointing to the warning message text in "messages.properties"
* file.
*/
public static final String MSG_KEY = "non.empty.atclause";
@Override
public int[] getDefaultJavadocTokens() {
return new int[] {
JavadocTokenTypes.PARAM_LITERAL,
JavadocTokenTypes.RETURN_LITERAL,
JavadocTokenTypes.THROWS_LITERAL,
JavadocTokenTypes.EXCEPTION_LITERAL,
JavadocTokenTypes.DEPRECATED_LITERAL,
};
}
@Override
public void visitJavadocToken(DetailNode ast) {
if (isEmptyTag(ast.getParent())) {
log(ast.getLineNumber(), MSG_KEY);
}
}
/**
* Tests if block tag is empty.
*
* @param tagNode block tag.
* @return true, if block tag is empty.
*/
private static boolean isEmptyTag(DetailNode tagNode) {
final DetailNode tagDescription =
JavadocUtil.findFirstToken(tagNode, JavadocTokenTypes.DESCRIPTION);
return tagDescription == null
|| hasOnlyEmptyText(tagDescription);
}
/**
* Tests if description node is empty (has only new lines and blank strings).
*
* @param description description node.
* @return true, if description node has only new lines and blank strings.
*/
private static boolean hasOnlyEmptyText(DetailNode description) {
boolean result = true;
for (DetailNode child : description.getChildren()) {
if (child.getType() != JavadocTokenTypes.LEADING_ASTERISK
&& !CommonUtil.isBlank(child.getText())) {
result = false;
break;
}
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy