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