PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/resources/com/puppycrawl/tools/checkstyle/coding/InputFallThrough.java

https://github.com/marschall/checkstyle
Java | 409 lines | 360 code | 18 blank | 31 comment | 34 complexity | ffb3ab672ea2faf0ce894cd345c537bb MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1
  1. package com.puppycrawl.tools.checkstyle.coding;
  2. public class InputFallThrough
  3. {
  4. void method(int i, int j, boolean cond) {
  5. while (true) {
  6. switch (i) {
  7. case 0: // no problem
  8. case 1:
  9. i++;
  10. break;
  11. case 2:
  12. i++;
  13. case 3: //fall through!!!
  14. i++;
  15. break;
  16. case 4:
  17. return;
  18. case 5:
  19. throw new RuntimeException("");
  20. case 6:
  21. continue;
  22. case 7: {
  23. break;
  24. }
  25. case 8: {
  26. return;
  27. }
  28. case 9: {
  29. throw new RuntimeException("");
  30. }
  31. case 10: {
  32. continue;
  33. }
  34. case 11: {
  35. i++;
  36. }
  37. case 12: //fall through!!!
  38. if (false)
  39. break;
  40. else
  41. break;
  42. case 13:
  43. if (true) {
  44. return;
  45. }
  46. case 14:
  47. if (true) {
  48. return;
  49. } else {
  50. //do nothing
  51. }
  52. case 15: //fall through!!!
  53. do {
  54. System.out.println("something");
  55. return;
  56. } while(true);
  57. case 16:
  58. for (int j1 = 0; j1 < 10; j1++) {
  59. System.err.println("something");
  60. return;
  61. }
  62. case 17:
  63. while (true)
  64. throw new RuntimeException("");
  65. case 18:
  66. while(cond) {
  67. break;
  68. }
  69. case 19: //fall through!!!
  70. try {
  71. i++;
  72. break;
  73. } catch (RuntimeException e) {
  74. break;
  75. } catch (Error e) {
  76. return;
  77. }
  78. case 20:
  79. try {
  80. i++;
  81. break;
  82. } catch (RuntimeException e) {
  83. } catch (Error e) {
  84. return;
  85. }
  86. case 21: //fall through!!!
  87. try {
  88. i++;
  89. } catch (RuntimeException e) {
  90. i--;
  91. } finally {
  92. break;
  93. }
  94. case 22:
  95. try {
  96. i++;
  97. break;
  98. } catch (RuntimeException e) {
  99. i--;
  100. break;
  101. } finally {
  102. i++;
  103. }
  104. case 23: //fall through!!!
  105. switch (j) {
  106. case 1:
  107. continue;
  108. case 2:
  109. return;
  110. default:
  111. return;
  112. }
  113. case 24:
  114. switch (j) {
  115. case 1:
  116. continue;
  117. case 2:
  118. break;
  119. default:
  120. return;
  121. }
  122. default: //fall through!!!
  123. // this is the last label
  124. i++;
  125. }
  126. }
  127. }
  128. /* Like above, but all fall throughs with relief comment */
  129. void methodFallThru(int i, int j, boolean cond) {
  130. while (true) {
  131. switch (i) {
  132. case -1: // FALLTHRU
  133. case 0: // no problem
  134. case 1:
  135. i++;
  136. break;
  137. case 2:
  138. i++;
  139. // fallthru
  140. case 3:
  141. i++;
  142. break;
  143. case 4:
  144. return;
  145. case 5:
  146. throw new RuntimeException("");
  147. case 6:
  148. continue;
  149. case 7: {
  150. break;
  151. }
  152. case 8: {
  153. return;
  154. }
  155. case 9: {
  156. throw new RuntimeException("");
  157. }
  158. case 10: {
  159. continue;
  160. }
  161. case 11: {
  162. i++;
  163. }
  164. // fallthru
  165. case 12:
  166. if (false)
  167. break;
  168. else
  169. break;
  170. case 13:
  171. if (true) {
  172. return;
  173. }
  174. case 14:
  175. if (true) {
  176. return;
  177. } else {
  178. //do nothing
  179. }
  180. // fallthru
  181. case 15:
  182. do {
  183. System.out.println("something");
  184. return;
  185. } while(true);
  186. case 16:
  187. for (int j1 = 0; j1 < 10; j1++) {
  188. System.err.println("something");
  189. return;
  190. }
  191. case 17:
  192. while (cond)
  193. throw new RuntimeException("");
  194. case 18:
  195. while(cond) {
  196. break;
  197. }
  198. // fallthru
  199. case 19:
  200. try {
  201. i++;
  202. break;
  203. } catch (RuntimeException e) {
  204. break;
  205. } catch (Error e) {
  206. return;
  207. }
  208. case 20:
  209. try {
  210. i++;
  211. break;
  212. } catch (RuntimeException e) {
  213. } catch (Error e) {
  214. return;
  215. }
  216. // fallthru
  217. case 21:
  218. try {
  219. i++;
  220. } catch (RuntimeException e) {
  221. i--;
  222. } finally {
  223. break;
  224. }
  225. case 22:
  226. try {
  227. i++;
  228. break;
  229. } catch (RuntimeException e) {
  230. i--;
  231. break;
  232. } finally {
  233. i++;
  234. }
  235. /* fallthru */
  236. case 23:
  237. switch (j) {
  238. case 1:
  239. continue;
  240. case 2:
  241. return;
  242. default:
  243. return;
  244. }
  245. case 24:
  246. i++;
  247. /* fallthru */ case 25:
  248. i++;
  249. break;
  250. case 26:
  251. switch (j) {
  252. case 1:
  253. continue;
  254. case 2:
  255. break;
  256. default:
  257. return;
  258. }
  259. // fallthru
  260. default:
  261. // this is the last label
  262. i++;
  263. // fallthru
  264. }
  265. }
  266. }
  267. /* Test relief comment. */
  268. void methodFallThruCC(int i, int j, boolean cond) {
  269. while (true) {
  270. switch (i){
  271. case 0:
  272. i++; // fallthru
  273. case 1:
  274. i++;
  275. // fallthru
  276. case 2: {
  277. i++;
  278. }
  279. // fallthru
  280. case 3:
  281. i++;
  282. /* fallthru */case 4:
  283. break;
  284. case 5:
  285. i++;
  286. // fallthru
  287. }
  288. }
  289. }
  290. /* Like above, but C-style comments. */
  291. void methodFallThruC(int i, int j, boolean cond) {
  292. while (true) {
  293. switch (i){
  294. case 0:
  295. i++; /* fallthru */
  296. case 1:
  297. i++;
  298. /* fallthru */
  299. case 2:
  300. i++;
  301. /* fallthru */case 3:
  302. break;
  303. case 4:
  304. i++;
  305. /* fallthru */
  306. }
  307. }
  308. }
  309. /* Like above, but C-style comments with no spaces. */
  310. void methodFallThruC2(int i, int j, boolean cond) {
  311. while (true) {
  312. switch (i){
  313. case 0:
  314. i++; /*fallthru*/
  315. case 1:
  316. i++;
  317. /*fallthru*/
  318. case 2:
  319. i++;
  320. /*fallthru*/case 3:
  321. break;
  322. case 4:
  323. i++;
  324. /*fallthru*/
  325. }
  326. }
  327. }
  328. /* C-style comments with other default fallthru-comment. */
  329. void methodFallThruCOtherWords(int i, int j, boolean cond) {
  330. while (true) {
  331. switch (i){
  332. case 0:
  333. i++; /* falls through */
  334. case 1:
  335. i++;
  336. /* falls through */
  337. case 2:
  338. i++;
  339. /* falls through */case 3:
  340. break;
  341. case 4:
  342. i++;
  343. /* falls through */
  344. }
  345. }
  346. }
  347. /* C-style comments with custom fallthru-comment. */
  348. void methodFallThruCCustomWords(int i, int j, boolean cond) {
  349. while (true) {
  350. switch (i){
  351. case 0:
  352. i++; /* Continue with next case */
  353. case 1:
  354. i++;
  355. /* Continue with next case */
  356. case 2:
  357. i++;
  358. /* Continue with next case */case 3:
  359. break;
  360. case 4:
  361. i++;
  362. /* Continue with next case */
  363. }
  364. }
  365. }
  366. void methodFallThruLastCaseGroup(int i, int j, boolean cond) {
  367. while (true) {
  368. switch (i){
  369. case 0:
  370. i++; // fallthru
  371. }
  372. switch (i){
  373. case 0:
  374. i++;
  375. // fallthru
  376. }
  377. switch (i){
  378. case 0:
  379. i++;
  380. /* fallthru */ }
  381. }
  382. }
  383. void method1472228(int i) {
  384. switch(i) {
  385. case 2:
  386. // do nothing
  387. break;
  388. default:
  389. }
  390. }
  391. }