1 package com.google.checkstyle.test.chapter4formatting.rule411optionalbracesusage;
2
3 class InputUseOfOptionalBraces {
4
5
6
7
8
9 boolean condition() {
10 return false;
11 }
12
13
14 void testDoWhile() {
15
16 do {
17 testDoWhile();
18 } while (condition());
19
20
21
22 do testDoWhile();
23 while (condition());
24 }
25
26
27 void testWhile() {
28
29 while (condition()) {
30 testWhile();
31 }
32
33
34
35
36 while (condition())
37 ;
38 while (condition()) testWhile();
39
40
41 while (condition()) if (condition()) testWhile();
42 String k = "testing";
43
44 if (k != null) k = "ss";
45 }
46
47
48 void testFor() {
49
50 for (int i = 1; i < 5; i++) {
51 testFor();
52 }
53
54
55
56 for (int i = 1; i < 5; i++)
57 ;
58
59 for (int i = 1; i < 5; i++) testFor();
60
61
62 for (int i = 1; i < 5; i++) if (i > 2) testFor();
63 }
64
65
66 public void testIf() {
67
68 if (condition()) {
69 testIf();
70 } else if (condition()) {
71 testIf();
72 } else {
73 testIf();
74 }
75
76
77
78 if (condition())
79 ;
80
81 if (condition()) testIf();
82
83
84 if (condition()) testIf();
85 else testIf();
86
87 if (condition()) testIf();
88 else {
89 testIf();
90 }
91 if (condition()) {
92 testIf();
93
94 } else testIf();
95
96
97 if (condition()) if (condition()) testIf();
98 }
99
100 void whitespaceAfterSemi() {
101
102 int i = 1;
103 int j = 2;
104
105
106 for (; ; ) {}
107 }
108
109
110 public InputUseOfOptionalBraces() {}
111
112
113 public void emptyImplementation() {}
114
115
116 static Runnable r2 = () -> String.CASE_INSENSITIVE_ORDER.equals("Hello world one!");
117
118 static Runnable r3 = () -> String.CASE_INSENSITIVE_ORDER.equals("Hello world one!");
119 static Runnable r4 =
120 () -> {
121 String.CASE_INSENSITIVE_ORDER.equals("Hello world one!");
122 };
123 static Runnable r5 = () -> {};
124
125 class EmptyBlocks {
126 boolean flag = true;
127 int[] abc = {
128 1, 2, 3, 4,
129 };
130
131 void foo() {
132
133 while (flag)
134 ;
135 while (flag) {}
136 while (flag) {
137
138 }
139
140 do
141 ;
142 while (flag);
143 do {} while (flag);
144 do {
145
146 } while (flag);
147
148 if (flag)
149 ;
150 if (flag) {
151
152 }
153 if (flag) {
154
155 }
156
157
158 if (flag)
159 ;
160 else
161 ;
162 if (flag) {
163 } else {
164 }
165 if (flag) {
166
167 } else {
168
169 }
170
171 for (int i = 0; i < 10; i++)
172 ;
173 for (int i = 0; i < 10; i++) {}
174 for (int i = 0; i < 10; i++) {
175
176 }
177
178 for (int b : abc)
179 ;
180 for (int b : abc) {}
181 for (int b : abc) {
182
183 }
184 }
185
186 class InnerEmptyBlocks {
187 boolean flag = true;
188 int[] abc = {
189 1, 2, 3, 4,
190 };
191
192 void foo() {
193
194 while (flag)
195 ;
196 while (flag) {}
197 while (flag) {
198
199 }
200
201 do
202 ;
203 while (flag);
204 do {} while (flag);
205 do {
206
207 } while (flag);
208
209 if (flag)
210 ;
211 if (flag) {
212
213 }
214 if (flag) {
215
216 }
217
218
219 if (flag)
220 ;
221 else
222 ;
223 if (flag) {
224 } else {
225 }
226 if (flag) {
227
228 } else {
229
230 }
231
232 for (int i = 0; i < 10; i++)
233 ;
234 for (int i = 0; i < 10; i++) {}
235 for (int i = 0; i < 10; i++) {
236
237 }
238
239 for (int b : abc)
240 ;
241 for (int b : abc) {}
242 for (int b : abc) {
243
244 }
245 }
246 }
247
248 InnerEmptyBlocks anon =
249 new InnerEmptyBlocks() {
250 boolean flag = true;
251 int[] abc = {
252 1, 2, 3, 4,
253 };
254
255 void foo() {
256
257 while (flag)
258 ;
259 while (flag) {}
260 while (flag) {
261
262 }
263
264 do
265 ;
266 while (flag);
267 do {} while (flag);
268 do {
269
270 } while (flag);
271
272 if (flag)
273 ;
274 if (flag) {
275
276 }
277 if (flag) {
278
279 }
280
281
282 if (flag)
283 ;
284 else
285 ;
286 if (flag) {
287 } else {
288 }
289 if (flag) {
290
291 } else {
292
293 }
294
295 for (int i = 0; i < 10; i++)
296 ;
297 for (int i = 0; i < 10; i++) {}
298 for (int i = 0; i < 10; i++) {
299
300 }
301
302 for (int b : abc)
303 ;
304 for (int b : abc) {}
305 for (int b : abc) {
306
307 }
308 }
309 };
310 }
311 }