View Javadoc
1   package com.puppycrawl.tools.checkstyle.checks.coding.finallocalvariable;
2   
3   import java.util.ArrayList;
4   
5   public class InputFinalLocalVariableAssignedInsideAndOutsideSwitch {
6   
7       private static void foo1(final int[][] m, final int x, final int y,
8                                   final int d, final int[] regionSizes) {
9           final int a = m[y][x] & 1;
10          int b;
11          switch (d) {
12              case 1:
13                  b = m[y - 1][x];
14                  break;
15              case 2:
16                  b = m[y][x - 1];
17                  break;
18              case 3:
19                  b = m[y][x + 1];
20                  break;
21              default:
22                  b = m[y + 1][x];
23                  break;
24          }
25          b &= 5;
26      }
27  
28      private static void foo2(final int[][] m, final int x, final int y,
29                                  final int d, final int[] regionSizes) {
30          final int a = m[y][x] & 1;
31          int b; // violation
32          switch (d) {
33              case 1:
34                  break;
35              case 2:
36                  b = m[y][x - 1];
37                  break;
38              case 3:
39                  b = m[y][x + 1];
40                  break;
41              default:
42                  b = m[y + 1][x];
43                  break;
44          }
45      }
46  
47      private static void foo3(final int[][] m, final int x, final int y,
48                                   final int d, final int[] regionSizes) {
49          final int a = m[y][x] & 1;
50          int b;
51          switch (d) {
52              case 1:
53              case 2:
54              case 3:
55                  b = m[y][x + 1];
56                  break;
57              default:
58                  b = m[y + 1][x];
59                  break;
60          }
61          b &= 5;
62      }
63  }