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