1
2
3
4
5
6
7
8
9
10 package com.puppycrawl.tools.checkstyle.checks.blocks.needbraces;
11
12 public class InputNeedBracesSingleLineStatements
13 {
14 private static class SomeClass {
15 boolean flag = true;
16 private static boolean test(boolean k) {
17 return k;
18 }
19 }
20
21 private int foo() {
22 if (SomeClass.test(true) == true) return 4;
23 return 0;
24 }
25
26 private int foo1() {
27 if (SomeClass.test(true)) return 4; int k = 3;
28 return 0;
29 }
30
31 private int foo2() {
32 if (SomeClass.test(true) == true)
33 return 4;
34 return 0;
35 }
36
37 private int foo3() {
38
39 if (SomeClass.test(true) == true) if (true) return 4;
40 return 0;
41 }
42
43 private void foo(Object o) {
44 if (o != null) this.notify();
45 }
46
47 private void foo2(Object o) {
48 if (o != null)
49 this.notify();
50 }
51
52 private void loopTest(Object o) {
53 while (o != null) {
54 this.notify();
55 }
56 while (o != null)
57 this.notify();
58 while (o != null) this.notify();
59 do {
60 this.notify();
61 } while (o != null);
62 do this.notify(); while (o != null);
63 do
64 this.notify();
65 while (o != null);
66 for (;;)
67 break;
68 for (;;) break;
69 for (int i = 0; i < 10; i++) {
70 this.notify();
71 }
72 for (int i = 0; i < 10; i++)
73 this.notify();
74 for (int i = 0; ; ) this.notify();
75 }
76
77 private int getSmth(int num)
78 {
79 int counter = 0;
80 switch (num) {
81 case 1: counter++; break;
82 case 2:
83 counter += 2;
84 break;
85 case 3:
86 counter += 3;
87 break;
88 case 6: counter += 10; break;
89 default: counter = 100; break;
90 }
91 return counter;
92 }
93
94 private void testElse(int k) {
95 if (k == 4) System.identityHashCode("yes");
96 else System.identityHashCode("no");
97 for (;;);
98 }
99
100 private int testMissingWarnings() {
101 if (true)
102 throw new RuntimeException();
103 if (true) {
104 return 1;
105 } else
106 return 2;
107 }
108
109 void enhancedForLoop(int[] array) {
110 for (int value: array) return;
111 }
112
113 int[] sourceLocators;
114
115 private class StateInfo {
116 public boolean isInitial() {
117
118 for (int locator: sourceLocators) if (locator != 0) return false;
119 return true;
120 }
121 }
122
123 private void forEachLoop() {
124 for (String s: new String[]{""}) break;
125 for (String s: new String[]{""})
126 break;
127 for (;;)
128 ;
129 }
130 private void method(){
131 if(false) {
132 switch (0) {
133 case -1:
134 return;
135 default:
136 return;
137 }
138 }
139 switch(1){
140 case 1: return;
141 default: throw new RuntimeException("");
142 }
143 }
144 }