blob: a116339147f15065aab14c8c2878526ef4c4c29a (
plain)
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
|
package com.puppycrawl.tools.checkstyle.checks.blocks.needbraces;
public class InputNeedBracesSingleLineStatements
{
private static class SomeClass {
boolean flag = true;
private static boolean test(boolean k) {
return k;
}
}
private int foo() {
if (SomeClass.test(true) == true) return 4; //No warning if 'mAllowSingleLineIf' is true
return 0;
}
private int foo1() {
if (SomeClass.test(true) == true) return 4; int k = 3; //No warning if 'mAllowSingleLineIf' is true
return 0;
}
private int foo2() {
if (SomeClass.test(true) == true) //Warning, not single-line if-statement
return 4;
return 0;
}
private int foo3() {
if (SomeClass.test(true) == true) if (true) return 4; //Warning, complex block
return 0;
}
private void foo(Object o) {
if (o != null) this.notify();
}
private void foo2(Object o) {
if (o != null)
this.notify();
}
private void loopTest(Object o) {
while (o != null) {
this.notify();
}
while (o != null)
this.notify();
while (o != null) this.notify();
do {
this.notify();
} while (o != null);
do this.notify(); while (o != null);
do
this.notify();
while (o != null);
for (;;)
break;
for (;;) break;
for (int i = 0; i < 10; i++) {
this.notify();
}
for (int i = 0; i < 10; i++)
this.notify();
for (int i = 0; ; ) this.notify();
}
private int getSmth(int num)
{
int counter = 0;
switch (num) {
case 1: counter++; break;
case 2:
counter += 2;
break;
case 3:
counter += 3;
break;
case 6: counter += 10; break;
default: counter = 100; break;
}
return counter;
}
private void testElse(int k) {
if (k == 4) System.identityHashCode("yes");
else System.identityHashCode("no");
for (;;);
}
private int testMissingWarnings() {
if (true)
throw new RuntimeException();
if (true) {
return 1;
} else
return 2;
}
void enhancedForLoop(int[] array) {
for (int value: array) return;
}
int[] sourceLocators;
private class StateInfo {
public boolean isInitial() {
for (int locator: sourceLocators) if (locator != 0) return false;
return true;
}
}
private void forEachLoop() {
for (String s: new String[]{""}) break;
for (String s: new String[]{""})
break;
}
}
|