1 /* 2 LineLength 3 fileExtensions = (default)all files 4 ignorePattern = ^.*is OK.*regexp.*$ 5 max = (default)80 6 message.maxLineLen = {0},{1} 7 8 9 */ 10 11 package com.puppycrawl.tools.checkstyle.checks.sizes.linelength; 12 13 /** 14 * Contains simple mistakes: 15 * - Long lines 16 * - Tabs 17 * - Format of variables and parameters 18 * - Order of modifiers 19 * @author Oliver Burn 20 **/ 21 final class InputLineLengthSimple1 22 { 23 // Long line --------------------------------------------------- // violation 24 // Contains a tab -> <- 25 // Contains trailing whitespace -> 26 27 // Name format tests 28 // 29 /** Invalid format **/ 30 public static final int badConstant = 2; 31 /** Valid format **/ 32 public static final int MAX_ROWS = 2; 33 34 /** Invalid format **/ 35 private static int badStatic = 2; 36 /** Valid format **/ 37 private static int sNumCreated = 0; 38 39 /** Invalid format **/ 40 private int badMember = 2; 41 /** Valid format **/ 42 private int mNumCreated1 = 0; 43 /** Valid format **/ 44 protected int mNumCreated2 = 0; 45 46 /** commas are wrong **/ 47 private int[] mInts = new int[] {1,2, 3, 48 4}; 49 50 // 51 // Accessor tests 52 // 53 /** should be private **/ 54 public static int sTest1; 55 /** should be private **/ 56 protected static int sTest3; 57 /** should be private **/ 58 static int sTest2; 59 60 /** should be private **/ 61 int mTest1; 62 /** should be private **/ 63 public int mTest2; 64 65 // 66 // Parameter name format tests 67 // 68 69 /** 70 * @return hack 71 * @param badFormat1 bad format 72 * @param badFormat2 bad format 73 * @param badFormat3 bad format 74 * @throws Exception abc 75 **/ 76 int test1(int badFormat1,int badFormat2, 77 final int badFormat3) 78 throws Exception 79 { 80 return 0; 81 } 82 83 /** method that is 20 lines long **/ 84 private void longMethod() 85 { 86 // a line 87 // a line 88 // a line 89 // a line 90 // a line 91 // a line 92 // a line 93 // a line 94 // a line 95 // a line 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 } 105 106 /** constructor that is 10 lines long **/ 107 private InputLineLengthSimple1() 108 { 109 // a line 110 // a line 111 // a line 112 // a line 113 // a line 114 // a line 115 // a line 116 // a line 117 } 118 119 /** test local variables */ 120 private void localVariables() 121 { 122 // normal decl 123 int abc = 0; 124 int ABC = 0; 125 126 // final decls 127 final int cde = 0; 128 final int CDE = 0; 129 130 // decl in for loop init statement 131 for (int k = 0; k < 1; k++) 132 { 133 String innerBlockVariable = ""; 134 } 135 for (int I = 0; I < 1; I++) 136 { 137 String InnerBlockVariable = ""; 138 } 139 } 140 141 /** test method pattern */ 142 void ALL_UPPERCASE_METHOD() 143 { 144 } 145 146 /** test illegal constant **/ 147 private static final int BAD__NAME = 3; 148 149 // A very, very long line that is OK because it matches the regexp "^.*is OK.*regexp.*$" 150 // line has a tab -> <- and but OK if tab counted as 1 char // violation 151 // tabs that count as one char because of their position -> <- -> <-, OK 152 153 /** some lines to test the violation column after tabs */ 154 void errorColumnAfterTabs() 155 { 156 // with tab-width 8 all statements below start at the same column, 157 // with different combinations of ' ' and '\t' before the statement 158 int tab0 =1; 159 int tab1 =1; 160 int tab2 =1; 161 int tab3 =1; 162 int tab4 =1; 163 int tab5 =1; 164 } 165 166 // MEMME: 167 /* MEMME: a 168 * MEMME: 169 * OOOO 170 */ 171 /* NOTHING */ 172 /* YES */ /* MEMME: x */ /* YES!! */ 173 174 /** test long comments **/ 175 void veryLong() 176 { 177 /* 178 blah blah blah blah 179 blah blah blah blah 180 blah blah blah blah 181 blah blah blah blah 182 blah blah blah blah 183 blah blah blah blah 184 blah blah blah blah 185 blah blah blah blah 186 blah blah blah blah 187 blah blah blah blah 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 enough talk */ 194 } 195 196 /** 197 * @see to lazy to document all args. Testing excessive # args 198 **/ 199 void toManyArgs(int aArg1, int aArg2, int aArg3, int aArg4, int aArg5, 200 int aArg6, int aArg7, int aArg8, int aArg9) 201 { 202 } 203 } 204 205 /** Test class for variable naming in for each clause. */ 206 class InputLineLengthSimple3 207 { 208 /** Some more Javadoc. */ 209 public void doSomething() 210 { 211 //"O" should be named "o" 212 for (Object O : new java.util.ArrayList()) 213 { 214 215 } 216 } 217 } 218 219 /** Test enum for member naming check */ 220 enum MyEnum2 221 { 222 /** ABC constant */ 223 ABC, 224 225 /** XYZ constant */ 226 XYZ; 227 228 /** Should be mSomeMember */ 229 private int someMember; 230 }