KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > InputBraces


1 ////////////////////////////////////////////////////////////////////////////////
2
// Test case file for checkstyle.
3
// Created: 2001
4
////////////////////////////////////////////////////////////////////////////////
5
package com.puppycrawl.tools.checkstyle;
6
7 /**
8  * Test case for correct use of braces.
9  * @author Oliver Burn
10  **/

11 class InputBraces
12 {
13     /** @return helper func **/
14     boolean condition()
15     {
16         return false;
17     }
18
19     /** Test do/while loops **/
20     void testDoWhile()
21     {
22         // Valid
23
do {
24             testDoWhile();
25         }
26         while (condition());
27
28         // Invalid
29
do testDoWhile(); while (condition());
30     }
31
32     /** Test while loops **/
33     void testWhile()
34     {
35         // Valid
36
while (condition()) {
37             testWhile();
38         }
39
40         // Invalid
41
while(condition());
42         while (condition())
43             testWhile();
44         while (condition())
45             if (condition())
46                 testWhile();
47     }
48
49     /** Test for loops **/
50     void testFor()
51     {
52         // Valid
53
for (int i = 1; i < 5; i++) {
54             testFor();
55         }
56
57         // Invalid
58
for(int i = 1;i < 5;i++);
59         for (int i = 1; i < 5; i++)
60             testFor();
61         for (int i = 1; i < 5;
62              i++)
63             if (i > 2)
64                 testFor();
65     }
66
67     /** Test if constructs **/
68     public void testIf()
69     {
70         // Valid
71
if (condition()) {
72             testIf();
73         }
74         else if (condition()) {
75             testIf();
76         }
77         else {
78             testIf();
79         }
80
81         // Invalid
82
if (condition());
83         if (condition())
84             testIf();
85         if (condition())
86             testIf();
87         else
88             testIf();
89         if (condition())
90             testIf();
91         else {
92             testIf();
93         }
94         if (condition()) {
95             testIf();
96         }
97         else
98             testIf();
99         if (condition())
100             if (condition())
101                 testIf();
102     }
103
104     void whitespaceAfterSemi()
105     {
106         //reject
107
int i = 1;int j = 2;
108
109         //accept
110
for (;;) {
111         }
112     }
113
114     /** Empty constructor block. **/
115     public InputBraces() {}
116     
117     /** Empty method block. **/
118     public void emptyImplementation() {}
119 }
120
Popular Tags