From 5e14d63f0f33284c1d95d8254f0676bb4381a6da Mon Sep 17 00:00:00 2001 From: Mauryan Kansara Date: Wed, 10 Jul 2024 01:45:58 +0530 Subject: [PATCH] Issue #15214: Migrated section 4.8.4.2 Fall through commented to whole config testing --- .../FallThroughCommentedTest.java | 3 +- .../rule4842fallthrough/InputFallThrough.java | 817 +++++++++--------- 2 files changed, 412 insertions(+), 408 deletions(-) diff --git a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule4842fallthrough/FallThroughCommentedTest.java b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule4842fallthrough/FallThroughCommentedTest.java index 5f8afb69e56..0f85064323f 100644 --- a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule4842fallthrough/FallThroughCommentedTest.java +++ b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule4842fallthrough/FallThroughCommentedTest.java @@ -32,8 +32,7 @@ protected String getPackageLocation() { @Test public void testFallThrough() throws Exception { - final String filePath = getPath("InputFallThrough.java"); - verifyWithConfigParser(new String[] {"FallThrough"}, filePath); + verifyWithWholeConfig(getPath("InputFallThrough.java")); } } diff --git a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4842fallthrough/InputFallThrough.java b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4842fallthrough/InputFallThrough.java index 726edb23809..eda4f113a69 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4842fallthrough/InputFallThrough.java +++ b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4842fallthrough/InputFallThrough.java @@ -1,454 +1,459 @@ package com.google.checkstyle.test.chapter4formatting.rule4842fallthrough; -public class InputFallThrough -{ - void method(int i, int j, boolean cond) { - while (true) { - switch (i) { - case 0: // no problem +/** Some javadoc. */ +public class InputFallThrough { + void method(int i, int j, boolean cond) { + while (true) { + switch (i) { + case 0: // no problem + case 1: + i++; + break; + case 2: + i++; + case 3: // violation 'Fall through from previous branch of the switch statement.' + i++; + break; + case 4: + return; + case 5: + throw new RuntimeException(""); + case 6: + continue; + case 7: { + break; + } + case 8: { + return; + } + case 9: { + throw new RuntimeException(""); + } + case 10: { + continue; + } + case 11: { + i++; + } + case 12: // violation 'Fall through from previous branch of the switch statement.' + if (false) { + break; + } else { + break; + } + case 13: + if (true) { + return; + } + case 14: // violation 'Fall through from previous branch of the switch statement.' + if (true) { + return; + } else { + // do nothing + } + case 15: // violation 'Fall through from previous branch of the switch statement.' + do { + System.identityHashCode("something"); + return; + } while (true); + case 16: + for (int j1 = 0; j1 < 10; j1++) { + System.identityHashCode("something"); + return; + } + case 17: + while (true) { + throw new RuntimeException(""); + } + case 18: + while (cond) { + break; + } + case 19: // violation 'Fall through from previous branch of the switch statement.' + try { + i++; + break; + } catch (RuntimeException e) { + break; + } catch (Error e) { + return; + } + case 20: + try { + i++; + break; + } catch (RuntimeException e) { + // do nothing + } catch (Error e) { + return; + } + case 21: // violation 'Fall through from previous branch of the switch statement.' + try { + i++; + } catch (RuntimeException e) { + i--; + } finally { + break; + } + case 22: + try { + i++; + break; + } catch (RuntimeException e) { + i--; + break; + } finally { + i++; + } + case 23: + switch (j) { case 1: - i++; - break; + continue; case 2: - i++; - case 3: // violation 'Fall through from previous branch of the switch statement.' - i++; - break; - case 4: - return; - case 5: - throw new RuntimeException(""); - case 6: - continue; - case 7: { - break; - } - case 8: { - return; - } - case 9: { - throw new RuntimeException(""); - } - case 10: { - continue; - } - case 11: { - i++; - } - case 12: // violation 'Fall through from previous branch of the switch statement.' - if (false) - break; - else - break; - case 13: - if (true) { - return; - } - case 14: // violation 'Fall through from previous branch of the switch statement.' - if (true) { - return; - } else { - //do nothing - } - case 15: // violation 'Fall through from previous branch of the switch statement.' - do { - System.identityHashCode("something"); - return; - } while(true); - case 16: - for (int j1 = 0; j1 < 10; j1++) { - System.identityHashCode("something"); - return; - } - case 17: - while (true) - throw new RuntimeException(""); - case 18: - while(cond) { - break; - } - case 19: // violation 'Fall through from previous branch of the switch statement.' - try { - i++; - break; - } catch (RuntimeException e) { - break; - } catch (Error e) { - return; - } - case 20: - try { - i++; - break; - } catch (RuntimeException e) { - } catch (Error e) { - return; - } - case 21: // violation 'Fall through from previous branch of the switch statement.' - try { - i++; - } catch (RuntimeException e) { - i--; - } finally { - break; - } - case 22: - try { - i++; - break; - } catch (RuntimeException e) { - i--; - break; - } finally { - i++; - } - case 23: - switch (j) { - case 1: - continue; - case 2: - return; - default: - return; - } - case 24: - switch (j) { - case 1: - continue; - case 2: - break; - default: - return; - } - default: // violation 'Fall through from previous branch of the switch statement.' - // this is the last label - i++; - } - } - } - - - - /* Like above, but all fall throughs with relief comment */ - void methodFallThru(int i, int j, boolean cond) { - while (true) { - switch (i) { - case -1: // FALLTHRU - - case 0: // no problem - case 1: - i++; - break; - case 2: - i++; - // fallthru - case 3: - i++; - break; - case 4: return; - case 5: - throw new RuntimeException(""); - case 6: + default: + return; + } + case 24: + switch (j) { + case 1: continue; - case 7: { + case 2: break; - } - case 8: { + default: return; } - case 9: { - throw new RuntimeException(""); + default: // violation 'Fall through from previous branch of the switch statement.' + // this is the last label + i++; + } + } + } + + /* Like above, but all fall throughs with relief comment */ + void methodFallThru(int i, int j, boolean cond) { + while (true) { + switch (i) { + case -1: // FALLTHRU + + case 0: // no problem + case 1: + i++; + break; + case 2: + i++; + // fallthru + case 3: + i++; + break; + case 4: + return; + case 5: + throw new RuntimeException(""); + case 6: + continue; + case 7: { + break; + } + case 8: { + return; + } + case 9: { + throw new RuntimeException(""); + } + case 10: { + continue; + } + case 11: { + i++; + } + // fallthru + case 12: + if (false) { + break; + } else { + break; } - case 10: { - continue; + case 13: + if (true) { + return; } - case 11: { - i++; + case 14: // violation 'Fall through from previous branch of the switch statement.' + if (true) { + return; + } else { + // do nothing } // fallthru - case 12: - if (false) - break; - else - break; - case 13: - if (true) { - return; - } - case 14: // violation 'Fall through from previous branch of the switch statement.' - if (true) { - return; - } else { - //do nothing - } - // fallthru - case 15: - do { - System.identityHashCode("something"); - return; - } while(true); - case 16: - for (int j1 = 0; j1 < 10; j1++) { - System.identityHashCode("something"); - return; - } - case 17: - while (cond) - throw new RuntimeException(""); - case 18: - while(cond) { - break; - } - // fallthru - case 19: - try { - i++; - break; - } catch (RuntimeException e) { - break; - } catch (Error e) { - return; - } - case 20: - try { - i++; - break; - } catch (RuntimeException e) { - } catch (Error e) { - return; - } - // fallthru - case 21: - try { - i++; - } catch (RuntimeException e) { - i--; - } finally { - break; - } - case 22: - try { - i++; - break; - } catch (RuntimeException e) { - i--; - break; - } finally { - i++; - } - /* fallthru */ - case 23: - switch (j) { - case 1: - continue; - case 2: - return; - default: - return; - } - case 24: - i++; - /* fallthru */ case 25: - i++; - break; + case 15: + do { + System.identityHashCode("something"); + return; + } while (true); + case 16: + for (int j1 = 0; j1 < 10; j1++) { + System.identityHashCode("something"); + return; + } + case 17: + while (cond) { + throw new RuntimeException(""); + } + case 18: + while (cond) { + break; + } + // fallthru + case 19: + try { + i++; + break; + } catch (RuntimeException e) { + break; + } catch (Error e) { + return; + } + case 20: + try { + i++; + break; + } catch (RuntimeException e) { + return; + } catch (Error e) { + return; + } + // fallthru + case 21: + try { + i++; + } catch (RuntimeException e) { + i--; + } finally { + break; + } + case 22: + try { + i++; + break; + } catch (RuntimeException e) { + i--; + break; + } finally { + i++; + } + /* fallthru */ + case 23: + switch (j) { + case 1: + continue; + case 2: + return; + default: + return; + } + case 24: + i++; + /* fallthru */ case 25: + i++; + break; - case 26: - switch (j) { - case 1: - continue; - case 2: - break; - default: - return; - } - // fallthru - default: - // this is the last label - i++; + case 26: + switch (j) { + case 1: + continue; + case 2: + break; + default: + return; + } + // fallthru + default: + // this is the last label + i++; // fallthru - } } - } + } + } - /* Test relief comment. */ - void methodFallThruCC(int i, int j, boolean cond) { - while (true) { - switch (i){ - case 0: - i++; // fallthru + /* Test relief comment. */ + void methodFallThruCc(int i, int j, boolean cond) { + while (true) { + switch (i) { // violation 'switch without "default" clause.' + case 0: + i++; // fallthru - case 1: - i++; + case 1: + i++; // fallthru - case 2: { - i++; - } - // fallthru - case 3: - i++; - /* fallthru */case 4: - break; - case 5: - i++; + case 2: { + i++; + } + // fallthru + case 3: + i++; + /* fallthru */ case 4: + break; + case 5: + i++; // fallthru - } } - } + } + } - /* Like above, but C-style comments. */ - void methodFallThruC(int i, int j, boolean cond) { - while (true) { - switch (i){ - case 0: - i++; /* fallthru */ + /* Like above, but C-style comments. */ + void methodFallThruC(int i, int j, boolean cond) { + while (true) { + switch (i) { // violation 'switch without "default" clause.' + case 0: + i++; /* fallthru */ - case 1: - i++; + case 1: + i++; /* fallthru */ - case 2: - i++; - /* fallthru */case 3: - break; - case 4: - i++; + case 2: + i++; + /* fallthru */ case 3: + break; + case 4: + i++; /* fallthru */ - } } - } + } + } - /* Like above, but C-style comments with no spaces. */ - void methodFallThruC2(int i, int j, boolean cond) { - while (true) { - switch (i){ - case 0: - i++; /*fallthru*/ + /* Like above, but C-style comments with no spaces. */ + void methodFallThruC2(int i, int j, boolean cond) { + while (true) { + switch (i) { // violation 'switch without "default" clause.' + case 0: + i++; /*fallthru*/ - case 1: - i++; + case 1: + i++; /*fallthru*/ - case 2: - i++; - /*fallthru*/case 3: - break; - case 4: - i++; + case 2: + i++; + /*fallthru*/ case 3: + break; + case 4: + i++; /*fallthru*/ - } } - } + } + } - /* C-style comments with other default fallthru-comment. */ - void methodFallThruCOtherWords(int i, int j, boolean cond) { - while (true) { - switch (i){ - case 0: - i++; /* falls through */ + /* C-style comments with other default fallthru-comment. */ + void methodFallThruOtherWords(int i, int j, boolean cond) { + while (true) { + switch (i) { // violation 'switch without "default" clause.' + case 0: + i++; /* falls through */ - case 1: - i++; + case 1: + i++; /* falls through */ - case 2: - i++; - /* falls through */case 3: - break; - case 4: - i++; + case 2: + i++; + /* falls through */ case 3: + break; + case 4: + i++; /* falls through */ - } } - } + } + } - /* C-style comments with custom fallthru-comment. */ - void methodFallThruCustomWords(int i, int j, boolean cond) { - while (true) { - switch (i){ - case 0: - i++; /* Continue with next case */ + /* C-style comments with custom fallthru-comment. */ + void methodFallThruCustomWords(int i, int j, boolean cond) { + while (true) { + switch (i) { // violation 'switch without "default" clause.' + case 0: + i++; /* Continue with next case */ - case 1: // violation 'Fall through from previous branch of the switch statement.' - i++; + case 1: // violation 'Fall through from previous branch of the switch statement.' + i++; /* Continue with next case. */ - case 2: // violation 'Fall through from previous branch of the switch statement.' - i++; - /* Continue with next case. */case 3: - // violation above 'Fall through from previous branch of the switch statement.' - break; - case 4: - i++; + case 2: // violation 'Fall through from previous branch of the switch statement.' + i++; + /* Continue with next case. */ case 3: + // violation above 'Fall through from previous branch of the switch statement.' + break; + case 4: + i++; /* Continue with next case */ - } } - } + } + } - void methodFallThruLastCaseGroup(int i, int j, boolean cond) { - while (true) { - switch (i){ - case 0: - i++; // fallthru - } - switch (i){ - case 0: - i++; - // fallthru - } - switch (i){ - case 0: - i++; - /* fallthru */ } - } + void methodFallThruLastCaseGroup(int i, int j, boolean cond) { + while (true) { + switch (i) { // violation 'switch without "default" clause.' + case 0: + i++; // fallthru + } + switch (i) { // violation 'switch without "default" clause.' + case 0: + i++; + // fallthru + } + switch (i) { // violation 'switch without "default" clause.' + case 0: + i++; + /* fallthru */ + } } + } - void method1472228(int i) { - switch(i) { - case 2: - // do nothing - break; - default: - } + void method1472228(int i) { + switch (i) { + case 2: + // do nothing + break; + 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: // violation 'Fall through from previous branch of the switch statement.' - i++; // fall+through - case 14: // violation 'Fall through from previous branch of the switch statement.' - i++; // falls_thru - case 15: // violation 'Fall through from previous branch of the switch statement.' - i++; // falls=through - case 16: // violation 'Fall through from previous branch of the switch statement.' - i++; // falls-throug - default: // violation 'Fall through from previous branch of the switch statement.' - throw new RuntimeException(); - } + /* 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: // violation 'Fall through from previous branch of the switch statement.' + i++; // fall+through + case 14: // violation 'Fall through from previous branch of the switch statement.' + i++; // falls_thru + case 15: // violation 'Fall through from previous branch of the switch statement.' + i++; // falls=through + case 16: // violation 'Fall through from previous branch of the switch statement.' + i++; // falls-throug + default: // violation 'Fall through from previous branch of the switch statement.' + throw new RuntimeException(); } - } + } + } }