View Javadoc
1   package com.puppycrawl.tools.checkstyle.checks.coding.declarationorder;
2   
3   public class InputDeclarationOrder
4   {
5       static final int FOO2 = 3;
6   
7       // error public before package
8       public static final int FOO = 3;
9       
10      private static final int FOO3 = 3;
11     
12      // eror public before package and private
13      public static final int FOO4 = 3;
14  
15      private static final String ERROR = "error";
16  
17      // error protected before private
18      protected static final String ERROR1 = "error";
19     
20      // error public before private
21      public static final String WARNING = "warning";
22      
23      private int mMaxInitVars = 3;
24      
25      // error statics should be before instance members
26      // error publics before private
27      public static final int MAX_ITER_VARS = 3;
28  
29      private class InnerClass
30      {
31          private static final int INNER_FOO = 2;
32         
33          // error public before private
34          public static final int INNER_FOO2 = 2;
35  
36          public InnerClass()
37          {
38              int foo = INNER_FOO;
39              foo += INNER_FOO2;
40              foo += INNER_FOO3;
41          }
42  
43          public InnerClass(int start)
44          {
45              int foo = start;
46              foo += INNER_FOO2;
47              foo += INNER_FOO3;
48          }
49  
50          // error member variables should be before methods or ctors
51          // error public before private
52          public static final int INNER_FOO3 = 2;
53      }
54  
55      public int getFoo1()
56      {
57          return mFoo;
58      }
59  
60      //  error ctors before methods
61      public InputDeclarationOrder()
62      {
63          String foo = ERROR;
64          foo += ERROR1;
65          foo += WARNING;
66          int fooInt = mMaxInitVars;
67          fooInt += MAX_ITER_VARS;
68          fooInt += mFoo;
69      }
70  
71      public static int getFoo2()
72      {
73          return 13;
74      }
75  
76      public int getFoo()
77      {
78          return mFoo;
79      }
80  
81      private static int getFoo21()
82      {
83          return 14;
84      }
85  
86      // error member variables should be before methods or ctors
87      private int mFoo = 0;
88  }
89  
90  enum InputDeclarationOrderEnum
91  {
92      ENUM_VALUE_1,
93      ENUM_VALUE_2,
94      ENUM_VALUE_3
95      {
96          private static final int INNER_FOO = 2;
97  
98          // error public before private
99          public static final int INNER_FOO2 = 2;
100 
101         public void doIt()
102         {
103         }
104 
105         // error member variables should be before methods or ctors
106         // error public before private
107         public static final int INNER_FOO3 = 2;
108     };
109 
110     static final int FOO2 = 3;
111 
112     // error public before package
113     public static final int FOO = 3;
114 
115     private static final int FOO3 = 3;
116 
117     // eror public before package and private
118     public static final int FOO4 = 3;
119 
120     private static final String ERROR = "error";
121 
122     // error protected before private
123     protected static final String ERROR1 = "error";
124 
125     // error public before private
126     public static final String WARNING = "warning";
127 
128     private int mMaxInitVars = 3;
129 
130     // error statics should be before instance members
131     // error publics before private
132     public static final int MAX_ITER_VARS = 3;
133 
134     private class InnerClass
135     {
136         private static final int INNER_FOO = 2;
137 
138         // error public before private
139         public static final int INNER_FOO2 = 2;
140 
141         public InnerClass()
142         {
143             int foo = INNER_FOO;
144             foo += INNER_FOO2;
145             foo += INNER_FOO3;
146         }
147 
148         // error member variables should be before methods or ctors
149         // error public before private
150         public static final int INNER_FOO3 = 2;
151     }
152 
153     public int getFoo1()
154     {
155         return mFoo;
156     }
157 
158     //  error ctors before methods
159     InputDeclarationOrderEnum()
160     {
161         String foo = ERROR;
162         foo += ERROR1;
163         foo += WARNING;
164         int fooInt = mMaxInitVars;
165         fooInt += MAX_ITER_VARS;
166         fooInt += mFoo;
167     }
168 
169     public static int getFoo2()
170     {
171         return 2;
172     }
173 
174     public int getFoo()
175     {
176         return mFoo;
177     }
178 
179     private static int getFoo21()
180     {
181         return 1;
182     }
183 
184     // error member variables should be before methods or ctors
185     private int mFoo = 0;
186 
187     class AsyncProcess {
188         private final int startLogErrorsCnt = 0;
189         protected final int maxTotalConcurrentTasks = 0;
190     }
191 }