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