View Javadoc
1   /*
2   UnusedLocalVariable
3   allowUnnamedVariables = false
4   
5   */
6   
7   package com.puppycrawl.tools.checkstyle.checks.coding.unusedlocalvariable;
8   
9   public class InputUnusedLocalVariableSwitchStatement2 {
10      public void testParameters0() {
11  
12          int i = 0;
13          switch (i+1) {
14              default:
15              case 0:
16                  System.out.println("one: ");
17                  break;
18              case 1:
19                  System.out.println("two: " );
20                  break;
21          }
22  
23      }
24  
25      public void testParameters01() {
26          int i = 0;
27          switch (1+i) {
28              default:
29              case 0:
30                  System.out.println("one: ");
31                  break;
32              case 1:
33                  System.out.println("two: " );
34                  break;
35          }
36  
37      }
38  
39      public void testParameters() {
40          String[] tests = { "one", "two" };
41          int i = 0;
42          for (String test : tests) {
43              switch (i+1) {
44                  default:
45                  case 0:
46                      System.out.println("one: " + test);
47                      break;
48                  case 1:
49                      System.out.println("two: " + test);
50                      break;
51              }
52          }
53      }
54  
55      public void testParameters2() {
56          String[] tests = { "one", "two" };
57          int i = 0;
58          i++;
59          int j = 0; // violation, 'Unused local variable 'j''
60          for (String test : tests) {
61              switch (i) {
62                  default:
63                  case 0:
64                      j++;
65                      System.out.println("one: " + test);
66                      break;
67                  case 1:
68                      System.out.println("two: " + test);
69                      break;
70              }
71          }
72      }
73  
74      public void testParameters4() {
75          int i = 2;
76          int j = 1;
77          switch (j) {
78              case 1:
79                  System.out.println("j is 1");
80                  break;
81              case 2:
82                  System.out.println("j is 2");
83                  System.out.println("i is: " + i);
84                  break;
85              default:
86                  System.out.println("j is something else");
87          }
88      }
89  
90      public void testParameters5() {
91          int i = 2;
92          int j = 1;
93          switch (++j) {
94              case 1:
95                  System.out.println("j is 1");
96                  break;
97              case 2:
98                  System.out.println("j is 2");
99                  System.out.println("i is: " + ++i);
100                 break;
101             default:
102                 System.out.println("j is something else");
103         }
104     }
105 }