Skip to content

Commit

Permalink
Merge de87d6a into 05981e0
Browse files Browse the repository at this point in the history
  • Loading branch information
Zopsss committed Apr 21, 2024
2 parents 05981e0 + de87d6a commit 7db3be1
Show file tree
Hide file tree
Showing 36 changed files with 1,199 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,28 @@
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<fileName>src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocLeadingAsteriskAlignCheck.java</fileName>
<specifier>array.access.unsafe.high</specifier>
<message>Potentially unsafe array access: the index could be larger than the array&apos;s bound</message>
<lineContent>final String startLine = getLines()[rootAst.getLineNumber() - 1];</lineContent>
<details>
found : int
required: @IndexFor(&quot;this.getLines()&quot;) or @LTLengthOf(&quot;this.getLines()&quot;) -- an integer less than this.getLines()&apos;s length
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<fileName>src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocLeadingAsteriskAlignCheck.java</fileName>
<specifier>array.access.unsafe.low</specifier>
<message>Potentially unsafe array access: the index could be negative.</message>
<lineContent>final String startLine = getLines()[rootAst.getLineNumber() - 1];</lineContent>
<details>
found : int
required: an integer &gt;= 0 (@NonNegative or @Positive)
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<fileName>src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.java</fileName>
<specifier>array.access.unsafe.high</specifier>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3901,6 +3901,20 @@
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<fileName>src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocLeadingAsteriskAlignCheck.java</fileName>
<specifier>dereference.of.nullable</specifier>
<message>dereference of possibly-null reference matcher.group(1)</message>
<lineContent>columnNumber = matcher.group(1).length() + 1;</lineContent>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<fileName>src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocLeadingAsteriskAlignCheck.java</fileName>
<specifier>dereference.of.nullable</specifier>
<message>dereference of possibly-null reference matcher.group(1)</message>
<lineContent>return matcher.group(1).length() + 2;</lineContent>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<fileName>src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.java</fileName>
<specifier>argument</specifier>
Expand Down
1 change: 1 addition & 0 deletions config/checkstyle-checks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@
<property name="validateThrows" value="true"/>
</module>
<module name="JavadocMissingLeadingAsterisk"/>
<module name="JavadocLeadingAsteriskAlign"/>
<module name="JavadocMissingWhitespaceAfterAsterisk"/>
<module name="JavadocParagraph"/>
<module name="JavadocStyle">
Expand Down
2 changes: 2 additions & 0 deletions config/checkstyle-resources-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@
files="[\\/]InputMagicNumberAnnotationElement\.java"/>
<suppress checks="FileTabCharacter"
files="[\\/]InputInnerTypeLastClass\.java"/>
<suppress checks="FileTabCharacter"
files="[\\/]InputJavadocLeadingAsteriskAlignTabs\.java"/>
<suppress checks="FileTabCharacter"
files="[\\/]InputJavadocMissingWhitespaceAfterAsteriskValidWithTab\.java"/>
<suppress checks="FileTabCharacter"
Expand Down
1 change: 1 addition & 0 deletions config/jsoref-spellchecker/whitelist.words
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ javadoc
javadocblocktaglocation
javadoccontentlocation
javadocdetailnodeparser
javadocleadingasteriskalign
javadocmetadatascraper
javadocmethod
javadocmissingleadingasterisk
Expand Down
3 changes: 3 additions & 0 deletions config/linkcheck-suppressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@
<a href="apidocs/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocBlockTagLocationCheck.html#%3Cinit%3E()">#%3Cinit%3E()</a>: doesn't exist.
<a href="apidocs/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocContentLocationCheck.html#%3Cinit%3E()">#%3Cinit%3E()</a>: doesn't exist.
<a href="apidocs/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocContentLocationOption.html#%3Cinit%3E()">#%3Cinit%3E()</a>: doesn't exist.
<a href="apidocs/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocLeadingAsteriskAlignCheck.html#%3Cinit%3E()">#%3Cinit%3E()</a>: doesn't exist.
<a href="apidocs/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.ClassInfo.html#%3Cinit%3E(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.Token)">#%3Cinit%3E(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.Token)</a>: doesn't exist.
<a href="apidocs/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.ClassInfo.html#%3Cinit%3E(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.Token)">../JavadocMethodCheck.ClassInfo.html#%3Cinit%3E(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.Token)</a>: doesn't exist.
<a href="apidocs/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.ExceptionInfo.html#%3Cinit%3E(com.puppycrawl.tools.checkstyle.api.DetailAST,com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.ClassInfo)">#%3Cinit%3E(com.puppycrawl.tools.checkstyle.api.DetailAST,com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.ClassInfo)</a>: doesn't exist.
Expand Down Expand Up @@ -1107,6 +1108,7 @@
<a href="com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocBlockTagLocationCheck.html#%3Cinit%3E()">com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocBlockTagLocationCheck.html#%3Cinit%3E()</a>: doesn't exist.
<a href="com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocContentLocationCheck.html#%3Cinit%3E()">com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocContentLocationCheck.html#%3Cinit%3E()</a>: doesn't exist.
<a href="com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocContentLocationOption.html#%3Cinit%3E()">com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocContentLocationOption.html#%3Cinit%3E()</a>: doesn't exist.
<a href="com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocLeadingAsteriskAlignCheck.html#%3Cinit%3E()">com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocLeadingAsteriskAlignCheck.html#%3Cinit%3E()</a>: doesn't exist.
<a href="com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.ClassInfo.html#%3Cinit%3E(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.Token)">com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.ClassInfo.html#%3Cinit%3E(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.Token)</a>: doesn't exist.
<a href="com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.ExceptionInfo.html#%3Cinit%3E(com.puppycrawl.tools.checkstyle.api.DetailAST,com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.ClassInfo)">com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.ExceptionInfo.html#%3Cinit%3E(com.puppycrawl.tools.checkstyle.api.DetailAST,com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.ClassInfo)</a>: doesn't exist.
<a href="com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.Token.html#%3Cinit%3E(com.puppycrawl.tools.checkstyle.api.FullIdent)">com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.Token.html#%3Cinit%3E(com.puppycrawl.tools.checkstyle.api.FullIdent)</a>: doesn't exist.
Expand Down Expand Up @@ -1333,6 +1335,7 @@
<a href="com/puppycrawl/tools/checkstyle/xpath/XpathQueryGenerator.html#%3Cinit%3E(com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent,int)">com/puppycrawl/tools/checkstyle/xpath/XpathQueryGenerator.html#%3Cinit%3E(com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent,int)</a>: doesn't exist.
<a href="com/puppycrawl/tools/checkstyle/xpath/XpathQueryGenerator.html#%3Cinit%3E(com.puppycrawl.tools.checkstyle.api.DetailAST,int,int,com.puppycrawl.tools.checkstyle.api.FileText,int)">com/puppycrawl/tools/checkstyle/xpath/XpathQueryGenerator.html#%3Cinit%3E(com.puppycrawl.tools.checkstyle.api.DetailAST,int,int,com.puppycrawl.tools.checkstyle.api.FileText,int)</a>: doesn't exist.
<a href="com/puppycrawl/tools/checkstyle/xpath/XpathQueryGenerator.html#%3Cinit%3E(com.puppycrawl.tools.checkstyle.api.DetailAST,int,int,int,com.puppycrawl.tools.checkstyle.api.FileText,int)">com/puppycrawl/tools/checkstyle/xpath/XpathQueryGenerator.html#%3Cinit%3E(com.puppycrawl.tools.checkstyle.api.DetailAST,int,int,int,com.puppycrawl.tools.checkstyle.api.FileText,int)</a>: doesn't exist.
<a href="config_blocks.html#LeftCurly">config_blocks.html#LeftCurly</a>: doesn't exist.
<a href="com/puppycrawl/tools/checkstyle/xpath/iterators/DescendantIterator.StartWith.html#%3Cinit%3E()">com/puppycrawl/tools/checkstyle/xpath/iterators/DescendantIterator.StartWith.html#%3Cinit%3E()</a>: doesn't exist.
<a href="com/puppycrawl/tools/checkstyle/xpath/iterators/DescendantIterator.html#%3Cinit%3E(net.sf.saxon.om.NodeInfo,com.puppycrawl.tools.checkstyle.xpath.iterators.DescendantIterator.StartWith)">com/puppycrawl/tools/checkstyle/xpath/iterators/DescendantIterator.html#%3Cinit%3E(net.sf.saxon.om.NodeInfo,com.puppycrawl.tools.checkstyle.xpath.iterators.DescendantIterator.StartWith)</a>: doesn't exist.
<a href="com/puppycrawl/tools/checkstyle/xpath/iterators/FollowingIterator.html#%3Cinit%3E(net.sf.saxon.om.NodeInfo)">com/puppycrawl/tools/checkstyle/xpath/iterators/FollowingIterator.html#%3Cinit%3E(net.sf.saxon.om.NodeInfo)</a>: doesn't exist.
Expand Down
2 changes: 2 additions & 0 deletions config/spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
<Class name="com.puppycrawl.tools.checkstyle.checks.coding.MatchXpathCheck"/>
<Class name="com.puppycrawl.tools.checkstyle.checks.OuterTypeFilenameCheck" />
<Class name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpCheck" />
<Class name=
"com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocLeadingAsteriskAlignCheck" />
<!-- createJavadocNode is private and can not be launched without visitToken -->
<Class name="com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck" />
<!-- has only one public method and all initialized in that method -->
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1796,6 +1796,7 @@
<exclude>**/JavadocMethodCheck.class</exclude>
<exclude>**/JavadocMissingLeadingAsteriskCheck.class</exclude>
<exclude>**/JavadocMissingWhitespaceAfterAsteriskCheck.class</exclude>
<exclude>**/JavadocLeadingAsteriskAlignCheck.class</exclude>
<exclude>**/JavadocParagraphCheck.class</exclude>
<exclude>**/JavadocStyleCheck.class</exclude>
<exclude>**/JavadocTagContinuationIndentationCheck.class</exclude>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,8 @@ private static void fillChecksFromJavadocPackage() {
BASE_PACKAGE + ".checks.javadoc.JavadocMethodCheck");
NAME_TO_FULL_MODULE_NAME.put("JavadocMissingLeadingAsteriskCheck",
BASE_PACKAGE + ".checks.javadoc.JavadocMissingLeadingAsteriskCheck");
NAME_TO_FULL_MODULE_NAME.put("JavadocLeadingAsteriskAlignCheck",
BASE_PACKAGE + ".checks.javadoc.JavadocLeadingAsteriskAlignCheck");
NAME_TO_FULL_MODULE_NAME.put("JavadocMissingWhitespaceAfterAsteriskCheck",
BASE_PACKAGE + ".checks.javadoc.JavadocMissingWhitespaceAfterAsteriskCheck");
NAME_TO_FULL_MODULE_NAME.put("JavadocPackageCheck",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// 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 java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.puppycrawl.tools.checkstyle.GlobalStatefulCheck;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.DetailNode;
import com.puppycrawl.tools.checkstyle.api.JavadocTokenTypes;
import com.puppycrawl.tools.checkstyle.utils.JavadocUtil;

/**
* <p>
* Checks that the
* <a href="https://docs.oracle.com/en/java/javase/14/docs/specs/javadoc/doc-comment-spec.html#leading-asterisks">
* leading asterisks</a> are aligned vertically under the second asterisk ( &#42; )
* of opening Javadoc tag. The alignment of closing Javadoc tag is also checked.
* If the line does not contain leading asterisk then that line will be ignored.
* </p>
* <p>
* If you're using tabs then specify the the tab width in the
* <a href="https://checkstyle.org/config.html#tabWidth">tabWidth</a> property.
* The default value of {@code tabWidth} is 8.
* </p>
* <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>.
* Type is {@code boolean}.
* Default value is {@code false}.
* </li>
* </ul>
* <p>
* Parent is {@code com.puppycrawl.tools.checkstyle.TreeWalker}
* </p>
* <p>
* Violation Message Keys:
* </p>
* <ul>
* <li>
* {@code javadoc.asterisk.indentation}
* </li>
* <li>
* {@code javadoc.missed.html.close}
* </li>
* <li>
* {@code javadoc.parse.rule.error}
* </li>
* <li>
* {@code javadoc.unclosedHtml}
* </li>
* <li>
* {@code javadoc.wrong.singleton.html.tag}
* </li>
* </ul>
*
* @since 10.16.0
*/
@GlobalStatefulCheck
public class JavadocLeadingAsteriskAlignCheck extends AbstractJavadocCheck {

/**
* A key is pointing to the warning message text in "messages.properties"
* file.
*/
public static final String MSG_KEY = "javadoc.asterisk.indentation";

/** Specifies the tab. */
private static final Pattern TAB = Pattern.compile("\t");

/** Specifies the whitespace. */
private static final String SPACE = " ";

/** Specifies the column number of starting block of the javadoc comment. */
private int parentColNumber;
/** Specifies the line number of starting block of the javadoc comment. */
private int parentLineNumber;

@Override
public int[] getDefaultJavadocTokens() {
return new int[] {
JavadocTokenTypes.LEADING_ASTERISK,
};
}

@Override
public int[] getRequiredJavadocTokens() {
return getAcceptableJavadocTokens();
}

// get the starting block of javadoc
@Override
public void beginJavadocTree(DetailNode rootAst) {
final String startLine = getLines()[rootAst.getLineNumber() - 1];
parentColNumber = getColumnForStartToken(startLine);
parentLineNumber = rootAst.getLineNumber();
}

// process leading asterisks of the javadoc
@Override
public void visitJavadocToken(DetailNode ast) {
if (ast.getLineNumber() != parentLineNumber) {
final int commentIndex = getColumnForCommentText(ast.getText());

checkAsteriskAlignment(
ast.getLineNumber(),
parentColNumber,
commentIndex);
}
}

// process the end block of javadoc
@Override
public void finishJavadocTree(DetailNode rootAst) {
final DetailAST javadocEndToken = getBlockCommentAst().getLastChild();

if (parentLineNumber != javadocEndToken.getLineNo()) {
final String lastLine = getLastLine(javadocEndToken);
final int commentIndex = getColumnForCommentText(lastLine);

checkAsteriskAlignment(
javadocEndToken.getLineNo(),
parentColNumber,
commentIndex);
}
}

/**
* Processes and sets the last line of javadoc which includes comment's ending token.
*
* @param endToken javadoc ending token
* @return last line of javadoc comment including ending token
*/
private String getLastLine(DetailAST endToken) {
final String lastLine;

if (endToken.getColumnNo() == 0) {
lastLine = endToken.getText();
}
else {
final String blockComment = JavadocUtil.getBlockCommentContent(getBlockCommentAst());
final List<String> commentTextLineList = Arrays.asList(blockComment.split("\n"));
lastLine = commentTextLineList.get(commentTextLineList.size() - 1) + "*/";
}

return lastLine;
}

/**
* Processes and returns the column number of leading asterisk from javadoc comment text.
*
* @param line single line from block comment text
* @return column number of asterisk
*/
private int getColumnForCommentText(String line) {
final Matcher tabMatcher = TAB.matcher(line);
final String lineWithoutTabs = tabMatcher.replaceAll(SPACE.repeat(getTabWidth()));
final Pattern pattern = Pattern.compile("^(\\s*)\\*");
final Matcher matcher = pattern.matcher(lineWithoutTabs);
final int columnNumber;

if (matcher.find()) {
columnNumber = matcher.group(1).length() + 1;
}
else {
columnNumber = -1;
}

return columnNumber;
}

/**
* Processes and returns the column number of starting block of javadoc comment.
*
* @param line starting line of the javadoc comment
* @return column number of start token
* @noinspection ResultOfMethodCallIgnored
* @noinspectionreason ResultOfMethodCallIgnored- the file cannot be read without calling
* the find() method. In our case we are sure that the find() will always be true, so
* we don't need to check its result
*/
private int getColumnForStartToken(String line) {
final Matcher tabMatcher = TAB.matcher(line);
final String lineWithoutTabs = tabMatcher.replaceAll(SPACE.repeat(getTabWidth()));
final Pattern pattern = Pattern.compile("^(.*)/\\*\\*");
final Matcher matcher = pattern.matcher(lineWithoutTabs);
matcher.find();

return matcher.group(1).length() + 2;
}

/**
* Checks alignment of asterisks and logs violations.
*
* @param lineNumber line number of current comment line
* @param commentBeginColumn column number of javadoc starting token
* @param asteriskColumn column number of current line's leading asterisk
*/
private void checkAsteriskAlignment(int lineNumber,
int commentBeginColumn,
int asteriskColumn) {

if (asteriskColumn != -1) {
final int columnDifference = commentBeginColumn - asteriskColumn;
if (columnDifference != 0) {
log(lineNumber, asteriskColumn - 1, MSG_KEY, commentBeginColumn);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ indentation.child.error=O filho de ''{0}'' está no nível de indentação incor
indentation.child.error.multi=O filho de ''{0}'' está no nível de indentação incorreto de {1}. O nível esperado era um desses: {2}.
indentation.error=''{0}'' tem um nível de indentação incorreto de {1}. O nível esperado era o {2}.
indentation.error.multi=''{0}'' tem um nível de indentação incorreto de {1}. O nível esperado era um desses: {2}.

0 comments on commit 7db3be1

Please sign in to comment.