Skip to content
Commits on Source (5)
......@@ -134,6 +134,7 @@ blockcommentstyle
blockquote
blog
blogspot
Bludov
bluej
bluejcheckstyle
BNOT
......@@ -627,6 +628,7 @@ jarchitect
javac
javadoc
javadocblocktaglocation
javadoccontentlocation
javadocdetailnodeparser
javadocmethod
javadocpackage
......@@ -994,6 +996,7 @@ pathelement
patreon
Paulicke
paypal
pbludov
pdf
Peclipse
perl
......
......@@ -111,14 +111,8 @@ jdk12-assembly-site)
;;
jdk12-verify-limited)
# powermock doesn't support modifying final fields in JDK12, so need jacoco skip
exclude1="!FileContentsTest#testGetJavadocBefore,"
exclude2="!MainFrameModelPowerTest#testOpenFileWithUnknownParseMode,"
exclude3="!TokenUtilTest#testTokenValueIncorrect2,"
exclude4="!ImportControlLoaderPowerTest#testInputStreamThatFailsOnClose"
# we skip pmd and spotbugs as they executed in special Travis build
mvn -e verify -Dtest=*,$exclude1$exclude2$exclude3$exclude4 -Djacoco.skip=true \
-Dpmd.skip=true -Dspotbugs.skip=true
mvn -e verify -Dpmd.skip=true -Dspotbugs.skip=true
;;
nondex)
......
......@@ -37,6 +37,9 @@ no-error-orekit)
echo CS_version: ${CS_POM_VERSION}
checkout_from https://github.com/Hipparchus-Math/hipparchus.git
cd .ci-temp/hipparchus
# checkout to version that Orekit expects
SHA_HIPPARCHUS="4c6c6fc45e859e""ae2d4eb091a3a3c0a7a458b8d9"
git checkout $SHA_HIPPARCHUS
mvn install -DskipTests
cd -
checkout_from https://github.com/CS-SI/Orekit.git
......@@ -44,7 +47,7 @@ no-error-orekit)
# no CI is enforced in project, so to make our build stable we should
# checkout to latest release/development (annotated tag or hash)
# git checkout $(git describe --abbrev=0 --tags)
git checkout 3a9787ec3f166bd770f9c119cd7724f57
git checkout 973d1bd3e4532d2c1d3a7c28136e2713bd057542
mvn -e compile checkstyle:check -Dorekit.checkstyle.version=${CS_POM_VERSION}
cd ../
rm -rf Orekit
......@@ -91,7 +94,7 @@ no-error-hibernate-search)
echo CS_version: ${CS_POM_VERSION}
checkout_from https://github.com/hibernate/hibernate-search.git
cd .ci-temp/hibernate-search
mvn -e clean install -DskipTests=true -Dtest.elasticsearch.host.provided=true \
mvn -e clean install -DskipTests=true -Dtest.elasticsearch.run.skip=true \
-Dcheckstyle.skip=true -Dforbiddenapis.skip=true \
-Dpuppycrawl.checkstyle.version=${CS_POM_VERSION}
mvn -e checkstyle:check -Dpuppycrawl.checkstyle.version=${CS_POM_VERSION}
......
......@@ -471,6 +471,7 @@
<!-- additional tags used in the project -->
<property name="tags" value="noinspection"/>
</module>
<module name="JavadocContentLocation"/>
<module name="JavadocMethod">
<property name="allowUndeclaredRTE" value="true"/>
<property name="allowThrowsTagsForSubclasses" value="true"/>
......
......@@ -173,7 +173,7 @@
<!-- This inherited from GeneratedJavaLexer. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@Image='AssertGeneratedJavaLexer']
//MethodDeclarator[@Image='LA']"/>
//MethodDeclaration[@Name='LA']"/>
</properties>
</rule>
......@@ -186,9 +186,9 @@
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[
@Image='SuppressionXpathSingleFilterTest']
//MethodDeclarator[@Image='createSuppressionXpathSingleFilter']
//MethodDeclaration[@Name='createSuppressionXpathSingleFilter']
| //ClassOrInterfaceDeclaration[ @Image='XdocsPagesTest']
//MethodDeclarator[@Image='validateRuleNameOrder']"/>
//MethodDeclaration[@Name='validateRuleNameOrder']"/>
</properties>
</rule>
<rule ref="category/java/errorprone.xml/CloseResource">
......
......@@ -75,7 +75,7 @@
<!-- It is possible only in functional languages and fanatically-pristine code, without
additional option that are done at ReturnCountExtendedCheck it is not a good rule. -->
<exclude name="OnlyOneReturn"/>
<!-- We use CheckstyleCustomShortVariable, to control the length and skip Override methods. -->
<!-- it is not easily configurable we use our Check to cover our needs -->
<exclude name="ShortVariable"/>
<!-- huge amount of false positives from 6.18.0 -->
<exclude name="UnnecessaryFullyQualifiedName"/>
......@@ -110,15 +110,15 @@
<!-- False positives on IF_ELSE-IF-ELSE-IF. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@Image='XMLLogger']
//MethodDeclarator[@Image='isReference']
//MethodDeclaration[@Name='isReference']
| //ClassOrInterfaceDeclaration[@Image='DetailAstImpl']
//MethodDeclarator[@Image='addPreviousSibling']
//MethodDeclaration[@Name='addPreviousSibling']
| //ClassOrInterfaceDeclaration[@Image='AnnotationLocationCheck']
//MethodDeclarator[@Image='checkAnnotations']
//MethodDeclaration[@Name='checkAnnotations']
| //ClassOrInterfaceDeclaration[@Image='AbstractImportControl']
//MethodDeclarator[@Image='checkAccess']
//MethodDeclaration[@Name='checkAccess']
| //ClassOrInterfaceDeclaration[@Image='HandlerFactory']
//MethodDeclarator[@Image='getHandler']"/>
//MethodDeclaration[@Name='getHandler']"/>
</properties>
</rule>
<rule ref="category/java/codestyle.xml/EmptyMethodInAbstractClassShouldBeAbstract">
......@@ -231,7 +231,7 @@
<property name="problemDepth" value="4"/>
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@Image='ClassResolver']
//MethodDeclarator[@Image='resolve']"/>
//MethodDeclaration[@Name='resolve']"/>
</properties>
</rule>
<rule ref="category/java/design.xml/AvoidThrowingRawExceptionTypes">
......@@ -398,7 +398,7 @@
modifier. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@Image='UniqueProperties'
or @Image='SequencedProperties']//MethodDeclarator[@Image='keys' or @Image='put']"/>
or @Image='SequencedProperties']//MethodDeclaration[@Name='keys' or @Name='put']"/>
</properties>
</rule>
......@@ -408,32 +408,4 @@
<!-- Not configurable, decreases readability. -->
<exclude name="UseStringBufferForStringAppends"/>
</rule>
<!-- Checkstyle own rules. -->
<rule name="CheckstyleCustomShortVariable"
message="Avoid variables with short names that shorter than 2 symbols: {0}"
language="java"
class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="">
<description>
Fields, local variables, or parameter names that are very short are not helpful to the reader.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//VariableDeclaratorId[string-length(@Image) < 2]
[not(ancestor::ForInit)]
[not(../../VariableDeclarator and ../../../LocalVariableDeclaration
and ../../../../ForStatement)]
[not((ancestor::FormalParameter) and (ancestor::TryStatement))]
[not(ancestor::ClassOrInterfaceDeclaration[
//MarkerAnnotation/Name[pmd-java:typeIs('java.lang.Override')]])]
]]>
</value>
</property>
</properties>
</rule>
</ruleset>
checkstyle (8.27-1) unstable; urgency=medium
* Team upload
* New upstream version 8.27
* Specify debhelper compat via debhelper-compat dependency
* checkstyle-doc is now marked Multi-Arch: foreign
* Set "Rules-Requires-Root: no" in debian/control
-- tony mancill <tmancill@debian.org> Sun, 08 Dec 2019 14:05:05 -0800
checkstyle (8.26-1) unstable; urgency=medium
* Team upload
......
......@@ -7,7 +7,7 @@ Build-Depends:
ant-optional,
antlr (>= 2.7.6),
antlr4-maven-plugin,
debhelper (>= 12),
debhelper-compat (= 12),
default-jdk,
default-jdk-doc,
javahelper,
......@@ -29,6 +29,7 @@ Standards-Version: 4.4.1
Vcs-Git: https://salsa.debian.org/java-team/checkstyle.git
Vcs-Browser: https://salsa.debian.org/java-team/checkstyle
Homepage: http://checkstyle.sourceforge.net
Rules-Requires-Root: no
Package: checkstyle
Architecture: all
......@@ -56,6 +57,7 @@ Description: checks Java source against a coding standard
Package: checkstyle-doc
Architecture: all
Multi-Arch: foreign
Section: doc
Depends: ${misc:Depends}
Suggests: default-jdk-doc
......
......@@ -13,7 +13,7 @@
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.26</version>
<version>8.27</version>
<packaging>jar</packaging>
<name>checkstyle</name>
......@@ -45,6 +45,13 @@
<role>project admin, developer</role>
</roles>
</developer>
<developer>
<id>pbludov</id>
<name>Pavel Bludov</name>
<roles>
<role>developer</role>
</roles>
</developer>
<developer>
<id>sabaka</id>
<name>Ilja Dubinin</name>
......@@ -196,14 +203,14 @@
<maven.site.plugin.version>3.8.2</maven.site.plugin.version>
<maven.spotbugs.plugin.version>3.1.12.2</maven.spotbugs.plugin.version>
<maven.pmd.plugin.version>3.12.0</maven.pmd.plugin.version>
<pmd.version>6.18.0</pmd.version>
<pmd.version>6.19.0</pmd.version>
<maven.jacoco.plugin.version>0.8.5</maven.jacoco.plugin.version>
<powermock.version>2.0.4</powermock.version>
<saxon.version>9.9.1-5</saxon.version>
<maven.checkstyle.plugin.version>3.1.0</maven.checkstyle.plugin.version>
<maven.sevntu.checkstyle.plugin.version>1.35.0</maven.sevntu.checkstyle.plugin.version>
<maven.sevntu.checkstyle.plugin.version>1.36.0</maven.sevntu.checkstyle.plugin.version>
<maven.sevntu-checkstyle-check.checkstyle.version>
8.18
8.26
</maven.sevntu-checkstyle-check.checkstyle.version>
<maven.versions.plugin.version>2.7</maven.versions.plugin.version>
<java.version>1.8</java.version>
......@@ -227,7 +234,7 @@
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>4.0.4</version>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>antlr</groupId>
......@@ -302,7 +309,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.28</version>
<version>1.7.29</version>
<scope>test</scope>
</dependency>
<dependency>
......@@ -338,7 +345,7 @@
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<version>3.2.0</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
......@@ -973,7 +980,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M2</version>
<version>3.0.0-M3</version>
<executions>
<execution>
<id>enforce-versions</id>
......@@ -1190,7 +1197,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
......@@ -2098,6 +2105,10 @@
<targetTests>
<param>com.puppycrawl.tools.checkstyle.checks.imports.*</param>
</targetTests>
<excludedMethods>
<!-- unkilled in generated code https://github.com/hcoles/pitest/issues/255 -->
<param>loadUri</param>
</excludedMethods>
<excludedTestClasses>
<param>*.Input*</param>
</excludedTestClasses>
......@@ -2951,6 +2962,10 @@
<targetClasses>
<param>com.puppycrawl.tools.checkstyle.utils.*</param>
</targetClasses>
<excludedMethods>
<!-- unkilled in generated code https://github.com/hcoles/pitest/issues/255 -->
<param>isFileExists</param>
</excludedMethods>
<targetTests>
<param>com.puppycrawl.tools.checkstyle.utils.*</param>
<!-- 12% mutation in CommonUtil,
......
......@@ -624,6 +624,8 @@ public class PackageObjectFactory implements ModuleFactory {
BASE_PACKAGE + ".checks.javadoc.InvalidJavadocPositionCheck");
NAME_TO_FULL_MODULE_NAME.put("JavadocBlockTagLocationCheck",
BASE_PACKAGE + ".checks.javadoc.JavadocBlockTagLocationCheck");
NAME_TO_FULL_MODULE_NAME.put("JavadocContentLocationCheck",
BASE_PACKAGE + ".checks.javadoc.JavadocContentLocationCheck");
NAME_TO_FULL_MODULE_NAME.put("JavadocMethodCheck",
BASE_PACKAGE + ".checks.javadoc.JavadocMethodCheck");
NAME_TO_FULL_MODULE_NAME.put("JavadocPackageCheck",
......
......@@ -615,7 +615,7 @@ public class RequireThisCheck extends AbstractCheck {
final DetailAST prevSibling = ast.getPreviousSibling();
if (variableDeclarationFrameType == FrameType.CLASS_FRAME
&& !validateOnlyOverlapping
&& prevSibling == null
&& (prevSibling == null || ast.getParent().getType() != TokenTypes.DOT)
&& canBeReferencedFromStaticContext(ast)) {
frameWhereViolationIsFound = variableDeclarationFrame;
}
......
......@@ -22,7 +22,6 @@ package com.puppycrawl.tools.checkstyle.checks.coding;
import com.puppycrawl.tools.checkstyle.StatelessCheck;
/**
*
* <p>
* Checks that an overriding {@code clone()} method invokes {@code super.clone()}.
* Does not check native methods, as they have no possible java defined implementation.
......
......@@ -285,10 +285,12 @@ public class IllegalImportCheck
*/
private String[] illegalPkgs;
/** Specify class names to reject, if <b>regexp</b> property is not set,
/**
* Specify class names to reject, if <b>regexp</b> property is not set,
* checks if import equals class name. If <b>regexp</b> property is set,
* then list of class names will be interpreted as regular expressions.
* Note, all properties for match will be used. */
* Note, all properties for match will be used.
*/
private String[] illegalClasses;
/**
......
......@@ -248,16 +248,7 @@ public final class ImportControlLoader extends XmlLoader {
* @throws CheckstyleException if an error occurs.
*/
public static PkgImportControl load(URI uri) throws CheckstyleException {
try (InputStream inputStream = uri.toURL().openStream()) {
final InputSource source = new InputSource(inputStream);
return load(source, uri);
}
catch (MalformedURLException ex) {
throw new CheckstyleException("syntax error in url " + uri, ex);
}
catch (IOException ex) {
throw new CheckstyleException("unable to find " + uri, ex);
}
return loadUri(uri);
}
/**
......@@ -283,6 +274,25 @@ public final class ImportControlLoader extends XmlLoader {
}
}
/**
* Loads the import control file from a URI.
* @param uri the uri of the file to load.
* @return the root {@link PkgImportControl} object.
* @throws CheckstyleException if an error occurs.
*/
private static PkgImportControl loadUri(URI uri) throws CheckstyleException {
try (InputStream inputStream = uri.toURL().openStream()) {
final InputSource source = new InputSource(inputStream);
return load(source, uri);
}
catch (MalformedURLException ex) {
throw new CheckstyleException("syntax error in url " + uri, ex);
}
catch (IOException ex) {
throw new CheckstyleException("unable to find " + uri, ex);
}
}
/**
* Returns root PkgImportControl.
* @return the root {@link PkgImportControl} object loaded.
......
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2019 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 java.util.Locale;
import com.puppycrawl.tools.checkstyle.StatelessCheck;
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.utils.JavadocUtil;
/**
* <p>
* Checks that the Javadoc content begins from the same position
* for all Javadoc comments in the project. Any leading asterisks and spaces
* are not counted as the beginning of the content and are therefore ignored.
* </p>
* <p>
* It is possible to enforce two different styles:
* </p>
* <ul>
* <li>
* {@code first_line} - Javadoc content starts from the first line:
* <pre>
* &#47;** Summary text.
* * More details.
* *&#47;
* public void method();
* </pre>
* </li>
* <li>
* {@code second_line} - Javadoc content starts from the second line:
* <pre>
* &#47;**
* * Summary text.
* * More details.
* *&#47;
* public void method();
* </pre>
* </li>
* </ul>
* <p>
* This check does not validate the Javadoc summary itself nor its presence.
* The check will not report any violations for missing or malformed javadoc summary.
* To validate the Javadoc summary use
* <a href="https://checkstyle.org/config_javadoc.html#SummaryJavadoc">SummaryJavadoc</a> check.
* </p>
* <p>
* The <a href="https://docs.oracle.com/en/java/javase/11/docs/specs/doc-comment-spec.html">
* Documentation Comment Specification</a> permits leading asterisks on the first line.
* For these Javadoc comments:
* </p>
* <pre>
* &#47;***
* * Some text.
* *&#47;
* &#47;************
* * Some text.
* *&#47;
* &#47;** **
* * Some text.
* *&#47;
* </pre>
* <p>
* The documentation generated will be just "Some text." without any asterisks.
* Since these asterisks will not appear in the generated documentation,
* they should not be considered as the beginning of the Javadoc content.
* In such cases, the check assumes that the Javadoc content begins on the second line.
* </p>
* <ul>
* <li>
* Property {@code location} - Specify the policy on placement of the Javadoc content.
* Default value is {@code second_line}.
* </li>
* </ul>
* <p>
* By default Check validate that the Javadoc content starts from the second line:
* </p>
* <pre>
* &lt;module name="JavadocContentLocationCheck"/&gt;
* </pre>
* <p>
* This setting produces a violation for each multi-line comment starting
* on the same line as the initial asterisks:
* </p>
* <pre>
* &#47;** This comment causes a violation because it starts from the first line
* * and spans several lines.
* *&#47;
* &#47;**
* * This comment is OK because it starts from the second line.
* *&#47;
* &#47;** This comment is OK because it is on the single line. *&#47;
*</pre>
* <p>
* To ensure that Javadoc content starts from the first line:
* </p>
* <pre>
* &lt;module name="JavadocContentLocationCheck"&gt;
* &lt;property name="location" value="first_line"/&gt;
* &lt;/module&gt;
* </pre>
* <p>
* This setting produces a violation for each comment not
* starting on the same line as the initial asterisks:
* </p>
* <pre>
* &#47;** This comment is OK because it starts on the first line.
* * There may be additional text.
* *&#47;
* &#47;**
* * This comment causes a violation because it starts on the second line.
* *&#47;
* &#47;** This single-line comment also is OK. *&#47;
* </pre>
*
* @since 8.27
*/
@StatelessCheck
public class JavadocContentLocationCheck extends AbstractCheck {
/**
* A key is pointing to the warning message text in "messages.properties" file.
*/
public static final String MSG_JAVADOC_CONTENT_FIRST_LINE = "javadoc.content.first.line";
/**
* A key is pointing to the warning message text in "messages.properties" file.
*/
public static final String MSG_JAVADOC_CONTENT_SECOND_LINE = "javadoc.content.second.line";
/**
* Specify the policy on placement of the Javadoc content.
*/
private JavadocContentLocationOption location = JavadocContentLocationOption.SECOND_LINE;
@Override
public int[] getRequiredTokens() {
return new int[] {
TokenTypes.BLOCK_COMMENT_BEGIN,
};
}
@Override
public int[] getAcceptableTokens() {
return getRequiredTokens();
}
@Override
public int[] getDefaultTokens() {
return getRequiredTokens();
}
@Override
public boolean isCommentNodesRequired() {
return true;
}
/**
* Setter to specify the policy on placement of the Javadoc content.
*
* @param value string to decode location from
* @throws IllegalArgumentException if unable to decode
*/
public void setLocation(String value) {
location = JavadocContentLocationOption.valueOf(value.trim().toUpperCase(Locale.ENGLISH));
}
@Override
public void visitToken(DetailAST ast) {
if (isMultilineComment(ast) && JavadocUtil.isJavadocComment(ast)) {
final String commentContent = JavadocUtil.getJavadocCommentContent(ast);
final int indexOfFirstNonBlankLine = findIndexOfFirstNonBlankLine(commentContent);
if (indexOfFirstNonBlankLine >= 0) {
if (location == JavadocContentLocationOption.FIRST_LINE) {
if (indexOfFirstNonBlankLine != 0) {
log(ast, MSG_JAVADOC_CONTENT_FIRST_LINE);
}
}
else if (indexOfFirstNonBlankLine != 1) {
log(ast, MSG_JAVADOC_CONTENT_SECOND_LINE);
}
}
}
}
/**
* Checks if a DetailAST of type {@code TokenTypes.BLOCK_COMMENT_BEGIN} span
* more than one line. The node always has at least one child of the type
* {@code TokenTypes.BLOCK_COMMENT_END}.
*
* @param node node to check
* @return {@code true} for multi-line comment nodes
*/
private static boolean isMultilineComment(DetailAST node) {
return node.getLineNo() != node.getLastChild().getLineNo();
}
/**
* Returns the index of the first non-blank line.
* All lines consists only of asterisks and whitespaces are treated as blank.
*
* @param commentContent Javadoc content to process
* @return the index of the first non-blank line or {@code -1} if all lines are blank
*/
private static int findIndexOfFirstNonBlankLine(String commentContent) {
int lineNo = 0;
boolean noContent = true;
for (int i = 0; i < commentContent.length(); ++i) {
final char character = commentContent.charAt(i);
if (character == '\n') {
++lineNo;
}
else if (character != '*' && !Character.isWhitespace(character)) {
noContent = false;
break;
}
}
if (noContent) {
lineNo = -1;
}
return lineNo;
}
}
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2019 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;
/**
* Represents the locations for the javadoc content.
*/
public enum JavadocContentLocationOption {
/**
* Represents a policy for the location of content starting from
* the same line as {@code /**}.
* Example:
* <pre>
* &#47;** Summary text.
* * More details.
* *&#47;
* public void method();
* </pre>
* This style is also known as "scala" style.
*/
FIRST_LINE,
/**
* Represents a policy for the location of content starting from
* the next line after {@code /**}.
* Example:
* <pre>
* &#47;**
* * Summary text.
* * More details.
* *&#47;
* public void method();
* </pre>
* This style is common to java projects.
*/
SECOND_LINE,
}
......@@ -48,7 +48,163 @@ import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
import com.puppycrawl.tools.checkstyle.utils.ScopeUtil;
/**
* Checks the Javadoc of a method or constructor.
* <p>
* Checks the Javadoc of a method or constructor. By default,
* check does not validate methods and constructors for unused throws.
* To allow documented exceptions derived from {@code java.lang.RuntimeException}
* that are not declared, set property {@code allowUndeclaredRTE} to true.
* The scope to verify is specified using the {@code Scope} class and defaults
* to {@code Scope.PRIVATE}. To verify another scope, set property scope to
* a different <a href="https://checkstyle.org/property_types.html#scope">scope</a>.
* </p>
* <p>
* Violates parameters and type parameters for which no param tags are present
* can be suppressed by defining property {@code allowMissingParamTags}.
* Violates exceptions which are declared to be thrown, but for which no throws
* tag is present can be suppressed by defining property {@code allowMissingThrowsTags}.
* Violates methods which return non-void but for which no return tag is present
* can be suppressed by defining property {@code allowMissingReturnTag}.
* </p>
* <p>
* Javadoc is not required on a method that is tagged with the {@code @Override}
* annotation. However under Java 5 it is not possible to mark a method required
* for an interface (this was <i>corrected</i> under Java 6). Hence Checkstyle
* supports using the convention of using a single {@code {@inheritDoc}} tag
* instead of all the other tags.
* </p>
* <p>
* Note that only inheritable items will allow the {@code {@inheritDoc}}
* tag to be used in place of comments. Static methods at all visibilities,
* private non-static methods and constructors are not inheritable.
* </p>
* <p>
* For example, if the following method is implementing a method required by
* an interface, then the Javadoc could be done as:
* </p>
* <pre>
* &#47;** {&#64;inheritDoc} *&#47;
* public int checkReturnTag(final int aTagIndex,
* JavadocTag[] aTags,
* int aLineNo)
* </pre>
* <p>
* The classpath may need to be configured to locate the class information.
* The classpath configuration is dependent on the mechanism used to invoke Checkstyle.
* </p>
* <ul>
* <li>
* Property {@code allowedAnnotations} - Specify the list of annotations
* that allow missed documentation.
* Default value is {@code Override}.
* </li>
* <li>
* Property {@code validateThrows} - Control whether to validate {@code throws} tags.
* Default value is {@code false}.
* </li>
* <li>
* Property {@code scope} - Specify the visibility scope where Javadoc comments are checked.
* Default value is {@code private}.
* </li>
* <li>
* Property {@code excludeScope} - Specify the visibility scope where Javadoc comments
* are not checked.
* Default value is {@code null}.
* </li>
* <li>
* Property {@code allowUndeclaredRTE} - Control whether to allow documented exceptions
* that are not declared if they are a subclass of {@code java.lang.RuntimeException}.
* Default value is {@code false}.
* </li>
* <li>
* Property {@code allowThrowsTagsForSubclasses} - Control whether to allow
* documented exceptions that are subclass of one of declared exception.
* Default value is {@code false}.
* </li>
* <li>
* Property {@code allowMissingParamTags} - Control whether to ignore violations
* when a method has parameters but does not have matching {@code param} tags in the javadoc.
* Default value is {@code false}.
* </li>
* <li>
* Property {@code allowMissingThrowsTags} - Control whether to ignore violations
* when a method declares that it throws exceptions but does not have matching
* {@code throws} tags in the javadoc.
* Default value is {@code false}.
* </li>
* <li>
* Property {@code allowMissingReturnTag} - Control whether to ignore violations
* when a method returns non-void type and does not have a {@code return} tag in the javadoc.
* Default value is {@code false}.
* </li>
* <li>
* Property {@code logLoadErrors} - Control checkstyle's error handling when
* a class loading fails. This check may need to load exception classes mentioned
* in the {@code @throws} tag to check whether they are RuntimeExceptions.
* If set to {@code false} a classpath configuration problem is assumed and
* the TreeWalker stops operating on the class completely. If set to {@code true}
* (the default), checkstyle assumes a typo or refactoring problem in the javadoc
* and logs the problem in the normal checkstyle report (potentially masking
* a configuration error).
* Default value is {@code true}.
* </li>
* <li>
* Property {@code suppressLoadErrors} - Control whether to suppress violations
* when a class loading fails. When logLoadErrors is set to true, the TreeWalker
* completely processes a class and displays any problems with loading exceptions
* as checkstyle violations. When this property is set to true, the violations
* generated when logLoadErrors is set true are suppressed from being reported as
* violations in the checkstyle report.
* Default value is {@code false}.
* </li>
* <li>
* Property {@code tokens} - tokens to check Default value is:
* <a href="https://checkstyle.org/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_DEF">
* METHOD_DEF</a>,
* <a href="https://checkstyle.org/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CTOR_DEF">
* CTOR_DEF</a>,
* <a href="https://checkstyle.org/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ANNOTATION_FIELD_DEF">
* ANNOTATION_FIELD_DEF</a>.
* </li>
* </ul>
* <p>
* To configure the default check:
* </p>
* <pre>
* &lt;module name="JavadocMethod"/&gt;
* </pre>
* <p>
* To configure the check for {@code public} scope and to allow documentation
* of undeclared RuntimeExceptions:
* </p>
* <pre>
* &lt;module name="JavadocMethod"&gt;
* &lt;property name="scope" value="public"/&gt;
* &lt;property name="allowUndeclaredRTE" value="true"/&gt;
* &lt;/module&gt;
* </pre>
* <p>
* To configure the check for for {@code public} scope, to allow documentation
* of undeclared RuntimeExceptions, while ignoring any missing param tags is:
* </p>
* <pre>
* &lt;module name="JavadocMethod"&gt;
* &lt;property name="scope" value="public"/&gt;
* &lt;property name="allowUndeclaredRTE" value="true"/&gt;
* &lt;property name="allowMissingParamTags" value="true"/&gt;
* &lt;/module&gt;
* </pre>
* <p>
* To configure the check for methods which are in {@code private},
* but not in {@code protected} scope:
* </p>
* <pre>
* &lt;module name="JavadocMethod"&gt;
* &lt;property name="scope" value="private"/&gt;
* &lt;property name="excludeScope" value="protected"/&gt;
* &lt;/module&gt;
* </pre>
*
* @since 3.0
*/
@FileStatefulCheck
public class JavadocMethodCheck extends AbstractCheck {
......@@ -98,14 +254,14 @@ public class JavadocMethodCheck extends AbstractCheck {
/** Compiled regexp to match Javadoc tags that take an argument. */
private static final Pattern MATCH_JAVADOC_ARG = CommonUtil.createPattern(
"^\\s*(?>\\*|\\/\\*\\*)?\\s*@(throws|exception|param)\\s+(\\S+)\\s+\\S*");
/** Compiled regexp to match first part of multilineJavadoc tags. */
private static final Pattern MATCH_JAVADOC_ARG_MULTILINE_START = CommonUtil.createPattern(
"^\\s*(?>\\*|\\/\\*\\*)?\\s*@(throws|exception|param)\\s+(\\S+)\\s*$");
/** Compiled regexp to match Javadoc tags with argument but with missing description. */
private static final Pattern MATCH_JAVADOC_ARG_MISSING_DESCRIPTION =
CommonUtil.createPattern("^\\s*(?>\\*|\\/\\*\\*)?\\s*@(throws|exception|param)\\s+"
+ "(\\S[^*]*)(?:(\\s+|\\*\\/))?");
/** Compiled regexp to look for a continuation of the comment. */
private static final Pattern MATCH_JAVADOC_MULTILINE_CONT =
CommonUtil.createPattern("(\\*/|@|[^\\s\\*])");
CommonUtil.createPattern("(\\*\\/|@|[^\\s\\*])");
/** Multiline finished at end of comment. */
private static final String END_JAVADOC = "*/";
......@@ -137,55 +293,55 @@ public class JavadocMethodCheck extends AbstractCheck {
/** {@code ClassResolver} instance for current tree. */
private ClassResolver classResolver;
/** The visibility scope where Javadoc comments are checked. */
/** Specify the visibility scope where Javadoc comments are checked. */
private Scope scope = Scope.PRIVATE;
/** The visibility scope where Javadoc comments shouldn't be checked. */
/** Specify the visibility scope where Javadoc comments are not checked. */
private Scope excludeScope;
/**
* Controls whether to allow documented exceptions that are not declared if
* they are a subclass of java.lang.RuntimeException.
* Control whether to allow documented exceptions that are not declared if
* they are a subclass of {@code java.lang.RuntimeException}.
*/
// -@cs[AbbreviationAsWordInName] We can not change it as,
// check's property is part of API (used in configurations).
private boolean allowUndeclaredRTE;
/**
* Allows validating throws tags.
* Control whether to validate {@code throws} tags.
*/
private boolean validateThrows;
/**
* Controls whether to allow documented exceptions that are subclass of one
* of declared exception. Defaults to false (backward compatibility).
* Control whether to allow documented exceptions that are subclass of one
* of declared exception.
*/
private boolean allowThrowsTagsForSubclasses;
/**
* Controls whether to ignore violations when a method has parameters but does
* not have matching param tags in the javadoc. Defaults to false.
* Control whether to ignore violations when a method has parameters but does
* not have matching {@code param} tags in the javadoc.
*/
private boolean allowMissingParamTags;
/**
* Controls whether to ignore violations when a method declares that it throws
* exceptions but does not have matching throws tags in the javadoc.
* Defaults to false.
* Control whether to ignore violations when a method declares that it throws
* exceptions but does not have matching {@code throws} tags in the javadoc.
*/
private boolean allowMissingThrowsTags;
/**
* Controls whether to ignore violations when a method returns non-void type
* but does not have a return tag in the javadoc. Defaults to false.
* Control whether to ignore violations when a method returns non-void type
* and does not have a {@code return} tag in the javadoc.
*/
private boolean allowMissingReturnTag;
/** List of annotations that allow missed documentation. */
/** Specify the list of annotations that allow missed documentation. */
private List<String> allowedAnnotations = Collections.singletonList("Override");
/**
* Allow validating throws tag.
* Setter to control whether to validate {@code throws} tags.
*
* @param value user's value.
*/
public void setValidateThrows(boolean value) {
......@@ -193,7 +349,8 @@ public class JavadocMethodCheck extends AbstractCheck {
}
/**
* Sets list of annotations.
* Setter to specify the list of annotations that allow missed documentation.
*
* @param userAnnotations user's value.
*/
public void setAllowedAnnotations(String... userAnnotations) {
......@@ -201,7 +358,7 @@ public class JavadocMethodCheck extends AbstractCheck {
}
/**
* Set the scope.
* Setter to specify the visibility scope where Javadoc comments are checked.
*
* @param scope a scope.
*/
......@@ -210,7 +367,7 @@ public class JavadocMethodCheck extends AbstractCheck {
}
/**
* Set the excludeScope.
* Setter to specify the visibility scope where Javadoc comments are not checked.
*
* @param excludeScope a scope.
*/
......@@ -219,8 +376,8 @@ public class JavadocMethodCheck extends AbstractCheck {
}
/**
* Controls whether to allow documented exceptions that are not declared if
* they are a subclass of java.lang.RuntimeException.
* Setter to control whether to allow documented exceptions that are not declared if
* they are a subclass of {@code java.lang.RuntimeException}.
*
* @param flag a {@code Boolean} value
*/
......@@ -231,8 +388,8 @@ public class JavadocMethodCheck extends AbstractCheck {
}
/**
* Controls whether to allow documented exception that are subclass of one
* of declared exceptions.
* Setter to control whether to allow documented exceptions that are subclass of one
* of declared exception.
*
* @param flag a {@code Boolean} value
*/
......@@ -241,8 +398,8 @@ public class JavadocMethodCheck extends AbstractCheck {
}
/**
* Controls whether to allow a method which has parameters to omit matching
* param tags in the javadoc. Defaults to false.
* Setter to control whether to ignore violations when a method has parameters
* but does not have matching {@code param} tags in the javadoc.
*
* @param flag a {@code Boolean} value
*/
......@@ -251,9 +408,8 @@ public class JavadocMethodCheck extends AbstractCheck {
}
/**
* Controls whether to allow a method which declares that it throws
* exceptions to omit matching throws tags in the javadoc. Defaults to
* false.
* Setter to control whether to ignore violations when a method declares that it throws
* exceptions but does not have matching {@code throws} tags in the javadoc.
*
* @param flag a {@code Boolean} value
*/
......@@ -262,8 +418,8 @@ public class JavadocMethodCheck extends AbstractCheck {
}
/**
* Controls whether to allow a method which returns non-void type to omit
* the return tag in the javadoc. Defaults to false.
* Setter to control whether to ignore violations when a method returns non-void type
* and does not have a {@code return} tag in the javadoc.
*
* @param flag a {@code Boolean} value
*/
......@@ -272,8 +428,13 @@ public class JavadocMethodCheck extends AbstractCheck {
}
/**
* Controls whether to log class loading errors to the checkstyle report
* instead of throwing a RTE.
* Setter to control checkstyle's error handling when a class loading fails.
* This check may need to load exception classes mentioned in the {@code @throws}
* tag to check whether they are RuntimeExceptions. If set to {@code false}
* a classpath configuration problem is assumed and the TreeWalker stops operating
* on the class completely. If set to {@code true}(the default), checkstyle assumes
* a typo or refactoring problem in the javadoc and logs the problem in the normal
* checkstyle report (potentially masking a configuration error).
*
* @param logLoadErrors true if errors should be logged
* @deprecated No substitute.
......@@ -284,7 +445,11 @@ public class JavadocMethodCheck extends AbstractCheck {
}
/**
* Controls whether to show class loading errors in the checkstyle report.
* Setter to control whether to suppress violations when a class loading fails.
* When logLoadErrors is set to true, the TreeWalker completely processes
* a class and displays any problems with loading exceptions as checkstyle violations.
* When this property is set to true, the violations generated when logLoadErrors
* is set true are suppressed from being reported as violations in the checkstyle report.
*
* @param suppressLoadErrors true if errors shouldn't be shown
* @deprecated No substitute.
......@@ -513,12 +678,12 @@ public class JavadocMethodCheck extends AbstractCheck {
currentLine++;
final Matcher javadocArgMatcher =
MATCH_JAVADOC_ARG.matcher(lines[i]);
final Matcher javadocArgMissingDescriptionMatcher =
MATCH_JAVADOC_ARG_MISSING_DESCRIPTION.matcher(lines[i]);
final Matcher javadocNoargMatcher =
MATCH_JAVADOC_NOARG.matcher(lines[i]);
final Matcher noargCurlyMatcher =
MATCH_JAVADOC_NOARG_CURLY.matcher(lines[i]);
final Matcher argMultilineStart =
MATCH_JAVADOC_ARG_MULTILINE_START.matcher(lines[i]);
final Matcher noargMultilineStart =
MATCH_JAVADOC_NOARG_MULTILINE_START.matcher(lines[i]);
......@@ -527,6 +692,13 @@ public class JavadocMethodCheck extends AbstractCheck {
tags.add(new JavadocTag(currentLine, col, javadocArgMatcher.group(1),
javadocArgMatcher.group(2)));
}
else if (javadocArgMissingDescriptionMatcher.find()) {
final int col = calculateTagColumn(javadocArgMissingDescriptionMatcher, i,
startColumnNumber);
tags.add(new JavadocTag(currentLine, col,
javadocArgMissingDescriptionMatcher.group(1),
javadocArgMissingDescriptionMatcher.group(2)));
}
else if (javadocNoargMatcher.find()) {
final int col = calculateTagColumn(javadocNoargMatcher, i, startColumnNumber);
tags.add(new JavadocTag(currentLine, col, javadocNoargMatcher.group(1)));
......@@ -535,10 +707,6 @@ public class JavadocMethodCheck extends AbstractCheck {
final int col = calculateTagColumn(noargCurlyMatcher, i, startColumnNumber);
tags.add(new JavadocTag(currentLine, col, noargCurlyMatcher.group(1)));
}
else if (argMultilineStart.find()) {
final int col = calculateTagColumn(argMultilineStart, i, startColumnNumber);
tags.addAll(getMultilineArgTags(argMultilineStart, col, lines, i, currentLine));
}
else if (noargMultilineStart.find()) {
tags.addAll(getMultilineNoArgTags(noargMultilineStart, lines, i, currentLine));
}
......@@ -562,35 +730,6 @@ public class JavadocMethodCheck extends AbstractCheck {
return col;
}
/**
* Gets multiline Javadoc tags with arguments.
* @param argMultilineStart javadoc tag Matcher
* @param column column number of Javadoc tag
* @param lines comment text lines
* @param lineIndex line number that contains the javadoc tag
* @param tagLine javadoc tag line number in file
* @return javadoc tags with arguments
*/
private static List<JavadocTag> getMultilineArgTags(final Matcher argMultilineStart,
final int column, final String[] lines, final int lineIndex, final int tagLine) {
final List<JavadocTag> tags = new ArrayList<>();
final String param1 = argMultilineStart.group(1);
final String param2 = argMultilineStart.group(2);
for (int remIndex = lineIndex + 1; remIndex < lines.length; remIndex++) {
final Matcher multilineCont = MATCH_JAVADOC_MULTILINE_CONT.matcher(lines[remIndex]);
if (multilineCont.find()) {
final String lFin = multilineCont.group(1);
if (!lFin.equals(NEXT_TAG)
&& !lFin.equals(END_JAVADOC)) {
tags.add(new JavadocTag(tagLine, column, param1, param2));
}
break;
}
}
return tags;
}
/**
* Gets multiline Javadoc tags with no arguments.
* @param noargMultilineStart javadoc tag Matcher
......
......@@ -30,8 +30,41 @@ import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
import com.puppycrawl.tools.checkstyle.api.FileText;
/**
* Checks that all packages have a package documentation. See the documentation
* for more information.
* <p>
* Checks that each Java package has a Javadoc file used for commenting.
* By default it only allows a {@code package-info.java} file,
* but can be configured to allow a {@code package.html} file.
* </p>
* <p>
* A violation will be reported if both files exist as this is not allowed by the Javadoc tool.
* </p>
* <ul>
* <li>
* Property {@code allowLegacy} - Allow legacy {@code package.html} file to be used.
* Default value is {@code false}.
* </li>
* <li>
* Property {@code fileExtensions} - Specify the file type extension of files to process.
* Default value is {@code .java}.
* </li>
* </ul>
* <p>
* To configure the check:
* </p>
* <pre>
* &lt;module name="JavadocPackage"/&gt;
* </pre>
* <p>
* To configure the check to use legacy {@code package.html} file
* when {@code package-info.java} file is absent:
* </p>
* <pre>
* &lt;module name="JavadocPackage"&gt;
* &lt;property name="allowLegacy" value="true"/&gt;
* &lt;/module&gt;
* </pre>
*
* @since 5.0
*/
@GlobalStatefulCheck
public class JavadocPackageCheck extends AbstractFileSetCheck {
......@@ -51,7 +84,7 @@ public class JavadocPackageCheck extends AbstractFileSetCheck {
/** The directories checked. */
private final Set<File> directoriesChecked = ConcurrentHashMap.newKeySet();
/** Indicates if allow legacy "package.html" file to be used. */
/** Allow legacy {@code package.html} file to be used. */
private boolean allowLegacy;
/**
......@@ -92,8 +125,8 @@ public class JavadocPackageCheck extends AbstractFileSetCheck {
}
/**
* Indicates whether to allow support for the legacy <i>package.html</i>
* file.
* Setter to allow legacy {@code package.html} file to be used.
*
* @param allowLegacy whether to allow support.
*/
public void setAllowLegacy(boolean allowLegacy) {
......
......@@ -26,49 +26,88 @@ import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
import com.puppycrawl.tools.checkstyle.utils.JavadocUtil;
/**
* <p>
* Checks the Javadoc paragraph.
* </p>
* <p>
* Checks that:
* </p>
* <ul>
* <li>There is one blank line between each of two paragraphs
* and one blank line before the at-clauses block if it is present.</li>
* <li>Each paragraph but the first has &lt;p&gt; immediately
* before the first word, with no space after.</li>
* </ul>
*
* <p>The check can be specified by option allowNewlineParagraph,
* which says whether the &lt;p&gt; tag should be placed immediately before
* the first word.
*
* <p>Default configuration:
* <ul>
* <li>
* Property {@code violateExecutionOnNonTightHtml} - Control when to print violations
* if the Javadoc being examined by this check violates the tight html rules defined at
* <a href="https://checkstyle.org/writingjavadocchecks.html#Tight-HTML_rules">
* Tight-HTML Rules</a>.
* Default value is {@code false}.
* </li>
* <li>
* Property {@code allowNewlineParagraph} - Control whether the &lt;p&gt; tag
* should be placed immediately before the first word.
* Default value is {@code true}.
* </li>
* </ul>
* <p>
* To configure the default check:
* </p>
* <pre>
* &lt;module name=&quot;JavadocParagraph&quot;/&gt;
* </pre>
*
* <p>To allow newlines and spaces immediately after the &lt;p&gt; tag:
* <p>
* By default, the check will report a violation if there is a new line
* or whitespace after the &lt;p&gt; tag:
* </p>
* <pre>
* &#47;**
* * No tag (ok).
* *
* * &lt;p&gt;Tag immediately before the text (ok).
* * &lt;p&gt;No blank line before the tag (violation).
* *
* * &lt;p&gt;
* * New line after tag (violation).
* *
* * &lt;p&gt; Whitespace after tag (violation).
* *
* *&#47;
* public class TestClass {
* }
* </pre>
* <p>
* To allow newlines and spaces immediately after the &lt;p&gt; tag:
* </p>
* <pre>
* &lt;module name=&quot;JavadocParagraph&quot;&gt;
* &lt;property name=&quot;allowNewlineParagraph&quot;
* value==&quot;false&quot;/&gt;
* &lt;/module&quot;&gt;
* &lt;property name=&quot;allowNewlineParagraph&quot; value=&quot;false&quot;/&gt;
* &lt;/module&gt;
* </pre>
*
* <p>In case of allowNewlineParagraph set to false
* <p>
* In case of {@code allowNewlineParagraph} set to {@code false}
* the following example will not have any violations:
* </p>
* <pre>
* /**
* * &lt;p&gt;
* * Some Javadoc.
* &#47;**
* * No tag (ok).
* *
* * &lt;p&gt; Some Javadoc.
* * &lt;p&gt;Tag immediately before the text (ok).
* * &lt;p&gt;No blank line before the tag (violation).
* *
* * &lt;p&gt;
* * &lt;pre&gt;
* * Some preformatted Javadoc.
* * &lt;/pre&gt;
* * New line after tag (ok).
* *
* * &lt;p&gt; Whitespace after tag (ok).
* *
* *&#47;
* public class TestClass {
* }
* </pre>
*
* @since 6.0
*/
@StatelessCheck
public class JavadocParagraphCheck extends AbstractJavadocCheck {
......@@ -98,12 +137,14 @@ public class JavadocParagraphCheck extends AbstractJavadocCheck {
public static final String MSG_MISPLACED_TAG = "javadoc.paragraph.misplaced.tag";
/**
* Whether the &lt;p&gt; tag should be placed immediately before the first word.
* Control whether the &lt;p&gt; tag should be placed immediately before the first word.
*/
private boolean allowNewlineParagraph = true;
/**
* Sets allowNewlineParagraph.
* Setter to control whether the &lt;p&gt; tag should be placed
* immediately before the first word.
*
* @param value value to set.
*/
public void setAllowNewlineParagraph(boolean value) {
......