View Javadoc
1   package com.google.checkstyle.test.chapter4formatting.rule487modifiers;
2   
3   abstract strictfp class InputFormattedModifierOrder {
4     private transient String dontSaveMe;
5   
6     public volatile int whatImReading;
7   
8     public volatile boolean ssModifierOrderVar = false;
9   
10    /**
11     * Illegal order of modifiers for methods. Make sure that the first and last modifier from the JLS
12     * sequence is used.
13     */
14    private strictfp void doStuff() {}
15  
16    /** Single annotation without other modifiers. */
17    @MyAnnotationFormatted
18    void someMethod() {}
19  
20    /** Illegal order of annotation - must come first. */
21    private @MyAnnotationFormatted void someMethod2() {}
22  
23    // violation 2 lines above '.* annotation modifier does not precede non-annotation modifiers.'
24  
25    /** Annotation in middle of other modifiers otherwise in correct order. */
26    private @MyAnnotationFormatted strictfp void someMethod3() {}
27  
28    // violation 2 lines above '.* annotation modifier does not precede non-annotation modifiers.'
29  
30    /** Correct order. */
31    @MyAnnotationFormatted
32    private strictfp void someMethod4() {}
33  
34    /** Annotation in middle of other modifiers otherwise in correct order. */
35    @MyAnnotationFormatted
36    public static @MyAnnotationFormatted2 strictfp void someMethod5() {}
37  
38    // violation 2 lines above '.* annotation modifier does not precede non-annotation modifiers.'
39  
40    @MyAnnotationFormatted
41    public static final synchronized strictfp void fooMethod() {}
42  
43    protected final strictfp @MyAnnotationFormatted static synchronized void fooMethod1() {}
44  
45    // violation 2 lines above '.* annotation modifier does not precede non-annotation modifiers.'
46  
47    synchronized @MyAnnotationFormatted private static final strictfp void fooMethod2() {}
48  
49    // violation 2 lines above '.* annotation modifier does not precede non-annotation modifiers.'
50  
51    @MyAnnotationFormatted
52    protected static final synchronized strictfp void fooMethod3() {}
53  
54    @MyAnnotationFormatted
55    private static final synchronized strictfp void fooMethod4() {}
56  
57    final synchronized strictfp @MyAnnotationFormatted public static void fooMethod5() {}
58  
59    // violation 2 lines above '.* annotation modifier does not precede non-annotation modifiers.'
60  
61    @MyAnnotationFormatted
62    private static final synchronized strictfp void fooMethod6() {}
63  
64    protected static final synchronized strictfp @MyAnnotationFormatted void fooMethod7() {}
65  
66    // violation 2 lines above '.* annotation modifier does not precede non-annotation modifiers.'
67  
68    @MyAnnotationFormatted
69    protected abstract void fooMet();
70  
71    abstract @MyAnnotationFormatted public void fooMet1();
72  
73    // violation 2 lines above '.* annotation modifier does not precede non-annotation modifiers.'
74  
75    /** holder for redundant 'public' modifier check. */
76    public static interface InputRedundantPublicModifier {
77      public void abc1();
78  
79      void abc2();
80  
81      abstract void abc3();
82  
83      public float PI_PUBLIC = (float) 3.14;
84  
85      final float PI_FINAL = (float) 3.14;
86  
87      /** all OK. */
88      float PI_OK = (float) 3.14;
89    }
90  
91    private final void method() {}
92  }
93  
94  // violation below 'Top-level class RedundantFinalClass2 has to reside in its own source file.'
95  final class RedundantFinalClass2 {
96    public final void finalMethod() {}
97  
98    public void method() {}
99  
100   protected @MyAnnotationFormatted static synchronized native void fooMethod();
101 
102   // violation 2 lines above '.* annotation modifier does not precede non-annotation modifiers.'
103 
104   protected static @MyAnnotationFormatted synchronized native void fooMethod1();
105 
106   // violation 2 lines above '.* annotation modifier does not precede non-annotation modifiers.'
107 
108   @MyAnnotationFormatted
109   protected synchronized native void fooMethod2();
110 
111   protected static synchronized native @MyAnnotationFormatted void fooMethod3();
112 
113   // violation 2 lines above '.* annotation modifier does not precede non-annotation modifiers.'
114 
115   native @MyAnnotationFormatted protected static synchronized void fooMethod4();
116 
117   // violation 2 lines above '.* annotation modifier does not precede non-annotation modifiers.'
118 
119   public static @MyAnnotationFormatted synchronized native void fooMethod5();
120 
121   // violation 2 lines above '.* annotation modifier does not precede non-annotation modifiers.'
122 
123   static synchronized native @MyAnnotationFormatted public void fooMethod6();
124 
125   // violation 2 lines above '.* annotation modifier does not precede non-annotation modifiers.'
126 
127   private static synchronized native @MyAnnotationFormatted void fooMethod7();
128   // violation above '.* annotation modifier does not precede non-annotation modifiers.'
129 }
130 
131 // violation 2 lines below 'Top-level class .* has to reside in its own source file.'
132 /** Holder for redundant modifiers of inner implementation. */
133 interface InnerImplementation2 {
134   InnerImplementation2 inner =
135       new InnerImplementation2() {
136         /** compiler requires 'public' modifier. */
137         public void method() {}
138       };
139 
140   void method();
141 }
142 
143 // violation below 'Top-level class WithInner2 has to reside in its own source file.'
144 class WithInner2 {
145   /**
146    * Inner class.
147    *
148    * @author max
149    */
150   class Inner {
151     private transient String dontSaveMe;
152 
153     public volatile int whatImReading;
154 
155     @MyAnnotationFormatted
156     protected synchronized native void fooMethod();
157 
158     protected @MyAnnotationFormatted synchronized native void fooMethod1();
159 
160     // violation 2 lines above '.* annotation modifier does not precede non-annotation modifiers.'
161 
162     protected synchronized @MyAnnotationFormatted native void fooMethod2();
163 
164     // violation 2 lines above '.* annotation modifier does not precede non-annotation modifiers.'
165 
166     protected synchronized native @MyAnnotationFormatted void fooMethod3();
167 
168     // violation 2 lines above '.* annotation modifier does not precede non-annotation modifiers.'
169 
170     native @MyAnnotationFormatted protected synchronized void fooMethod4();
171 
172     // violation 2 lines above '.* annotation modifier does not precede non-annotation modifiers.'
173 
174     public @MyAnnotationFormatted synchronized native void fooMethod5();
175 
176     // violation 2 lines above '.* annotation modifier does not precede non-annotation modifiers.'
177 
178     synchronized native @MyAnnotationFormatted public void fooMethod6();
179 
180     // violation 2 lines above '.* annotation modifier does not precede non-annotation modifiers.'
181 
182     private synchronized native @MyAnnotationFormatted void fooMethod7();
183 
184     // violation 2 lines above '.* annotation modifier does not precede non-annotation modifiers.'
185 
186     /** Anonymous class. */
187     InnerImplementation2 foo =
188         new InnerImplementation2() {
189 
190           public void method() {
191             // OOOO Auto-generated method stub
192 
193           }
194 
195           private transient String dontSaveMe;
196 
197           public volatile int whatImReading;
198 
199           protected @MyAnnotationFormatted synchronized native void fooMethod();
200 
201           // violation 2 lines above '.* annotation .* does not precede non-annotation modifiers.'
202 
203           protected @MyAnnotationFormatted synchronized native void fooMethod1();
204 
205           // violation 2 lines above '.* annotation .* does not precede non-annotation modifiers.'
206 
207           protected synchronized @MyAnnotationFormatted native void fooMethod2();
208 
209           // violation 2 lines above '.* annotation .* does not precede non-annotation modifiers.'
210 
211           protected synchronized native @MyAnnotationFormatted void fooMethod3();
212 
213           // violation 2 lines above '.* annotation .* does not precede non-annotation modifiers.'
214 
215           @MyAnnotationFormatted
216           protected synchronized native void fooMethod4();
217 
218           public @MyAnnotationFormatted synchronized native void fooMethod5();
219 
220           // violation 2 lines above '.* annotation .* does not precede non-annotation modifiers.'
221 
222           synchronized native @MyAnnotationFormatted public void fooMethod6();
223 
224           // violation 2 lines above '.* annotation .* does not precede non-annotation modifiers.'
225 
226           private synchronized native @MyAnnotationFormatted void fooMethod7();
227           // violation above '.* annotation modifier does not precede non-annotation modifiers.'
228         };
229   }
230 
231   /**
232    * Inner abstract class.
233    *
234    * @author max
235    */
236   abstract class AbsInner {
237     private transient String dontSaveMe;
238 
239     public volatile int whatImReading;
240 
241     @MyAnnotationFormatted
242     public final synchronized strictfp void fooMethod() {}
243 
244     protected final strictfp @MyAnnotationFormatted synchronized void fooMethod1() {}
245 
246     // violation 2 lines above '.* annotation modifier does not precede non-annotation modifiers.'
247 
248     synchronized @MyAnnotationFormatted private final strictfp void fooMethod2() {}
249 
250     // violation 2 lines above '.* annotation modifier does not precede non-annotation modifiers.'
251 
252     @MyAnnotationFormatted
253     protected final synchronized strictfp void fooMethod3() {}
254 
255     @MyAnnotationFormatted
256     private final synchronized strictfp void fooMethod4() {}
257 
258     final synchronized strictfp @MyAnnotationFormatted public void fooMethod5() {}
259 
260     // violation 2 lines above '.* annotation modifier does not precede non-annotation modifiers.'
261 
262     @MyAnnotationFormatted
263     private final synchronized strictfp void fooMethod6() {}
264 
265     protected final synchronized strictfp @MyAnnotationFormatted void fooMethod7() {}
266 
267     // violation 2 lines above '.* annotation modifier does not precede non-annotation modifiers.'
268 
269     @MyAnnotationFormatted
270     protected abstract void fooMet();
271 
272     abstract @MyAnnotationFormatted public void fooMet1();
273     // violation above '.* annotation modifier does not precede non-annotation modifiers.'
274   }
275 }
276 
277 // violation 2 lines below 'Top-level class Annotation2 has to reside in its own source file.'
278 /** Holder for redundant modifiers of annotation fields/variables. */
279 @interface Annotation2 {
280   public String s1 = "";
281   final String s2 = "";
282   static String s3 = "";
283   String s4 = "";
284 
285   public String blah();
286 
287   abstract String blah2();
288 }
289 
290 // violation below 'Top-level class MyAnnotationFormatted has to reside in its own source file.'
291 @interface MyAnnotationFormatted {}
292 
293 // violation below 'Top-level class MyAnnotationFormatted2 has to reside in its own source file.'
294 @interface MyAnnotationFormatted2 {}
295 
296 // violation 2 lines below 'Top-level class .* has to reside in its own source file.'
297 /** Illegal order of modifiers for interface methods. */
298 interface InputModifierOrderInterface2 {
299   default strictfp void abc1() {}
300 
301   default strictfp void abc2() {}
302 }