View Javadoc
1   /*
2   FinalLocalVariable
3   validateEnhancedForLoopVariable = (default)false
4   tokens = (default)VARIABLE_DEF
5   
6   
7   */
8   
9   package com.puppycrawl.tools.checkstyle.checks.coding.finallocalvariable;
10  
11  public class InputFinalLocalVariableFour {
12  
13      class Class3 {
14          public void test1() {
15              final boolean b = true;
16              int shouldBeFinal;        // violation
17  
18              if (b) {
19                  shouldBeFinal = 1;
20              }
21              else {
22                  shouldBeFinal = 2;
23              }
24          }
25  
26          public void test2() {
27              final int b = 10;
28              int shouldBeFinal;        // violation
29  
30              switch (b) {
31                  case 0:
32                      shouldBeFinal = 1;
33                      break;
34                  default:
35                      shouldBeFinal = 2;
36                      break;
37              }
38          }
39  
40          public void test3() {
41              int x;        // No Violation
42              try {
43                  x = 0;
44              } catch (final Exception e) {
45                  x = 1;
46              }
47  
48              int y;        // No Violation
49              try {
50                  y = 0;
51              } finally {
52                  y = 1;
53              }
54          }
55  
56          public void test4() {
57              final boolean b = false;
58              int x;        // No Violation
59              if (b) {
60                  x = 1;
61              } else {
62                  x = 2;
63              }
64  
65              if(b) {
66                  x = 3;
67              }
68          }
69  
70          public void test5() {
71              final boolean b = false;
72              int shouldBeFinal;    // violation
73              if(b) {
74              }
75              if (b) {
76                  shouldBeFinal = 1;
77              } else {
78                  shouldBeFinal = 2;
79              }
80          }
81      }
82  
83      class class4 {
84          public void foo() {
85              int shouldBeFinal;    // violation
86              class Bar {
87                  void bar () {
88                      int shouldBeFinal;    // violation
89                      final boolean b = false;
90                      if (b) {
91                          shouldBeFinal = 1;
92                      } else {
93                          shouldBeFinal = 2;
94                      }
95                  }
96              }
97          }
98      }
99  
100 }