View Javadoc
1   package com.puppycrawl.tools.checkstyle.checks.indentation.indentation; //indent:0 exp:0
2   
3   
4   /**                                                                           //indent:0 exp:0
5    * This test-input is intended to be checked using following configuration:   //indent:1 exp:1
6    *                                                                            //indent:1 exp:1
7    * arrayInitIndent = 4                                                        //indent:1 exp:1
8    * basicOffset = 4                                                            //indent:1 exp:1
9    * braceAdjustment = 0                                                        //indent:1 exp:1
10   * caseIndent = 4                                                             //indent:1 exp:1
11   * forceStrictCondition = false                                               //indent:1 exp:1
12   * lineWrappingIndentation = 4                                                //indent:1 exp:1
13   * tabWidth = 4                                                               //indent:1 exp:1
14   * throwsIndent = 4                                                           //indent:1 exp:1
15   *                                                                            //indent:1 exp:1
16   *                                                                            //indent:1 exp:1
17   */                                                                           //indent:1 exp:1
18  public class InputIndentationInvalidIfIndent { //indent:0 exp:0
19  
20      // ctor with rcurly on same line //indent:4 exp:4
21      public InputIndentationInvalidIfIndent() { //indent:4 exp:4
22      } //indent:4 exp:4
23  
24      // ctor with rcurly on next line //indent:4 exp:4
25      public InputIndentationInvalidIfIndent(int dummy) //indent:4 exp:4
26      { //indent:4 exp:4
27      } //indent:4 exp:4
28  
29      // method with rcurly on same line //indent:4 exp:4
30      public void method() { //indent:4 exp:4
31      } //indent:4 exp:4
32  
33      // method with rcurly on next line //indent:4 exp:4
34      public void method2() //indent:4 exp:4
35      { //indent:4 exp:4
36      } //indent:4 exp:4
37  
38      // method with a bunch of params //indent:4 exp:4
39      public void method2(int x, int y, int w, int h) //indent:4 exp:4
40      { //indent:4 exp:4
41      } //indent:4 exp:4
42  
43      // params on multiple lines //indent:4 exp:4
44      public void method2(int x, int y, int w, int h, //indent:4 exp:4
45          int x1, int y1, int w1, int h1) //indent:8 exp:>=8
46      { //indent:4 exp:4
47      } //indent:4 exp:4
48  
49      // test ifs //indent:4 exp:4
50      public void emptyIfTest() //indent:4 exp:4
51      { //indent:4 exp:4
52          boolean test = true; //indent:8 exp:8
53  
54          // lcurly on same line //indent:8 exp:8
55   if (test) { //indent:1 exp:8 warn
56          } //indent:8 exp:8
57  
58          // lcurly on next line -- if, rcurly indented too far, lcurly not far enough //indent:8 exp:8
59          //  //indent:8 exp:8
60           if (test)  //indent:9 exp:8 warn
61           { //indent:9 exp:8 warn
62         } //indent:7 exp:8 warn
63  
64        if (test)  //indent:6 exp:8 warn
65       { //indent:5 exp:8 warn
66       } //indent:5 exp:8 warn
67  
68          // lcurly for if and else on same line -- too much space after if on same line -- ALLOWED //indent:8 exp:8
69          if (test)      { //indent:8 exp:8
70            } else {      // this is not allowed //indent:10 exp:8 warn
71         } //indent:7 exp:8 warn
72  
73          // lcurly for if and else on same line //indent:8 exp:8
74           if (test)  //indent:9 exp:8 warn
75         { //indent:7 exp:8 warn
76          }  //indent:8 exp:8
77           else  //indent:9 exp:8 warn
78          { //indent:8 exp:8
79           } //indent:9 exp:8 warn
80  
81          // lcurly for if and else on same line -- mixed braces //indent:8 exp:8
82            if (test) { //indent:10 exp:8 warn
83         }  //indent:7 exp:8 warn
84           else  //indent:9 exp:8 warn
85         { //indent:7 exp:8 warn
86           } //indent:9 exp:8 warn
87  
88  
89          // lcurly for if and else on same line -- mixed braces //indent:8 exp:8
90           if (test)  //indent:9 exp:8 warn
91           { //indent:9 exp:8 warn
92           } else  //indent:9 exp:8 warn
93         { //indent:7 exp:8 warn
94            } //indent:10 exp:8 warn
95  
96          // lcurly for if and else on same line -- mixed braces //indent:8 exp:8
97        if (test)  //indent:6 exp:8 warn
98            { //indent:10 exp:8 warn
99            } else { //indent:10 exp:8 warn
100        } //indent:7 exp:8 warn
101 
102         // lcurly for if and else on same line -- mixed braces, unnested //indent:8 exp:8
103      if (test) { //indent:5 exp:8 warn
104            }  //indent:11 exp:8 warn
105      else { //indent:5 exp:8 warn
106            } //indent:11 exp:8 warn
107     } //indent:4 exp:4
108 
109     /////  same as above, with statements //indent:4 exp:4
110     public void populatedIfTest() //indent:4 exp:4
111     { //indent:4 exp:4
112         boolean test = false; //indent:8 exp:8
113         // no braces if //indent:8 exp:8
114         if (test) //indent:8 exp:8
115               System.getProperty("blah"); //indent:14 exp:>=12
116 
117         // no braces if/else //indent:8 exp:8
118         if (test) //indent:8 exp:8
119             System.getProperty("blah"); //indent:12 exp:>=12
120         else //indent:8 exp:8
121             System.getProperty("blah"); //indent:12 exp:>=12
122 
123 
124         // lcurly on same line, and stmt //indent:8 exp:8
125         if (test) { //indent:8 exp:8
126               System.getProperty("blah"); //indent:14 exp:12 warn
127         } //indent:8 exp:8
128 
129         // lcurly on next line and stmt //indent:8 exp:8
130         if (test)  //indent:8 exp:8
131           { //indent:10 exp:8 warn
132           System.getProperty("blah"); //indent:10 exp:12 warn
133         } //indent:8 exp:8
134         // lcurly for if and else on same line //indent:8 exp:8
135         if (test) { //indent:8 exp:8
136 
137               System. //indent:14 exp:12 warn
138           getProperty("blah"); //indent:10 exp:12 warn
139         } else { //indent:8 exp:8
140           System. //indent:10 exp:12 warn
141         getProperty("blah"); //indent:8 exp:12 warn
142         } //indent:8 exp:8
143 
144         // lcurly for if and else on same line //indent:8 exp:8
145         if (test)  //indent:8 exp:8
146         { //indent:8 exp:8
147             System.getProperty("blah"); //indent:12 exp:12
148                 System.getProperty("blah"); //indent:16 exp:12 warn
149          }  //indent:9 exp:8 warn
150         else  //indent:8 exp:8
151         { //indent:8 exp:8
152                 System.getProperty("blah"); //indent:16 exp:12 warn
153             System.getProperty("blah"); //indent:12 exp:12
154         } //indent:8 exp:8
155 
156         // lcurly for if and else on same line -- mixed braces //indent:8 exp:8
157         if (test) { //indent:8 exp:8
158 System.getProperty("blah"); //indent:0 exp:12 warn
159         }  //indent:8 exp:8
160         else  //indent:8 exp:8
161         { //indent:8 exp:8
162                                         System.getProperty("blah"); //indent:40 exp:12 warn
163         } //indent:8 exp:8
164 
165 
166         // lcurly for if and else on same line -- mixed braces //indent:8 exp:8
167         if (test)  //indent:8 exp:8
168         { //indent:8 exp:8
169               System.getProperty("blah"); //indent:14 exp:12 warn
170         } else  //indent:8 exp:8
171         { //indent:8 exp:8
172               System.getProperty("blah"); //indent:14 exp:12 warn
173         } //indent:8 exp:8
174 
175         // lcurly for if and else on same line -- mixed braces //indent:8 exp:8
176         if (test)  //indent:8 exp:8
177         { //indent:8 exp:8
178           System.getProperty("blah"); //indent:10 exp:12 warn
179         } else { //indent:8 exp:8
180           System.getProperty("blah"); //indent:10 exp:12 warn
181         } //indent:8 exp:8
182 
183         // lcurly for if and else on same line -- mixed braces, unnested //indent:8 exp:8
184           if (test) { //indent:10 exp:8 warn
185               System.getProperty("blah"); //indent:14 exp:12 warn
186           }  //indent:10 exp:8 warn
187           else { //indent:10 exp:8 warn
188               System.getProperty("blah"); //indent:14 exp:12 warn
189           } //indent:10 exp:8 warn
190 
191         if (test //indent:8 exp:8
192          && 7 < 8 && 8 < 9 //indent:9 exp:12 warn
193            && 10 < 11) { //indent:11 exp:12 warn
194         } //indent:8 exp:8
195 
196         if (test) //indent:8 exp:8
197           return; //indent:10 exp:12 warn
198 
199         if (test) { //indent:8 exp:8
200        } else if (7 < 8) { //indent:7 exp:8 warn
201         } else if (8 < 9) { //indent:8 exp:8
202         } //indent:8 exp:8
203 
204         if (test) { //indent:8 exp:8
205             System.getProperty("blah");  //indent:12 exp:>=12
206         } else if (7 < 8) { //indent:8 exp:8
207           System.getProperty("blah");  //indent:10 exp:>=12 warn
208         } else if (8 < 9) { //indent:8 exp:8
209           System.getProperty("blah");  //indent:10 exp:>=12 warn
210         } //indent:8 exp:8
211 
212 
213         if (test) //indent:8 exp:8
214             System.getProperty("blah");  //indent:12 exp:12
215         else if (7 < 8) //indent:8 exp:8
216           System.getProperty("blah");  //indent:10 exp:10
217         else if (8 < 9) //indent:8 exp:8
218             System.getProperty("blah");  //indent:12 exp:12
219 
220 
221         //                               //indent:8 exp:8
222         if (test) { //indent:8 exp:8
223             System.getProperty("blah");  //indent:12 exp:12
224         } else  //indent:8 exp:8
225           if (7 < 8) { //indent:10 exp:12 warn
226                 System.getProperty("blah");  //indent:16 exp:16
227             } else  //indent:12 exp:12
228                 if (8 < 9) { //indent:16 exp:16
229                   System.getProperty("blah");  //indent:18 exp:20 warn
230                 } //indent:16 exp:16
231 
232         if (test) { //indent:8 exp:8
233             System.getProperty("blah"); } //indent:12 exp:12
234     } //indent:4 exp:4
235 
236     public void parenIfTest() { //indent:4 exp:4
237         boolean test = true; //indent:8 exp:8
238 
239         if (test //indent:8 exp:8
240           ) { //indent:10 exp:8 warn
241             System.getProperty("blah");  //indent:12 exp:12
242         } //indent:8 exp:8
243 
244         if (test //indent:8 exp:8
245       )  //indent:6 exp:8 warn
246         { //indent:8 exp:8
247             System.getProperty("blah");  //indent:12 exp:12
248         } //indent:8 exp:8
249 
250         if  //indent:8 exp:8
251       ( //indent:6 exp:8 warn
252             test //indent:12 exp:12
253       ) { //indent:6 exp:8 warn
254             System.getProperty("blah");  //indent:12 exp:12
255         } //indent:8 exp:8
256 if (test  //indent:0 exp:8 warn
257 || test) {  //indent:0 exp:12 warn
258 System.getProperty("blah");  //indent:0 exp:12 warn
259 }  //indent:0 exp:8 warn
260 
261     } //indent:4 exp:4
262 
263 } //indent:0 exp:0