View Javadoc
1   package com.google.checkstyle.test.chapter4formatting.rule487modifiers;
2   
3   strictfp abstract class InputModifierOrder //warn
4   {
5   	transient private String dontSaveMe; //warn
6   	
7   	volatile public int whatImReading; //warn
8   	
9       public volatile boolean sModifierOrderVar = false; // ok
10  
11      /**
12       * Illegal order of modifiers for methods. Make sure that the
13       * first and last modifier from the JLS sequence is used.
14       */
15      strictfp private void doStuff() //warn
16      {
17      }
18  
19      /** Single annotation without other modifiers */
20      @MyAnnotation2 void someMethod()
21      {
22      }
23  
24      /** Illegal order of annotation - must come first */
25      private @MyAnnotation2 void someMethod2() //warn
26      {
27      }
28  
29      /** Annotation in middle of other modifiers otherwise in correct order */
30      private @MyAnnotation2 strictfp void someMethod3() //warn
31      {
32      }
33  
34      /** Correct order */
35      @MyAnnotation2 private strictfp void someMethod4()
36      {
37      }
38  
39      /** Annotation in middle of other modifiers otherwise in correct order */
40      @MyAnnotation2 public static @MyAnnotation4 strictfp void someMethod5() //warn
41      {
42      }
43      
44      @MyAnnotation2 public static final synchronized strictfp void fooMethod() {}; //ok
45      
46      strictfp protected final @MyAnnotation2 static synchronized void fooMethod1() {}; //warn
47      
48      synchronized @MyAnnotation2 strictfp private final static void fooMethod2() {}; //warn
49      
50      @MyAnnotation2 static synchronized final strictfp protected void fooMethod3() {}; //warn
51      
52      @MyAnnotation2 strictfp static final synchronized private void fooMethod4() {}; //warn
53      
54      synchronized final strictfp @MyAnnotation2 static public void fooMethod5() {}; //warn
55      
56      @MyAnnotation2 static synchronized strictfp private final void fooMethod6() {}; //warn
57      
58      final strictfp synchronized static protected @MyAnnotation2 void fooMethod7() {}; //warn
59      
60      @MyAnnotation2 abstract protected void fooMet(); //warn
61      
62      abstract @MyAnnotation2 public void fooMet1(); //warn
63  
64      /** holder for redundant 'public' modifier check. */
65      public static interface InputRedundantPublicModifier
66      {
67          public void a();
68  
69          void b();
70  
71          abstract void c();
72  
73          public float PI_PUBLIC = (float) 3.14;
74  
75          final float PI_FINAL = (float) 3.14;
76  
77          /** all OK */
78          float PI_OK = (float) 3.14;
79      }
80      final private void method() // warn
81      {
82      }
83  }
84  
85  final class RedundantFinalClass
86  {
87      public final void finalMethod()
88      {
89      }
90  
91  
92      public void method()
93      {
94      }
95      
96      protected @MyAnnotation2 static synchronized native void fooMethod(); // warn
97      
98      static protected @MyAnnotation2 synchronized native void fooMethod1(); // warn
99      
100     @MyAnnotation2 protected synchronized native void fooMethod2(); // ok
101     
102     native synchronized protected static @MyAnnotation2 void fooMethod3(); // warn
103     
104     native @MyAnnotation2 protected static synchronized void fooMethod4(); // warn
105     
106     public static @MyAnnotation2 synchronized native void fooMethod5(); // warn
107     
108     synchronized static native @MyAnnotation2 public void fooMethod6(); // warn
109     
110     static synchronized private native @MyAnnotation2 void fooMethod7(); // warn
111 }
112 
113 /** Holder for redundant modifiers of inner implementation */
114 interface InnerImplementation
115 {
116     InnerImplementation inner =
117         new InnerImplementation()
118         {
119             /** compiler requires 'public' modifier */
120             public void method()
121             {
122             }
123         };
124     
125     void method();
126 }
127 
128 class WithInner
129 {
130 	/**
131 	 * Inner class
132 	 * @author max
133 	 *
134 	 */
135 	class Inner 
136 	{
137 		transient private String dontSaveMe; //warn
138 		
139 		volatile public int whatImReading; //warn
140 		
141 		@MyAnnotation2 protected synchronized native void fooMethod(); // ok
142 		
143 	    protected @MyAnnotation2 synchronized native void fooMethod1(); // warn
144 	    
145 	    synchronized protected @MyAnnotation2 native void fooMethod2(); // warn
146 	    
147 	    native synchronized protected @MyAnnotation2 void fooMethod3(); // warn
148 	    
149 	    native @MyAnnotation2 protected synchronized void fooMethod4(); // warn
150 	    
151 	    public @MyAnnotation2 synchronized native void fooMethod5(); // warn
152 	    
153 	    synchronized native @MyAnnotation2 public void fooMethod6(); // warn
154 	    
155 	    synchronized private native @MyAnnotation2 void fooMethod7(); // warn
156 	    
157 	    /**
158 	     * Anonymous class
159 	     */
160 	    InnerImplementation foo = new InnerImplementation() {
161 
162 			
163 			public void method() {
164 				// TODO Auto-generated method stub
165 				
166 			}
167 			
168 			transient private String dontSaveMe; //warn
169 			
170 			volatile public int whatImReading; //warn
171 			
172 			protected @MyAnnotation2 synchronized native void fooMethod(); // warn
173 			
174 		    protected @MyAnnotation2 synchronized native void fooMethod1(); // warn
175 		    
176 		    synchronized protected @MyAnnotation2 native void fooMethod2(); // warn
177 		    
178 		    native synchronized protected @MyAnnotation2 void fooMethod3(); // warn
179 		    
180 		    @MyAnnotation2 protected synchronized native void fooMethod4(); // ok
181 		    
182 		    public @MyAnnotation2 synchronized native void fooMethod5(); // warn
183 		    
184 		    synchronized native @MyAnnotation2 public void fooMethod6(); // warn
185 		    
186 		    synchronized private native @MyAnnotation2 void fooMethod7(); // warn
187 		};
188 	}
189 
190 	/**
191 	 * Inner abstract class
192 	 * @author max
193 	 *
194 	 */
195 	abstract class AbsInner
196 	{
197 		transient private String dontSaveMe; //warn
198 		
199 		volatile public int whatImReading; //warn
200 		
201 		@MyAnnotation2 public final synchronized strictfp void fooMethod() {}; //ok
202 	    
203 	    strictfp protected final @MyAnnotation2 synchronized void fooMethod1() {}; //warn
204 	    
205 	    synchronized @MyAnnotation2 strictfp private final void fooMethod2() {}; //warn
206 	    
207 	    @MyAnnotation2 synchronized final strictfp protected void fooMethod3() {}; //warn
208 	    
209 	    @MyAnnotation2 strictfp final synchronized private void fooMethod4() {}; //warn
210 	    
211 	    synchronized final strictfp @MyAnnotation2 public void fooMethod5() {}; //warn
212 	    
213 	    @MyAnnotation2 synchronized strictfp private final void fooMethod6() {}; //warn
214 	    
215 	    final strictfp synchronized protected @MyAnnotation2 void fooMethod7() {}; //warn
216 	    
217 	    @MyAnnotation2 abstract protected void fooMet(); //warn
218 	    
219 	    abstract @MyAnnotation2 public void fooMet1(); //warn
220 	}
221 }
222 
223 /** Holder for redundant modifiers of annotation fields/variables */
224 @interface Annotation
225 {
226     public String s1 = "";
227     final String s2 = "";
228     static String s3 = "";
229     String s4 = "";
230     public String blah();
231     abstract String blah2();
232 }
233 
234 @interface MyAnnotation2 {
235 }
236 
237 @interface MyAnnotation4 {
238 }
239 
240 /** Illegal order of modifiers for interface methods */
241 interface InputModifierOrderInterface
242 {
243     default strictfp void a() { }  //ok
244 
245     strictfp default void b() { }  //warn
246 }