1 /* 2 WhitespaceAround 3 allowEmptyConstructors = (default)false 4 allowEmptyMethods = (default)false 5 allowEmptyTypes = (default)false 6 allowEmptyLoops = (default)false 7 allowEmptyLambdas = (default)false 8 allowEmptyCatches = (default)false 9 ignoreEnhancedForColon = (default)true 10 tokens = (default)ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, \ 11 BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, DO_WHILE, EQUAL, GE, GT, LAMBDA, LAND, \ 12 LCURLY, LE, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, \ 13 LITERAL_FOR, LITERAL_IF, LITERAL_RETURN, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, \ 14 LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN, \ 15 NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, RCURLY, SL, SLIST, SL_ASSIGN, SR, \ 16 SR_ASSIGN, STAR, STAR_ASSIGN, LITERAL_ASSERT, TYPE_EXTENSION_AND 17 18 19 */ 20 21 package com.puppycrawl.tools.checkstyle.checks.whitespace.whitespacearound; 22 23 /** 24 * Contains simple mistakes: 25 * - Long lines 26 * - Tabs 27 * - Format of variables and parameters 28 * - Order of modifiers 29 * @author Oliver Burn 30 **/ 31 final class InputWhitespaceAroundSimple 32 { 33 // Long line ---------------------------------------------------------------- 34 // Contains a tab -> <- 35 // Contains trailing whitespace -> 36 37 // Name format tests 38 // 39 /** Invalid format **/ 40 public static final int badConstant = 2; 41 /** Valid format **/ 42 public static final int MAX_ROWS = 2; 43 44 /** Invalid format **/ 45 private static int badStatic = 2; 46 /** Valid format **/ 47 private static int sNumCreated = 0; 48 49 /** Invalid format **/ 50 private int badMember = 2; 51 /** Valid format **/ 52 private int mNumCreated1 = 0; 53 /** Valid format **/ 54 protected int mNumCreated2 = 0; 55 56 /** commas are wrong **/ 57 private int[] mInts = new int[] {1,2, 3, 58 4}; 59 60 // 61 // Accessor tests 62 // 63 /** should be private **/ 64 public static int sTest1; 65 /** should be private **/ 66 protected static int sTest3; 67 /** should be private **/ 68 static int sTest2; 69 70 /** should be private **/ 71 int mTest1; 72 /** should be private **/ 73 public int mTest2; 74 75 // 76 // Parameter name format tests 77 // 78 79 /** 80 * @return hack 81 * @param badFormat1 bad format 82 * @param badFormat2 bad format 83 * @param badFormat3 bad format 84 * @throws Exception abc 85 **/ 86 int test1(int badFormat1,int badFormat2, 87 final int badFormat3) 88 throws Exception 89 { 90 return 0; 91 } 92 93 /** method that is 20 lines long **/ 94 private void longMethod() 95 { 96 // a line 97 // a line 98 // a line 99 // a line 100 // a line 101 // a line 102 // a line 103 // a line 104 // a line 105 // a line 106 // a line 107 // a line 108 // a line 109 // a line 110 // a line 111 // a line 112 // a line 113 // a line 114 } 115 116 /** constructor that is 10 lines long **/ 117 private InputWhitespaceAroundSimple() 118 { 119 // a line 120 // a line 121 // a line 122 // a line 123 // a line 124 // a line 125 // a line 126 // a line 127 } 128 129 /** test local variables */ 130 private void localVariables() 131 { 132 // normal decl 133 int abc = 0; 134 int ABC = 0; 135 136 // final decls 137 final int cde = 0; 138 final int CDE = 0; 139 140 // decl in for loop init statement 141 for (int k = 0; k < 1; k++) 142 { 143 String innerBlockVariable = ""; 144 } 145 for (int I = 0; I < 1; I++) 146 { 147 String InnerBlockVariable = ""; 148 } 149 } 150 151 /** test method pattern */ 152 void ALL_UPPERCASE_METHOD() 153 { 154 } 155 156 /** test illegal constant **/ 157 private static final int BAD__NAME = 3; 158 159 // A very, very long line that is OK because it matches the regexp "^.*is OK.*regexp.*$" 160 // long line that has a tab -> <- and would be OK if tab counted as 1 char 161 // tabs that count as one char because of their position -> <- -> <-, OK 162 163 /** some lines to test the violation column after tabs */ 164 void errorColumnAfterTabs() 165 { 166 // with tab-width 8 all statements below start at the same column, 167 // with different combinations of ' ' and '\t' before the statement 168 int tab0 =1; // violation ''=' is not followed by whitespace' 169 int tab1 =1; // violation ''=' is not followed by whitespace' 170 int tab2 =1; // violation ''=' is not followed by whitespace' 171 int tab3 =1; // violation ''=' is not followed by whitespace' 172 int tab4 =1; // violation ''=' is not followed by whitespace' 173 int tab5 =1; // violation ''=' is not followed by whitespace' 174 } 175 176 // MEMME: 177 /* MEMME: a 178 * MEMME: 179 * OOOO 180 */ 181 /* NOTHING */ 182 /* YES */ /* MEMME: x */ /* YES!! */ 183 184 /** test long comments **/ 185 void veryLong() 186 { 187 /* 188 blah blah blah blah 189 blah blah blah blah 190 blah blah blah blah 191 blah blah blah blah 192 blah blah blah blah 193 blah blah blah blah 194 blah blah blah blah 195 blah blah blah blah 196 blah blah blah blah 197 blah blah blah blah 198 blah blah blah blah 199 blah blah blah blah 200 blah blah blah blah 201 blah blah blah blah 202 blah blah blah blah 203 enough talk */ 204 } 205 206 /** 207 * @see to lazy to document all args. Testing excessive # args 208 **/ 209 void toManyArgs(int aArg1, int aArg2, int aArg3, int aArg4, int aArg5, 210 int aArg6, int aArg7, int aArg8, int aArg9) 211 { 212 } 213 } 214 215 /** Test class for variable naming in for each clause. */ 216 class InputWhitespaceAroundSimple2 217 { 218 /** Some more Javadoc. */ 219 public void doSomething() 220 { 221 //"O" should be named "o" 222 for (Object O : new java.util.ArrayList()) 223 { 224 225 } 226 } 227 } 228 229 /** Test enum for member naming check */ 230 enum MyEnum1 231 { 232 /** ABC constant */ 233 ABC, 234 235 /** XYZ constant */ 236 XYZ; 237 238 /** Should be mSomeMember */ 239 private int someMember; 240 }