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