Skip to content

Commit

Permalink
Issue checkstyle#10527: Added support for null in inline config
Browse files Browse the repository at this point in the history
  • Loading branch information
shashwatj07 authored and timurt committed Aug 17, 2021
1 parent dd52056 commit 0b64c4d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public final class InlineConfigParser {
private static final Pattern MULTIPLE_VIOLATIONS_PATTERN = Pattern
.compile(".*//\\s*(\\d) violations(?: .*)?$");

/** The String "(null)". */
private static final String NULL_STRING = "(null)";

/** Stop instances being created. **/
private InlineConfigParser() {
}
Expand Down Expand Up @@ -121,18 +124,28 @@ private static void setCheckProperties(TestInputConfiguration.Builder inputConfi
final String key = entry.getKey().toString();
final String value = entry.getValue().toString();
if (value.startsWith("(default)")) {
inputConfigBuilder.addDefaultProperty(key,
value.substring(value.indexOf(')') + 1));
final String defaultValue = value.substring(value.indexOf(')') + 1);
if (NULL_STRING.equals(defaultValue)) {
inputConfigBuilder.addDefaultProperty(key, null);
}
else {
inputConfigBuilder.addDefaultProperty(key, defaultValue);
}
}
else {
inputConfigBuilder.addNonDefaultProperty(key, value);
if (NULL_STRING.equals(value)) {
inputConfigBuilder.addNonDefaultProperty(key, null);
}
else {
inputConfigBuilder.addNonDefaultProperty(key, value);
}
}
}
}

private static void setViolations(TestInputConfiguration.Builder inputConfigBuilder,
List<String> lines) {
for (int lineNo = 2; lineNo < lines.size(); lineNo++) {
for (int lineNo = 0; lineNo < lines.size(); lineNo++) {
final Matcher violationMatcher = VIOLATION_PATTERN.matcher(lines.get(lineNo));
final Matcher violationAboveMatcher =
VIOLATION_ABOVE_PATTERN.matcher(lines.get(lineNo));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void testNullCustomMessage()
final String[] expected = {
"34:28: " + getCheckMessage(MSG_KEY, "a href"),
};
verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getPath("InputIllegalTokenTextTokens4.java"), expected);
}

Expand Down Expand Up @@ -167,7 +167,7 @@ public void testCommentToken()
"1:3: " + getCheckMessage(MSG_KEY, "a href"),
"45:28: " + getCheckMessage(MSG_KEY, "a href"),
};
verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getPath("InputIllegalTokenTextTokens5.java"), expected);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
IllegalTokenText
format = a href
ignoreCase = (default)false
message = (default)
message = (null)
tokens = STRING_LITERAL
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
/* // violation
IllegalTokenText
format = a href
ignoreCase = (default)false
message = (default)
message = (null)
tokens = COMMENT_CONTENT
Expand Down Expand Up @@ -41,8 +41,8 @@ public void methodWithLabels() {
anotherLabel: // some comment href
do {
continue anotherLabel;
} while (false);
break label; // violation Token text matches the illegal pattern 'a href'.
} while (false); // violation below
break label; // a href
}
}
}

0 comments on commit 0b64c4d

Please sign in to comment.