1 package com.google.checkstyle.test.chapter4formatting.rule451wheretobreak;
2
3 import java.util.Arrays;
4 import java.util.HashMap;
5 import java.util.Map;
6
7 class InputOperatorWrap {
8 void test() {
9 int x = 1 + // violation ''\+' should be on a new line.'
10 2 - // violation ''-' should be on a new line.'
11 3
12 -
13 4;
14 x = x + 2;
15 boolean y = true
16 &&
17 false;
18 y = true && // violation ''&&' should be on a new line.'
19 false;
20 y = false
21 && true;
22 /* Note: The three tests below will be used when issue #3381 is closed */
23 Arrays.sort(null, String
24 // violation below ''::' should be on a new line.'
25 ::
26 compareToIgnoreCase);
27 Arrays.sort(null, String:: // violation ''::' should be on a new line.'
28 compareToIgnoreCase);
29 Arrays.sort(null, String
30 ::compareToIgnoreCase);
31 }
32
33 void testAssignment() {
34 int x
35 = 0;
36 int y =
37 0;
38 }
39
40 <T extends Comparable & // violation ''&' should be on a new line.'
41 java.io.Serializable>
42 void testGenerics1() {
43 Comparable
44 <
45 String
46 >
47 c = new String();
48 Map<String, String> map = new HashMap<String, String>();
49
50 boolean flag = false;
51
52 int init = 9;
53
54 for (Map.Entry<String, String> entry :
55 map.entrySet()) {
56 int i = flag == true ? // violation ''?' should be on a new line.'
57 1 : 2;
58 }
59
60 if (init != // violation ''!=' should be on a new line.'
61 9) { /* ignore */ }
62
63 while (init == // violation ''==' should be on a new line.'
64 10) { } // violation 'Empty blocks should have no spaces. .* only be represented as {}'
65
66 if (init > // violation ''>' should be on a new line.'
67 10) { /* ignore */ }
68
69 while (init < 10 || // violation ''\|\|' should be on a new line.'
70 !flag) { } // violation 'Empty blocks should have no spaces. .* only be represented as {}'
71 }
72
73 class Inner {
74 void testGenerics1() {
75 Comparable
76 <
77 String
78 >
79 c = new String();
80 Map<String, String> map = new HashMap<String, String>();
81 boolean flag = false;
82
83 int init = 9;
84
85 for (Map.Entry<String, String> entry :
86 map.entrySet()) {
87 int i = flag == true ? // violation ''?' should be on a new line.'
88 1 : 2;
89 }
90
91 if (init != // violation ''!=' should be on a new line.'
92 9) { /* ignore */ }
93
94 while (init == // violation ''==' should be on a new line.'
95 10) { } // violation 'Empty blocks should have no spaces. .* only be represented as {}'
96
97 if (init > // violation ''>' should be on a new line.'
98 10) { /* ignore */ }
99
100 while (init < 10 || // violation ''\|\|' should be on a new line.'
101 !flag) {}
102 }
103 }
104
105 Inner anon =
106 new Inner() {
107 void testGenerics1() {
108 Comparable
109 <
110 String
111 >
112 c = new String();
113 Map<String, String> map = new HashMap<String, String>();
114 boolean flag = false;
115 int init = 9;
116
117 for (Map.Entry<String, String> entry :
118 map.entrySet()) {
119 int i = flag == true ? // violation ''?' should be on a new line.'
120 1 : 2;
121 }
122
123 if (init != // violation ''!=' should be on a new line.'
124 9) { /* ignore */ }
125
126 while (init == // violation ''==' should be on a new line.'
127 10) { } // violation 'Empty blocks should have no spaces.* only be represented as {}'
128
129 if (init > // violation ''>' should be on a new line.'
130 10) { /* ignore */ }
131
132 while (init < 10 || // violation ''\|\|' should be on a new line.'
133 !flag) {}
134 }
135 };
136
137 class AsInput {
138 int abc = 0;
139 String string
140 = "string";
141 double pi =
142 3.1415;
143 }
144
145 class Ternary {
146 void foo() {
147 boolean flag = true;
148 int i = flag == true ? // violation ''?' should be on a new line.'
149 1 :
150 2;
151 int i2 = flag == true
152 ?
153 1
154 :
155 2;
156 int i3 = flag == true
157 ? 1
158 : 2;
159 }
160 }
161
162 class AssignClass {
163 void foo() {
164 int i = 0;
165 int j = 0;
166 i +=
167 1;
168 j
169 += 2;
170 i -=
171 1;
172 j
173 -= 2;
174 i /=
175 1;
176 j
177 /= 2;
178 i *=
179 1;
180 j
181 *= 2;
182 i %=
183 1;
184 j
185 %= 2;
186 i ^=
187 1;
188 j
189 ^= 2;
190 i |=
191 1;
192 j
193 |= 2;
194 i &=
195 1;
196 j
197 &= 2;
198 i >>=
199 1;
200 j
201 >>= 2;
202 i >>>=
203 1;
204 j
205 >>>= 2;
206 i <<=
207 1;
208 j
209 <<= 2;
210 }
211
212 class InnerClass {
213 void foo() {
214 int i = 0;
215 int j = 0;
216 i +=
217 1;
218 j
219 += 2;
220 i -=
221 1;
222 j
223 -= 2;
224 i /=
225 1;
226 j
227 /= 2;
228 i *=
229 1;
230 j
231 *= 2;
232 i %=
233 1;
234 j
235 %= 2;
236 i ^=
237 1;
238 j
239 ^= 2;
240 i |=
241 1;
242 j
243 |= 2;
244 i &=
245 1;
246 j
247 &= 2;
248 i >>=
249 1;
250 j
251 >>= 2;
252 i >>>=
253 1;
254 j
255 >>>= 2;
256 i <<=
257 1;
258 j
259 <<= 2;
260 }
261 }
262
263 InnerClass anon =
264 new InnerClass() {
265 void foo() {
266 int i = 0;
267 int j = 0;
268 i +=
269 1;
270 j
271 += 2;
272 i -=
273 1;
274 j
275 -= 2;
276 i /=
277 1;
278 j
279 /= 2;
280 i *=
281 1;
282 j
283 *= 2;
284 i %=
285 1;
286 j
287 %= 2;
288 i ^=
289 1;
290 j
291 ^= 2;
292 i |=
293 1;
294 j
295 |= 2;
296 i &=
297 1;
298 j
299 &= 2;
300 i >>=
301 1;
302 j
303 >>= 2;
304 i >>>=
305 1;
306 j
307 >>>= 2;
308 i <<=
309 1;
310 j
311 <<= 2;
312 }
313 };
314
315 <T extends Comparable
316 & java.io.Serializable>
317 void testWrapBeforeOperator() {}
318 }
319 }