Skip to content

Commit

Permalink
Issue #7374: add default support for "fall-through" spelling to FallT…
Browse files Browse the repository at this point in the history
…hrough reliefPattern
  • Loading branch information
guillaumelambert authored and romani committed Dec 29, 2019
1 parent 0caf33d commit 55e3f75
Show file tree
Hide file tree
Showing 7 changed files with 641 additions and 36 deletions.
1 change: 1 addition & 0 deletions .ci/jsoref-spellchecker/whitelist.words
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,7 @@ tfoot
thead
thesummaryfragment
thetaphi
thr
throwable
throwscount
Thymeleaf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public void testFallThrough() throws Exception {
"369:11: " + msg,
"372:11: " + msg,
"374:41: " + msg,
"440:15: " + msg,
"442:15: " + msg,
"444:15: " + msg,
"446:15: " + msg,
"448:15: " + msg,
};

final Configuration checkConfig = getModuleConfig("FallThrough");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,4 +406,48 @@ void method1472228(int i) {
default:
}
}

/* Test relief comment. */
void methodFallThruWithDash(int i, int j, boolean cond) {
while (true) {
switch (i){
case 0:
i++; // fallthru
case 1:
i++; // fall thru
case 2:
i++; // fall-thru
case 3:
i++; // fallthrough
case 4:
i++; // fall through
case 5:
i++; // fall-through
case 6:
i++; // fallsthru
case 7:
i++; // falls thru
case 8:
i++; // falls-thru
case 9:
i++; // fallsthrough
case 10:
i++; // falls through
case 11:
i++; // falls-through
case 12:
i++; // fall--through
case 13: //warn
i++; // fall+through
case 14: //warn
i++; // falls_thru
case 15: //warn
i++; // falls=through
case 16: //warn
i++; // falls-throug
default: //warn
throw new RuntimeException();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
* </p>
* <p>
* The check honors special comments to suppress the warning.
* By default the text "fallthru", "fall through", "fallthrough",
* "falls through" and "fallsthrough" are recognized (case sensitive).
* By default the texts
* "fallthru", "fall thru", "fall-thru",
* "fallthrough", "fall through", "fall-through"
* "fallsthrough", "falls through", "falls-through" (case sensitive).
* The comment containing these words must be all on one line,
* and must be on the last non-empty line before the {@code case} triggering
* the warning or on the same line before the {@code case}(ugly, but possible).
Expand All @@ -59,7 +61,10 @@
* case 5:
* i++;
* &#47;* fallthru *&#47;case 6:
* i++
* i++;
* // fall-through
* case 7:
* i++;
* break;
* }
* </pre>
Expand All @@ -68,15 +73,15 @@
* </p>
* <p>
* The following fragment of code will NOT trigger the check,
* because of the comment "fallthru" and absence of any Java code
* in case 5.
* because of the comment "fallthru" or any Java code
* in case 5 are absent.
* </p>
* <pre>
* case 3:
* x = 2;
* // fallthru
* case 4:
* case 5:
* case 5: // violation
* case 6:
* break;
* </pre>
Expand All @@ -88,7 +93,7 @@
* <li>
* Property {@code reliefPattern} - Define the RegExp to match the relief comment that suppresses
* the warning about a fall through.
* Default value is {@code "fallthru|falls? ?through"}.
* Default value is {@code "falls?[ -]?thr(u|ough)"}.
* </li>
* </ul>
* <p>
Expand Down Expand Up @@ -130,7 +135,7 @@ public class FallThroughCheck extends AbstractCheck {
* Define the RegExp to match the relief comment that suppresses
* the warning about a fall through.
*/
private Pattern reliefPattern = Pattern.compile("fallthru|falls? ?through");
private Pattern reliefPattern = Pattern.compile("falls?[ -]?thr(u|ough)");

@Override
public int[] getDefaultTokens() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,32 @@ protected String getPackageLocation() {
public void testDefault() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(FallThroughCheck.class);
final String[] expected = {
"14:13: " + getCheckMessage(MSG_FALL_THROUGH),
"38:13: " + getCheckMessage(MSG_FALL_THROUGH),
"47:13: " + getCheckMessage(MSG_FALL_THROUGH),
"20:13: " + getCheckMessage(MSG_FALL_THROUGH),
"44:13: " + getCheckMessage(MSG_FALL_THROUGH),
"53:13: " + getCheckMessage(MSG_FALL_THROUGH),
"70:13: " + getCheckMessage(MSG_FALL_THROUGH),
"87:13: " + getCheckMessage(MSG_FALL_THROUGH),
"123:13: " + getCheckMessage(MSG_FALL_THROUGH),
"179:11: " + getCheckMessage(MSG_FALL_THROUGH),
"369:11: " + getCheckMessage(MSG_FALL_THROUGH),
"372:11: " + getCheckMessage(MSG_FALL_THROUGH),
"374:40: " + getCheckMessage(MSG_FALL_THROUGH),
"416:13: " + getCheckMessage(MSG_FALL_THROUGH),
"424:9: " + getCheckMessage(MSG_FALL_THROUGH),
"436:9: " + getCheckMessage(MSG_FALL_THROUGH),
"446:9: " + getCheckMessage(MSG_FALL_THROUGH),
"482:9: " + getCheckMessage(MSG_FALL_THROUGH),
"483:9: " + getCheckMessage(MSG_FALL_THROUGH),
"484:9: " + getCheckMessage(MSG_FALL_THROUGH),
"59:13: " + getCheckMessage(MSG_FALL_THROUGH),
"76:13: " + getCheckMessage(MSG_FALL_THROUGH),
"93:13: " + getCheckMessage(MSG_FALL_THROUGH),
"129:13: " + getCheckMessage(MSG_FALL_THROUGH),
"185:11: " + getCheckMessage(MSG_FALL_THROUGH),
"375:11: " + getCheckMessage(MSG_FALL_THROUGH),
"378:11: " + getCheckMessage(MSG_FALL_THROUGH),
"380:40: " + getCheckMessage(MSG_FALL_THROUGH),
"422:13: " + getCheckMessage(MSG_FALL_THROUGH),
"430:9: " + getCheckMessage(MSG_FALL_THROUGH),
"442:9: " + getCheckMessage(MSG_FALL_THROUGH),
"452:9: " + getCheckMessage(MSG_FALL_THROUGH),
"488:9: " + getCheckMessage(MSG_FALL_THROUGH),
"489:9: " + getCheckMessage(MSG_FALL_THROUGH),
"490:9: " + getCheckMessage(MSG_FALL_THROUGH),
"527:15: " + getCheckMessage(MSG_FALL_THROUGH),
"529:15: " + getCheckMessage(MSG_FALL_THROUGH),
"531:15: " + getCheckMessage(MSG_FALL_THROUGH),
"533:15: " + getCheckMessage(MSG_FALL_THROUGH),
"535:15: " + getCheckMessage(MSG_FALL_THROUGH),
};
verify(checkConfig,
getPath("InputFallThrough.java"),
getPath("InputFallThroughDefault.java"),
expected);
}

Expand Down
Loading

0 comments on commit 55e3f75

Please sign in to comment.