View Javadoc
1   /*
2   LeftCurly
3   option = (default)eol
4   ignoreEnums = (default)true
5   tokens = (default)ANNOTATION_DEF, CLASS_DEF, CTOR_DEF, ENUM_CONSTANT_DEF, \
6            ENUM_DEF, INTERFACE_DEF, LAMBDA, LITERAL_CASE, LITERAL_CATCH, \
7            LITERAL_DEFAULT, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, \
8            LITERAL_IF, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, \
9            METHOD_DEF, OBJBLOCK, STATIC_INIT, RECORD_DEF, COMPACT_CTOR_DEF
10  
11  
12  */
13  
14  package com.puppycrawl.tools.checkstyle.checks.blocks.leftcurly;
15  
16  class InputLeftCurlyTestMissingBraces
17  { // violation ''{' at column 1 should be on the previous line'
18      /** @return helper func **/
19      boolean condition()
20      { // violation ''{' at column 5 should be on the previous line'
21          return false;
22      }
23  
24      /** Test do/while loops **/
25      void testDoWhile()
26      { // violation ''{' at column 5 should be on the previous line'
27          // Valid
28          do {
29              testDoWhile();
30          }
31          while (condition());
32  
33          // Invalid
34          do testDoWhile(); while (condition());
35      }
36  
37      /** Test while loops **/
38      void testWhile()
39      { // violation ''{' at column 5 should be on the previous line'
40          // Valid
41          while (condition()) {
42              testWhile();
43          }
44  
45          // Invalid
46          while(condition());
47          while (condition())
48              testWhile();
49          while (condition())
50              if (condition())
51                  testWhile();
52      }
53  
54      /** Test for loops **/
55      void testFor()
56      { // violation ''{' at column 5 should be on the previous line'
57          // Valid
58          for (int i = 1; i < 5; i++) {
59              testFor();
60          }
61  
62          // Invalid
63          for(int i = 1;i < 5;i++);
64          for (int i = 1; i < 5; i++)
65              testFor();
66          for (int i = 1; i < 5;
67               i++)
68              if (i > 2)
69                  testFor();
70      }
71  
72      /** Test if constructs **/
73      public void testIf()
74      { // violation ''{' at column 5 should be on the previous line'
75          // Valid
76          if (condition()) {
77              testIf();
78          }
79          else if (condition()) {
80              testIf();
81          }
82          else {
83              testIf();
84          }
85  
86          // Invalid
87          if (condition());
88          if (condition())
89              testIf();
90          if (condition())
91              testIf();
92          else
93              testIf();
94          if (condition())
95              testIf();
96          else {
97              testIf();
98          }
99          if (condition()) {
100             testIf();
101         }
102         else
103             testIf();
104         if (condition())
105             if (condition())
106                 testIf();
107     }
108 
109     void whitespaceAfterSemi()
110     { // violation ''{' at column 5 should be on the previous line'
111         //reject
112         int i = 1;int j = 2;
113 
114         //accept
115         for (;;) {
116         }
117     }
118 
119     /** Empty constructor block. **/
120     public InputLeftCurlyTestMissingBraces() {}
121 
122     /** Empty method block. **/
123     public void emptyImplementation() {}
124 }