View Javadoc
1   /*
2   UnusedLocalVariable
3   allowUnnamedVariables = false
4   
5   */
6   
7   package com.puppycrawl.tools.checkstyle.checks.coding.unusedlocalvariable;
8   
9   public class InputUnusedLocalVariableAnonInnerClasses {
10  
11      static int a = 12, b = 13, c = 14;
12  
13      public void testAnonymousInnerClass() {
14          int a = 12; // violation, 'Unused local variable'
15          int b = 12; // violation, 'Unused local variable'
16          int k = 14;
17          Test obj = new Test() { // violation, 'Unused local variable'
18              int a = 2;
19  
20              private void testSameName(int s) {
21                  s = a + InputUnusedLocalVariable.a;
22                  Test obj = new Test() { // violation, 'Unused local variable'
23                      int b = 1;
24  
25                      private void testSameNameNested(int s) {
26                          s = b + InputUnusedLocalVariable.b + InputUnusedLocalVariable.a + a + k;
27                      }
28                  };
29              }
30          };
31  
32          Test obj2; // violation, 'Unused local variable'
33          obj2 = new Test() {
34              int a = 1;
35              int b = 1;
36              int c = 0;
37  
38              private void testSameName(int s) {
39                  s = a + b + this.a + this.b + InputUnusedLocalVariableAnonInnerClasses.a
40                          + InputUnusedLocalVariableAnonInnerClasses.b;
41              }
42          };
43      }
44  
45      {
46          int m = 12; // violation, 'Unused local variable'
47          int l = 2; // violation, 'Unused local variable'
48          d obj = new d() {
49              void method() {
50                  m += l;
51              }
52          };
53          obj.getClass();
54      }
55  
56      static {
57          int a = 1;
58          int x = 2;
59          int h = 3; // violation, 'Unused local variable'
60          m.Test obj = new m().new Test() {
61              void method() {
62                  boolean v = // violation, 'Unused local variable'
63                          a == x == (h == 2);
64              }
65          };
66          obj.getClass();
67      }
68  
69      class Test {
70          private int k = 1;
71      }
72  
73      static class m {
74          public int x = 1;
75  
76          class Test {
77              public int h = 12;
78          }
79      }
80  
81      class d {
82          protected int m = 11;
83          int l = 14;
84      }
85  
86  }