forked from checkstyle/checkstyle
-
Notifications
You must be signed in to change notification settings - Fork 1
/
InputNoWhitespaceAfterTestDefault.java
337 lines (287 loc) · 7.16 KB
/
InputNoWhitespaceAfterTestDefault.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/*
NoWhitespaceAfter
allowLineBreaks = false
tokens = (default)ARRAY_INIT, AT, INC, DEC, UNARY_MINUS, UNARY_PLUS, BNOT, LNOT, \
DOT, ARRAY_DECLARATOR, INDEX_OP
*/
package com . puppycrawl // violation
.tools. // violation
checkstyle.checks.whitespace.nowhitespaceafter; // ^ 2 violations above
class InputNoWhitespaceAfterTestDefault
{
/** ignore assignment **/
private int mVar1=1;
/** ignore assignment **/
private int mVar2 =1;
/** Should be ok **/
private int mVar3 = 1;
/** method **/
void method1()
{
final int a = 1;
int b= 1; // Ignore 1
b=1; // Ignore 1
b+=1; // Ignore 1
b -=- 1 + (+ b); // 2 violations
b = b ++ + b --; // Ignore 1
b = ++ b - -- b; // 2 violations
}
/** method **/
void method2()
{
synchronized(this) {
}
try{
}
catch(RuntimeException e){
}
}
/**
skip blank lines between comment and code,
should be ok
**/
private int mVar4 = 1;
/** test WS after void return */
private void fastExit()
{
boolean complicatedStuffNeeded = true;
if( !complicatedStuffNeeded )
{
return; // should not complain about missing WS after return
}
else
{
// do complicated stuff
}
}
/** test WS after non void return
@return 2
*/
private int nonVoid()
{
if ( true )
{
return(2); // should complain about missing WS after return
}
else
{
return 2; // this is ok
}
}
/** test casts **/
private void testCasts()
{
Object o = (Object) new Object(); // ok
o = (Object)o;
o = ( Object ) o; // ok
o = (Object) // ok
o; // ok
}
/** test questions **/
private void testQuestions()
{
boolean b = (1 == 2)?true:false;
b = (1==2) ? false : true;
}
/** star test **/
private void starTest()
{
int x = 2 *3* 4;
}
/** boolean test **/
private void boolTest()
{
boolean a = true;
boolean x = ! a; // violation
int z = ~1 + ~ 2; // violation
}
/** division test **/
private void divTest()
{
int a = 4 % 2;
int b = 4% 2;
int c = 4 %2;
int d = 4%2;
int e = 4 / 2;
int f = 4/ 2;
int g = 4 /2;
int h = 4/2;
}
/** @return dot test **/
private java .lang. String dotTest() // violation
{
Object o = new Object();
o. // violation
toString();
o
.toString();
o . toString(); // violation
return o.toString();
}
/** assert statement test */
public void assertTest()
{
// OK
assert true;
// OK
assert true : "Whups";
// evil colons, should be OK
assert "OK".equals(null) ? false : true : "Whups";
// missing WS around assert
assert(true);
// missing WS around colon
assert true:"Whups";
}
/** another check */
void donBradman(Runnable aRun)
{
donBradman(new Runnable() {
public void run() {
}
});
final Runnable r = new Runnable() {
public void run() {
}
};
}
/** rfe 521323, detect whitespace before ';' */
void rfe521323()
{
doStuff() ;
// ^ whitespace
for (int i = 0 ; i < 5; i++) {
// ^ whitespace
}
}
/** bug 806243 (NoWhitespaceBeforeCheck violation for anonymous inner class) */
private int i ;
// ^ whitespace
private int i1, i2, i3 ;
// ^ whitespace
private int i4, i5, i6;
/** bug 806243 (NoWhitespaceBeforeCheck violation for anonymous inner class) */
void bug806243()
{
Object o = new InputNoWhitespaceAfterTestDefault() {
private int j ;
// ^ whitespace
};
}
void doStuff() {
}
}
/**
* Bug 806242 (NoWhitespaceBeforeCheck violation with an interface).
* @author o_sukhodolsky
* @version 1.0
*/
interface IFoo
{
void foo() ;
// ^ whitespace
}
/**
* Avoid Whitespace violations in for loop.
* @author lkuehne
* @version 1.0
*/
class SpecialCasesInForLoop
{
void forIterator()
{
// avoid conflict between WhiteSpaceAfter ';' and ParenPad(nospace)
for (int i = 0; i++ < 5;) {
// ^ no whitespace
}
// bug 895072
// avoid conflict between ParenPad(space) and NoWhiteSpace before ';'
int i = 0;
for ( ; i < 5; i++ ) {
// ^ whitespace
}
for (int anInt : getSomeInts()) {
//Should be ignored
}
}
int[] getSomeInts() {
int i = (int) ( 2 / 3 ); // ok
return null;
}
public void myMethod() {
new Thread() {
public void run() {
}
}.start();
}
public void foo(java.util.List<? extends String[]> bar, Comparable<? super Object[]> baz) { }
public void mySuperMethod() {
Runnable[] runs = new Runnable[] {new Runnable() {
public void run() {
}
},
new Runnable() {
public void run() {
}
}};
runs[0]
. // violation
run()
;
}
public void testNullSemi() {
return ;
}
public void register(Object obj) { }
public void doSomething(String args[]) {
register(boolean[].class);
register( args );
}
public void parentheses() {
testNullSemi
(
)
;
}
public static void testNoWhitespaceBeforeEllipses(String ... args) {
}
@ interface BAD{} // violation
@ interface BAD2{} // violation
@ // violation
interface BAD3{}
@interface Ok{}
static {
int[]err = new int [50]; // violation
}
Object foo() {
return ( (Object
) ""); // ^ ok
}
public Object[]
variable;
int someStuff8
[]; // violation
}
class QualifiedAssignment {
Object o;
static Object o1;
static QualifiedAssignment q1;
static int idx = 1;
static boolean b = true;
void some() {
Object oo = new Object[4];
Object[] oo2 = new Object[4];
this.o = ((Object[]) oo)[1];
this.o = ((java.lang.Object[]) oo)[1];
this.o = oo2[1];
QualifiedAssignment.o1 = ((Object[]) oo)[1];
QualifiedAssignment.o1 = ((java.lang.Object[]) oo)[1];
QualifiedAssignment.o1 = oo2[1];
QualifiedAssignment qa1 = null;
QualifiedAssignment[] qa2 = null;
(qa1 = (QualifiedAssignment)qa2[idx]).o1 = (new QualifiedAssignment[idx][idx][idx])[idx];
(b ? (new QualifiedAssignment().q1 = new QualifiedAssignment()) :
(QualifiedAssignment)(new QualifiedAssignment().q1 = new QualifiedAssignment())).q1 =
(new QualifiedAssignment[new QualifiedAssignment().idx = (QualifiedAssignment.idx =
QualifiedAssignment.idx)])[QualifiedAssignment.idx];
}
}