View Javadoc
1   package com.puppycrawl.tools.checkstyle.checks.coding.hiddenfield;
2   
3   ////////////////////////////////////////////////////////////////////////////////
4   // Test case file for checkstyle.
5   // Created: 2002
6   ////////////////////////////////////////////////////////////////////////////////
7   
8   /**
9    * Test case for hidden fields
10   * @author Rick Giles
11   **/
12  class InputHiddenFieldReorder
13  {
14  
15      
16      public InputHiddenFieldReorder()
17      {
18          int hidden = 0; //shadows field
19      }
20      
21      public InputHiddenFieldReorder(int hidden) //parameter shadows field
22      {
23      }
24      
25      public void shadow()
26      {
27          int hidden = 0; //shadows field
28      }
29      
30      public void shadowFor()
31      {
32          for (int hidden = 0; hidden < 1; hidden++) { //shadows field
33          }
34      }
35      
36      public void shadowParam(int hidden) //parameter shadows field
37      {
38      }
39      
40      public class Inner
41      {
42  //        private int innerHidden = 0;
43          
44          public Inner()
45          {
46              int innerHidden = 0; //shadows field
47          }
48      
49          public Inner(int innerHidden) //shadows field
50          {
51          }
52          
53          private void innerShadow()
54          {
55              int innerHidden = 0; //shadows inner field
56              int hidden = 0; //shadows outer field
57          }
58          
59          private void innerShadowFor()
60          {
61              for (int innerHidden = 0; innerHidden < 1; innerHidden++) {
62              }
63              //shadows outer field
64              for (int hidden = 0; hidden < 1; hidden++) {
65              }
66          }
67          
68          private void shadowParam(
69              int innerHidden, //parameter shadows inner field
70              int hidden //parameter shadows outer field
71          )
72          {
73          }
74          
75          {
76              int innerHidden = 0;//shadows inner field
77              int hidden = 0; //shadows outer field
78          }
79          private int innerHidden = 0;
80      }
81  
82      {
83          int hidden = 0;//shadows field
84      }
85      private int hidden = 0;       
86  }
87      
88  interface NothingHiddenReorder
89  {
90      public static int notHidden = 0;
91      
92      // not an error
93      public void noShadow(int notHidden);
94  }
95  
96  enum HiddenEnum1
97  {
98      A(129),
99      B(283),
100     C(1212)
101     {
102         public void doSomething()
103         {
104             //Should be flagged as hiding enum constant member
105             int hidden = 0;
106         }
107 
108         /**
109          * Should not be flagged as error as we don't check
110          * hidden class level fields
111          */
112         int hidden;
113     };
114 
115     /**
116      * ctor parameter hides member
117      */
118     HiddenEnum1(int hidden)
119     {
120     }
121 
122     public void doSomething()
123     {
124         //Should be flagged as hiding static member
125         int hidden = 0;
126     }
127 
128     public static void doSomethingStatic()
129     {
130         //Should be flagged as hiding static member
131         int hiddenStatic = 0;
132     }
133 
134     int hidden;
135     static int hiddenStatic;
136 }