Skip to content

Commit

Permalink
Issue checkstyle#11446: Update AbstractJavadocCheckTest to use execut…
Browse files Browse the repository at this point in the history
…e method
  • Loading branch information
suniti0804 authored and 0xbakry committed Mar 13, 2024
1 parent 2835b9d commit d1e3768
Show file tree
Hide file tree
Showing 19 changed files with 1,121 additions and 345 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,13 @@
<exclude>**/RegexpHeaderCheckTest.class</exclude>

<!-- all bellow until https://github.com/checkstyle/checkstyle/issues/11446 -->
<exclude>**/FileSetCheckTest.class</exclude>
<exclude>**/AbstractFileSetCheckTest.class</exclude>
<exclude>**/DetailAstImplTest.class</exclude>
<exclude>**/TreeWalkerTest.class</exclude>
<exclude>**/CheckerTest.class</exclude>
<exclude>**/AllBlockCommentsTest.class</exclude>
<exclude>**/AbstractCheckTest.class</exclude>
</excludes>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,35 +132,9 @@ public final class InlineConfigParser {
private static final Pattern VIOLATION_SOME_LINES_BELOW_PATTERN = Pattern
.compile(".*//\\s*violation (\\d+) lines below\\s*(?:['\"](.*)['\"])?$");

/**
* <p>
* Multiple violations for above line. Messages are X lines below.
* {@code
* // X violations above:
* // 'violation message1'
* // 'violation messageX'
* }
*
* Messages are matched by {@link InlineConfigParser#VIOLATION_MESSAGE_PATTERN}
* </p>
*/
private static final Pattern VIOLATIONS_ABOVE_PATTERN_WITH_MESSAGES = Pattern
.compile(".*//\\s*(\\d+) violations above:$");

/**
* <p>
* Multiple violations for line. Violations are Y lines above, messages are X lines below.
* {@code
* // X violations Y lines above:
* // 'violation message1'
* // 'violation messageX'
* }
*
* Messages are matched by {@link InlineConfigParser#VIOLATION_MESSAGE_PATTERN}
* </p>
*/
private static final Pattern VIOLATIONS_SOME_LINES_ABOVE_PATTERN = Pattern
.compile(".*//\\s*(\\d+) violations (\\d+) lines above:$");
/** A pattern to find the string: "// X violations Y lines above". */
private static final Pattern MULTIPLE_VIOLATIONS_SOME_LINES_ABOVE_PATTERN = Pattern
.compile(".*//\\s*(\\d+) violations (\\d+) lines above\\s*(?:['\"](.*)['\"])?$");

/** The String "(null)". */
private static final String NULL_STRING = "(null)";
Expand Down Expand Up @@ -328,12 +302,7 @@ private static String getFullyQualifiedClassName(String filePath, String moduleN
"com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceAfterCheck");
moduleMappings.put("SummaryJavadoc",
"com.puppycrawl.tools.checkstyle.checks.javadoc.SummaryJavadocCheck");
moduleMappings.put("LineLength",
"com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck");
moduleMappings.put("Checker",
"com.puppycrawl.tools.checkstyle.CheckerCheck");

String fullyQualifiedClassName;
if (moduleMappings.containsKey(moduleName)) {
fullyQualifiedClassName = moduleMappings.get(moduleName);
}
Expand Down Expand Up @@ -535,10 +504,8 @@ private static void setViolations(TestInputConfiguration.Builder inputConfigBuil
VIOLATION_SOME_LINES_ABOVE_PATTERN.matcher(lines.get(lineNo));
final Matcher violationSomeLinesBelowMatcher =
VIOLATION_SOME_LINES_BELOW_PATTERN.matcher(lines.get(lineNo));
final Matcher violationsAboveMatcherWithMessages =
VIOLATIONS_ABOVE_PATTERN_WITH_MESSAGES.matcher(lines.get(lineNo));
final Matcher violationsSomeLinesAboveMatcher =
VIOLATIONS_SOME_LINES_ABOVE_PATTERN.matcher(lines.get(lineNo));
final Matcher multipleViolationsSomeLinesAboveMatcher =
MULTIPLE_VIOLATIONS_SOME_LINES_ABOVE_PATTERN.matcher(lines.get(lineNo));
if (violationMatcher.matches()) {
final String violationMessage = violationMatcher.group(1);
final int violationLineNum = lineNo + 1;
Expand Down Expand Up @@ -593,15 +560,17 @@ else if (violationSomeLinesBelowMatcher.matches()) {
violationLineNum);
inputConfigBuilder.addViolation(violationLineNum, violationMessage);
}
else if (violationsAboveMatcherWithMessages.matches()) {
inputConfigBuilder.addViolations(
getExpectedViolationsForSpecificLineAbove(
lines, lineNo, lineNo, violationsAboveMatcherWithMessages));
}
else if (violationsSomeLinesAboveMatcher.matches()) {
inputConfigBuilder.addViolations(
getExpectedViolations(
lines, lineNo, violationsSomeLinesAboveMatcher));
else if (multipleViolationsSomeLinesAboveMatcher.matches()) {
final int linesAbove =
Integer.parseInt(multipleViolationsSomeLinesAboveMatcher.group(2));
final int violationLineNum = lineNo - linesAbove + 1;

Collections
.nCopies(Integer.parseInt(multipleViolationsSomeLinesAboveMatcher.group(1)),
violationLineNum)
.forEach(actualLineNumber -> {
inputConfigBuilder.addViolation(actualLineNumber, null);
});
}
else if (multipleViolationsMatcher.matches()) {
Collections
Expand Down

0 comments on commit d1e3768

Please sign in to comment.