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