    1   /*
    2    * Created on 18.08.2004
    3    */
    4   package test.net.sourceforge.pmd.dfa;
    5
    6   import net.sourceforge.pmd.PMD;
    7   import net.sourceforge.pmd.ast.ASTMethodDeclarator;
    8   import net.sourceforge.pmd.dfa.IDataFlowNode;
    9   import test.net.sourceforge.pmd.testframework.ParserTst;
    10
    11  import java.util.List;
    12
    13  public class AcceptanceTest extends ParserTst {
    14
    15      public void testbook() throws Throwable {
    16          getOrderedNodes(ASTMethodDeclarator.class, FOO);
    17      }
    18
    19      private static final String FOO =
    20              "class Foo {" + PMD.EOL +
    21              " void bar() {" + PMD.EOL +
    22              "  int x = 2;" + PMD.EOL +
    23              " }" + PMD.EOL +
    24              "}";
    25
    26      public void testLabelledBreakLockup() throws Throwable {
    27          getOrderedNodes(ASTMethodDeclarator.class, LABELLED_BREAK_LOCKUP);
    28      }
    29
    30      private static final String LABELLED_BREAK_LOCKUP =
    31              "class Foo {" + PMD.EOL +
    32              " void bar(int x) {" + PMD.EOL +
    33              "  here: if (x>2) {" + PMD.EOL +
    34              "   break here;" + PMD.EOL +
    35              "  }" + PMD.EOL +
    36              " }" + PMD.EOL +
    37              "}";
    38
    39      private boolean check(int[][] array, List methodNodes) {
    40          for (int i = 0; i < methodNodes.size(); i++) {
    41              ASTMethodDeclarator decl = (ASTMethodDeclarator) methodNodes.get(i);
    42              IDataFlowNode inode = decl.getDataFlowNode();
    43              for (int j = 0; j < inode.getChildren().size(); j++) {
    44                  IDataFlowNode child = (IDataFlowNode) inode.getChildren().get(j);
    45                  if (array[i][j] != child.getIndex() - 1) {
    46                      return false;
    47                  }
    48              }
    49          }
    50          return true;
    51      }
    52
    53      public void test_1() throws Throwable {
    54          assertTrue(check(TEST1_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST1)));
    55      }
    56
    57      public void test_2() throws Throwable {
    58          assertTrue(check(TEST2_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST2)));
    59      }
    60
    61      public void test_3() throws Throwable {
    62          assertTrue(check(TEST3_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST3)));
    63      }
    64
    65      public void test_4() throws Throwable {
    66          assertTrue(check(TEST4_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST4)));
    67      }
    68
    69      public void test_6() throws Throwable {
    70          assertTrue(check(TEST5_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST6)));
    71      }
    72
    73      public void test_7() throws Throwable {
    74          assertTrue(check(TEST5_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST7)));
    75      }
    76
    77      public void test_8() throws Throwable {
    78          assertTrue(check(TEST8_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST8)));
    79      }
    80
    81      public void test_9() throws Throwable {
    82          assertTrue(check(TEST5_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST9)));
    83      }
    84
    85      public void test_10() throws Throwable {
    86          assertTrue(check(TEST8_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST10)));
    87      }
    88
    89      public void test_11() throws Throwable {
    90          assertTrue(check(TEST8_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST11)));
    91      }
    92
    93      public void test_12() throws Throwable {
    94          assertTrue(check(TEST12_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST12)));
    95      }
    96
    97      public void test_13() throws Throwable {
    98          assertTrue(check(TEST13_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST13)));
    99      }
    100
    101     public void test_14() throws Throwable {
    102         assertTrue(check(TEST14_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST14)));
    103     }
    104
    105     public void test_15() throws Throwable {
    106         assertTrue(check(TEST15_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST15)));
    107     }
    108
    109     public void test_16() throws Throwable {
    110         assertTrue(check(TEST16_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST16)));
    111     }
    112
    113     public void test_17() throws Throwable {
    114         assertTrue(check(TEST17_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST17)));
    115     }
    116
    117     public void test_18() throws Throwable {
    118         assertTrue(check(TEST18_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST18)));
    119     }
    120
    121     public void test_19() throws Throwable {
    122         assertTrue(check(TEST19_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST19)));
    123     }
    124
    125     public void test_20() throws Throwable {
    126         assertTrue(check(TEST20_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST20)));
    127     }
    128
    129     public void test_21() throws Throwable {
    130         assertTrue(check(TEST21_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST21)));
    131     }
    132
    133     public void test_22() throws Throwable {
    134         assertTrue(check(TEST22_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST22)));
    135     }
    136
    137     public void test_23() throws Throwable {
    138         assertTrue(check(TEST23_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST23)));
    139     }
    140
    141     public void test_24() throws Throwable {
    142         assertTrue(check(TEST24_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST24)));
    143     }
    144
    145     public void test_25() throws Throwable {
    146         assertTrue(check(TEST25_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST25)));
    147     }
    148
    149     public void test_26() throws Throwable {
    150         assertTrue(check(TEST26_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST26)));
    151     }
    152
    153     public void test_27() throws Throwable {
    154         assertTrue(check(TEST27_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST27)));
    155     }
    156
    157     public void test_28() throws Throwable {
    158         assertTrue(check(TEST28_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST28)));
    159     }
    160
    161     public void test_29() throws Throwable {
    162         assertTrue(check(TEST29_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST29)));
    163     }
    164
    165     public void test_30() throws Throwable {
    166         assertTrue(check(TEST30_NODES, getOrderedNodes(ASTMethodDeclarator.class, TEST30)));
    167     }
    168
    169     //  first dimension: the index of a node
    170     //  second dimension: the indices of the children
    171     private static final int[][] TEST1_NODES = {
    172         {1},
    173         {2},
    174         {3},
    175         {4, 6},
    176         {5},
    177         {6},
    178         {}
    179     };
    180
    181     private static final String TEST1 =
    182             "class Foo {" + PMD.EOL +
    183             " void test_1() {" + PMD.EOL +
    184             "  int x = 0;" + PMD.EOL +
    185             "  if (x == 0) {" + PMD.EOL +
    186             "   x++;" + PMD.EOL +
    187             "   x = 0;" + PMD.EOL +
    188             "  }" + PMD.EOL +
    189             " }" + PMD.EOL +
    190             " }";
    191
    192     private static final int[][] TEST2_NODES = {
    193         {1},
    194         {2},
    195         {3},
    196         {5, 7},
    197         {3},
    198         {6},
    199         {4},
    200         {}
    201     };
    202
    203     private static final String TEST2 =
    204             "class Foo {" + PMD.EOL +
    205             " public void test_2() {" + PMD.EOL +
    206             "  for (int i = 0; i < 1; i++) {" + PMD.EOL +
    207             "   i++;" + PMD.EOL +
    208             "   i = 8;" + PMD.EOL +
    209             "  }" + PMD.EOL +
    210             " }" + PMD.EOL +
    211             " }";
    212
    213     private static final int[][] TEST3_NODES = {
    214         {1},
    215         {2},
    216         {3},
    217         {4, 5},
    218         {3},
    219         {}
    220     };
    221
    222     private static final String TEST3 =
    223             "public class Foo {" + PMD.EOL +
    224             " public void test_3() {" + PMD.EOL +
    225             "  for (int i = 0; i < 1; i++) {" + PMD.EOL +
    226             "  }" + PMD.EOL +
    227             " }" + PMD.EOL +
    228             " }";
    229
    230
    231     private static final int[][] TEST4_NODES = {
    232         {1},
    233         {2},
    234         {3},
    235         {}
    236     };
    237
    238     private static final String TEST4 =
    239             "public class Foo {" + PMD.EOL +
    240             " public void test_4() {" + PMD.EOL +
    241             "  for (; ;) {" + PMD.EOL +
    242             "  }" + PMD.EOL +
    243             " }" + PMD.EOL +
    244             " }";
    245
    246     private static final int[][] TEST5_NODES = {
    247         {1},
    248         {2},
    249         {3},
    250         {4},
    251         {}
    252     };
    253
    254     private static final String TEST6 =
    255             "public class Foo {" + PMD.EOL +
    256             " public void test_6() {" + PMD.EOL +
    257             "  for (int i = 0; ;) {" + PMD.EOL +
    258             "  }" + PMD.EOL +
    259             " }" + PMD.EOL +
    260             " }";
    261
    262     private static final String TEST7 =
    263             "public class Foo {" + PMD.EOL +
    264             " public void test_7() {" + PMD.EOL +
    265             "  for (int i = 0; i < 0;) {" + PMD.EOL +
    266             "  }" + PMD.EOL +
    267             " }" + PMD.EOL +
    268             " }";
    269
    270     private static final int[][] TEST8_NODES = {
    271         {1},
    272         {2},
    273         {3},
    274         {4, 5},
    275         {3},
    276         {}
    277     };
    278
    279     public static final String TEST8 =
    280             "public class Foo {" + PMD.EOL +
    281             " public void test_8() {" + PMD.EOL +
    282             "  for (int i = 0; ; i++) {" + PMD.EOL +
    283             "  }" + PMD.EOL +
    284             " }" + PMD.EOL +
    285             " }";
    286
    287     public static final String TEST9 =
    288             "public class Foo {" + PMD.EOL +
    289             " public void test_9() {" + PMD.EOL +
    290             "  int i = 0;" + PMD.EOL +
    291             "  for (; i < 0;) {" + PMD.EOL +
    292             "  }" + PMD.EOL +
    293             " }" + PMD.EOL +
    294             " }";
    295
    296     public static final String TEST10 =
    297             "public class Foo {" + PMD.EOL +
    298             " public void test_10() {" + PMD.EOL +
    299             "  int i = 0;" + PMD.EOL +
    300             "  for (; i < 0; i++) {" + PMD.EOL +
    301             "  }" + PMD.EOL +
    302             " }" + PMD.EOL +
    303             " }";
    304
    305     public static final String TEST11 =
    306             "public class Foo {" + PMD.EOL +
    307             " public void test_11() {" + PMD.EOL +
    308             "  int i = 0;" + PMD.EOL +
    309             "  for (; ; i++) {" + PMD.EOL +
    310             "  }" + PMD.EOL +
    311             " }" + PMD.EOL +
    312             " }";
    313
    314     private static final int[][] TEST12_NODES = {
    315         {1},
    316         {2},
    317         {3},
    318         {4, 5},
    319         {3},
    320         {}
    321     };
    322     public static final String TEST12 =
    323             "public class Foo {" + PMD.EOL +
    324             " public void test_12() {" + PMD.EOL +
    325             "  for (; ;) {" + PMD.EOL +
    326             "   int i = 0;" + PMD.EOL +
    327             "  }" + PMD.EOL +
    328             " }" + PMD.EOL +
    329             " }";
    330
    331     private static final int[][] TEST13_NODES = {
    332         {1},
    333         {2},
    334         {3},
    335         {5, 9},
    336         {3},
    337         {6},
    338         {7, 8},
    339         {8},
    340         {4},
    341         {}
    342     };
    343     public static final String TEST13 =
    344             "public class Foo {" + PMD.EOL +
    345             " public void test_13() {" + PMD.EOL +
    346             "  for (int i = 0; i < 0; i++) {" + PMD.EOL +
    347             "   i = 9;" + PMD.EOL +
    348             "   if (i < 8) {" + PMD.EOL +
    349             "    i = 7;" + PMD.EOL +
    350             "   }" + PMD.EOL +
    351             "   i = 6;" + PMD.EOL +
    352             "  }" + PMD.EOL +
    353             " }" + PMD.EOL +
    354             " }";
    355
    356     private static final int[][] TEST14_NODES = {
    357         {1},
    358         {2},
    359         {3},
    360         {5, 8},
    361         {3},
    362         {6},
    363         {7, 4},
    364         {4},
    365         {}
    366     };
    367     public static final String TEST14 =
    368             "public class Foo {" + PMD.EOL +
    369             " public void test_14() {" + PMD.EOL +
    370             "  for (int i = 0; i < 0; i++) {" + PMD.EOL +
    371             "   i = 9;" + PMD.EOL +
    372             "   if (i < 8) {" + PMD.EOL +
    373             "    i = 7;" + PMD.EOL +
    374             "   }" + PMD.EOL +
    375             "  }" + PMD.EOL +
    376             " }" + PMD.EOL +
    377             " }";
    378
    379     private static final int[][] TEST15_NODES = {
    380         {1},
    381         {2},
    382         {3},
    383         {5, 7},
    384         {3},
    385         {6, 4},
    386         {4},
    387         {}
    388     };
    389     public static final String TEST15 =
    390             "public class Foo {" + PMD.EOL +
    391             " public void test_15() {" + PMD.EOL +
    392             "  for (int i = 0; i < 0; i++) {" + PMD.EOL +
    393             "   if (i < 8) {" + PMD.EOL +
    394             "    i = 7;" + PMD.EOL +
    395             "   }" + PMD.EOL +
    396             "  }" + PMD.EOL +
    397             " }" + PMD.EOL +
    398             " }";
    399
    400     private static final int[][] TEST16_NODES = {
    401         {1},
    402         {2},
    403         {3},
    404         {5, 8},
    405         {3},
    406         {6, 7},
    407         {4},
    408         {4},
    409         {}
    410     };
    411     public static final String TEST16 =
    412             "public class Foo {" + PMD.EOL +
    413             " public void test_16() {" + PMD.EOL +
    414             "  for (int i = 0; i < 0; i++) {" + PMD.EOL +
    415             "   if (i < 8) {" + PMD.EOL +
    416             "    i = 7;" + PMD.EOL +
    417             "   } else {" + PMD.EOL +
    418             "    i = 6;" + PMD.EOL +
    419             "   }" + PMD.EOL +
    420             "  }" + PMD.EOL +
    421             " }" + PMD.EOL +
    422             " }";
    423
    424     private static final int[][] TEST17_NODES = {
    425         {1},
    426         {2},
    427         {3},
    428         {5, 10},
    429         {3},
    430         {6, 7},
    431         {4},
    432         {8, 9},
    433         {4},
    434         {4},
    435         {}
    436     };
    437     public static final String TEST17 =
    438             "public class Foo {" + PMD.EOL +
    439             " public void test_17() {" + PMD.EOL +
    440             "  for (int i = 0; i < 0; i++) {" + PMD.EOL +
    441             "   if (i < 6) {" + PMD.EOL +
    442             "    i = 7;" + PMD.EOL +
    443             "   } else if (i > 8) {" + PMD.EOL +
    444             "    i = 9;" + PMD.EOL +
    445             "   } else {" + PMD.EOL +
    446             "    i = 10;" + PMD.EOL +
    447             "   }" + PMD.EOL +
    448             "  }" + PMD.EOL +
    449             " }" + PMD.EOL +
    450             " }";
    451
    452     private static final int[][] TEST18_NODES = {
    453         {1},
    454         {2},
    455         {3},
    456         {5, 9},
    457         {3},
    458         {6},
    459         {8, 4},
    460         {6},
    461         {7},
    462         {}
    463     };
    464     public static final String TEST18 =
    465             "public class Foo {" + PMD.EOL +
    466             " public void test_18() {" + PMD.EOL +
    467             "  for (int i = 0; i < 0; i++) {" + PMD.EOL +
    468             "   for (int j = 0; j < 0; j++) {" + PMD.EOL +
    469             "    j++;" + PMD.EOL +
    470             "   }" + PMD.EOL +
    471             "  }" + PMD.EOL +
    472             " }" + PMD.EOL +
    473             " }";
    474
    475     private static final int[][] TEST19_NODES = {
    476         {1},
    477         {2},
    478         {3},
    479         {4, 5},
    480         {10},
    481         {6, 7},
    482         {10},
    483         {8, 9},
    484         {10},
    485         {10},
    486         {}
    487     };
    488     public static final String TEST19 =
    489             "public class Foo {" + PMD.EOL +
    490             " public void test_19() {" + PMD.EOL +
    491             "  int i = 0;" + PMD.EOL +
    492             "  if (i == 1) {" + PMD.EOL +
    493             "   i = 2;" + PMD.EOL +
    494             "  } else if (i == 3) {" + PMD.EOL +
    495             "   i = 4;" + PMD.EOL +
    496             "  } else if (i == 5) {" + PMD.EOL +
    497             "   i = 6;" + PMD.EOL +
    498             "  } else {" + PMD.EOL +
    499             "   i = 7;" + PMD.EOL +
    500             "  }" + PMD.EOL +
    501             " }" + PMD.EOL +
    502             " }";
    503
    504     private static final int[][] TEST20_NODES = {
    505         {1},
    506         {2},
    507         {3},
    508         {4, 6},
    509         {5, 7},
    510         {7},
    511         {7},
    512         {}
    513     };
    514     public static final String TEST20 =
    515             "public class Foo {" + PMD.EOL +
    516             " public void test_20() {" + PMD.EOL +
    517             "  int i = 0;" + PMD.EOL +
    518             "  if (i == 1) {" + PMD.EOL +
    519             "   if (i == 2) {" + PMD.EOL +
    520             "    i = 3;" + PMD.EOL +
    521             "   }" + PMD.EOL +
    522             "  } else {" + PMD.EOL +
    523             "   i = 7;" + PMD.EOL +
    524             "  }" + PMD.EOL +
    525             " }" + PMD.EOL +
    526             " }";
    527
    528     private static final int[][] TEST21_NODES = {
    529         {1},
    530         {2},
    531         {3},
    532         {4, 9},
    533         {5},
    534         {7, 8},
    535         {5},
    536         {6},
    537         {11},
    538         {10, 11},
    539         {11},
    540         {}
    541     };
    542     public static final String TEST21 =
    543             "public class Foo {" + PMD.EOL +
    544             " public void test_21() {" + PMD.EOL +
    545             "  int i = 0;" + PMD.EOL +
    546             "  if (i == 1) {" + PMD.EOL +
    547             "   for (i = 3; i < 4; i++) {" + PMD.EOL +
    548             "    i = 5;" + PMD.EOL +
    549             "   }" + PMD.EOL +
    550             "   i++;" + PMD.EOL +
    551             "  } else if (i < 6) {" + PMD.EOL +
    552             "   i = 7;" + PMD.EOL +
    553             "  }" + PMD.EOL +
    554             " }" + PMD.EOL +
    555             " }";
    556
    557     private static final int[][] TEST22_NODES = {
    558         {1},
    559         {2},
    560         {3},
    561         {4, 8},
    562         {5},
    563         {7, 9},
    564         {5},
    565         {6},
    566         {9},
    567         {}
    568     };
    569     public static final String TEST22 =
    570             "public class Foo {" + PMD.EOL +
    571             " public void test_22() {" + PMD.EOL +
    572             "  int i = 0;" + PMD.EOL +
    573             "  if (i == 1) {" + PMD.EOL +
    574             "   for (i = 3; i < 4; i++) {" + PMD.EOL +
    575             "    i = 5;" + PMD.EOL +
    576             "   }" + PMD.EOL +
    577             "  } else {" + PMD.EOL +
    578             "   i = 7;" + PMD.EOL +
    579             "  }" + PMD.EOL +
    580             " }" + PMD.EOL +
    581             " }";
    582
    583     private static final int[][] TEST23_NODES = {
    584         {1},
    585         {2},
    586         {3},
    587         {4, 8},
    588         {5},
    589         {7, 10},
    590         {5},
    591         {6},
    592         {9, 10},
    593         {10},
    594         {}
    595     };
    596     public static final String TEST23 =
    597             "public class Foo {" + PMD.EOL +
    598             " public void test_23() {" + PMD.EOL +
    599             "  int i = 0;" + PMD.EOL +
    600             "  if (i == 1) {" + PMD.EOL +
    601             "   for (i = 3; i < 4; i++) {" + PMD.EOL +
    602             "    i = 5;" + PMD.EOL +
    603             "   }" + PMD.EOL +
    604             "  } else if (i < 6) {" + PMD.EOL +
    605             "   i = 7;" + PMD.EOL +
    606             "  }" + PMD.EOL +
    607             " }" + PMD.EOL +
    608             " }";
    609
    610     private static final int[][] TEST24_NODES = {
    611         {1},
    612         {2},
    613         {3},
    614         {4, 9},
    615         {5},
    616         {7, 11},
    617         {5},
    618         {8, 6},
    619         {6},
    620         {10, 11},
    621         {11},
    622         {}
    623     };
    624     public static final String TEST24 =
    625             "public class Foo {" + PMD.EOL +
    626             " public void test_24() {" + PMD.EOL +
    627             "  int x = 0;" + PMD.EOL +
    628             "  if (x > 2) {" + PMD.EOL +
    629             "   for (int i = 0; i < 1; i++) {" + PMD.EOL +
    630             "    if (x > 3) {" + PMD.EOL +
    631             "     x++;" + PMD.EOL +
    632             "    }" + PMD.EOL +
    633             "   }" + PMD.EOL +
    634             "  } else if (x > 4) {" + PMD.EOL +
    635             "   x++;" + PMD.EOL +
    636             "  }" + PMD.EOL +
    637             " }" + PMD.EOL +
    638             " }";
    639
    640     private static final int[][] TEST25_NODES = {
    641         {1},
    642         {2},
    643         {3},
    644         {4, 5},
    645         {5},
    646         {}
    647     };
    648     public static final String TEST25 =
    649             "public class Foo {" + PMD.EOL +
    650             " public void test_25() {" + PMD.EOL +
    651             "  int x = 0;" + PMD.EOL +
    652             "  switch (x) {" + PMD.EOL +
    653             "   default:" + PMD.EOL +
    654             "    x = 9;" + PMD.EOL +
    655             "  }" + PMD.EOL +
    656             " }" + PMD.EOL +
    657             " }";
    658
    659     private static final int[][] TEST26_NODES = {
    660         {1},
    661         {2},
    662         {3},
    663         {4},
    664         {5, 6},
    665         {6},
    666         {7},
    667         {8, 3},
    668         {9},
    669         {}
    670     };
    671     public static final String TEST26 =
    672             "public class Foo {" + PMD.EOL +
    673             " public void test_26() {" + PMD.EOL +
    674             "  int x = 0;" + PMD.EOL +
    675             "  do {" + PMD.EOL +
    676             "   if (x > 0) {" + PMD.EOL +
    677             "    x++;" + PMD.EOL +
    678             "   }" + PMD.EOL +
    679             "   x++;" + PMD.EOL +
    680             "  } while (x < 9);" + PMD.EOL +
    681             "  x++;" + PMD.EOL +
    682             " }" + PMD.EOL +
    683             " }";
    684
    685     private static final int[][] TEST27_NODES = {
    686         {1},
    687         {2},
    688         {3},
    689         {5, 9},
    690         {3},
    691         {6},
    692         {7},
    693         {8},
    694         {6, 4},
    695         {}
    696     };
    697     public static final String TEST27 =
    698             "public class Foo {" + PMD.EOL +
    699             " public void test_27() {" + PMD.EOL +
    700             "  for (int i = 0; i < 36; i++) {" + PMD.EOL +
    701             "   int x = 0;" + PMD.EOL +
    702             "   do {" + PMD.EOL +
    703             "    x++;" + PMD.EOL +
    704             "   } while (x < 9);" + PMD.EOL +
    705             "  }" + PMD.EOL +
    706             " }" + PMD.EOL +
    707             " }";
    708
    709     private static final int[][] TEST28_NODES = {
    710         {1},
    711         {2},
    712         {3},
    713         {5, 14},
    714         {3},
    715         {6},
    716         {7},
    717         {8, 12},
    718         {9},
    719         {10, 12},
    720         {11},
    721         {12},
    722         {13},
    723         {6, 4},
    724         {}
    725     };
    726     public static final String TEST28 =
    727             "public class Foo {" + PMD.EOL +
    728             " private void test_28() {" + PMD.EOL +
    729             "  for (int i = 0; i < 36; i++) {" + PMD.EOL +
    730             "   int x = 0;" + PMD.EOL +
    731             "   do {" + PMD.EOL +
    732             "    if (x > 0) {" + PMD.EOL +
    733             "     x++;" + PMD.EOL +
    734             "     switch (i) {" + PMD.EOL +
    735             "      case 0:" + PMD.EOL +
    736             "       x = 0;" + PMD.EOL +
    737             "       break;" + PMD.EOL +
    738             "     }" + PMD.EOL +
    739             "    }" + PMD.EOL +
    740             "    x++;" + PMD.EOL +
    741             "   } while (x < 9);" + PMD.EOL +
    742             "  }" + PMD.EOL +
    743             " }" + PMD.EOL +
    744             " }";
    745
    746     private static final int[][] TEST29_NODES = {
    747         {1},
    748         {2},
    749         {3, 4, 5},
    750         {6},
    751         {6},
    752         {6},
    753         {}
    754
    755     };
    756     public static final String TEST29 =
    757             "public class Foo {" + PMD.EOL +
    758             " private void test_29() {" + PMD.EOL +
    759             "  switch(x) {" + PMD.EOL +
    760             "   case 1:" + PMD.EOL +
    761             "    break; " + PMD.EOL +
    762             "   default: " + PMD.EOL +
    763             "    break;" + PMD.EOL +
    764             "   case 2:" + PMD.EOL +
    765             "    break;" + PMD.EOL +
    766             "  }" + PMD.EOL +
    767             " }" + PMD.EOL +
    768             "}";
    769
    770     private static final int[][] TEST30_NODES = {
    771         {1},
    772         {2},
    773         {3},
    774         {4, 7},
    775         {5, 6},
    776         {4},
    777         {3},
    778         {}
    779     };
    780     public static final String TEST30 =
    781             "public class Foo {" + PMD.EOL +
    782             " private void test_30() {" + PMD.EOL +
    783             "  int x = 0;" + PMD.EOL +
    784             "  while (true) {" + PMD.EOL +
    785             "   while (x>0) {" + PMD.EOL +
    786             "     x++;" + PMD.EOL +
    787             "   }" + PMD.EOL +
    788             "   continue;" + PMD.EOL +
    789             "  }" + PMD.EOL +
    790             " }" + PMD.EOL +
    791             "}";
    792 }