1 /* 2 JavadocVariable 3 scope = (default)private 4 excludeScope = (default)null 5 ignoreNamePattern = (default)null 6 tokens = (default)ENUM_CONSTANT_DEF 7 8 9 */ 10 11 package com.puppycrawl.tools.checkstyle.checks.javadoc.javadocvariable; 12 13 import java.io.IOException; 14 15 class InputJavadocVariableTags1 16 { 17 // Invalid - should be Javadoc 18 private int mMissingJavadoc; // violation 19 20 // Invalid - should be Javadoc 21 void method1() 22 { 23 } 24 25 /** @param unused asd **/ 26 void method2() 27 { 28 } 29 30 /** missing return **/ 31 int method3() 32 { 33 return 3; 34 } 35 36 /** 37 * <p>missing return 38 * @param aOne ignored 39 **/ 40 int method4(int aOne) 41 { 42 return aOne; 43 } 44 45 /** missing throws **/ 46 void method5() 47 throws Exception 48 { 49 } 50 51 /** 52 * @see missing throws 53 * @see need to see tags to avoid shortcut logic 54 **/ 55 void method6() 56 throws Exception 57 { 58 } 59 60 /** @throws WrongException problem **/ 61 void method7() 62 throws Exception, NullPointerException 63 { 64 } 65 66 /** missing param **/ 67 void method8(int aOne) 68 { 69 } 70 71 /** 72 * @see missing param 73 * @see need to see tags to avoid shortcut logic 74 **/ 75 void method9(int aOne) 76 { 77 } 78 79 /** @param WrongParam problem **/ 80 void method10(int aOne, int aTwo) 81 { 82 } 83 84 /** 85 * @param Unneeded parameter 86 * @return also unneeded 87 **/ 88 void method11() 89 { 90 } 91 92 /** 93 * @return first one 94 * @return duplicate 95 **/ 96 int method12() 97 { 98 return 0; 99 } 100 101 /** 102 * @param aOne 103 * @param aTwo 104 * 105 * This is a multiline piece of javadoc 106 * Unlike the previous one, it actually has content 107 * @param aThree 108 * 109 * 110 * This also has content 111 * @param aFour 112 113 * 114 * @param aFive 115 **/ 116 void method13(int aOne, int aTwo, int aThree, int aFour, int aFive) 117 { 118 } 119 120 /** @param aOne Perfectly legal **/ 121 void method14(int aOne) 122 { 123 } 124 125 /** @throws java.io.IOException 126 * just to see if this is also legal **/ 127 void method14() 128 throws java.io.IOException 129 { 130 } 131 132 133 134 // Test static initialiser 135 static 136 { 137 int x = 1; // should not require any javadoc 138 } 139 140 // test initialiser 141 { 142 int z = 2; // should not require any javadoc 143 } 144 145 /** handle where variable declaration over several lines **/ 146 private static final int 147 ON_SECOND_LINE = 2; 148 149 150 /** 151 * Documenting different causes for the same exception 152 * in separate tags is OK (bug 540384). 153 * 154 * @throws java.io.IOException if A happens 155 * @throws java.io.IOException if B happens 156 **/ 157 void method15() 158 throws java.io.IOException 159 { 160 } 161 162 /** {@inheritDoc} **/ 163 public String toString() 164 { 165 return super.toString(); 166 } 167 168 /** getting code coverage up **/ 169 static final int serialVersionUID = 666; 170 171 //**********************************************************************/ 172 // Method Name: method16 173 /** 174 * handle the case of an elaborate header surrounding javadoc comments 175 * 176 * @param aOne valid parameter content 177 */ 178 //**********************************************************************/ 179 void method16(int aOne) 180 { 181 } 182 183 184 /** 185 * @throws ThreadDeath although bad practice, should be silently ignored 186 * @throws ArrayStoreException another r/t subclass 187 * @throws IllegalMonitorStateException should be told to remove from throws 188 */ 189 void method17() 190 throws IllegalMonitorStateException 191 { 192 } 193 194 /** 195 * declaring the imported version of an Exception and documenting 196 * the full class name is OK (bug 658805). 197 * @throws java.io.IOException if bad things happen. 198 */ 199 void method18() 200 throws IOException 201 { 202 throw new IOException("to make compiler happy"); 203 } 204 205 /** 206 * reverse of bug 658805. 207 * @throws IOException if bad things happen. 208 */ 209 void method19() 210 throws java.io.IOException 211 { 212 throw new IOException("to make compiler happy"); 213 } 214 215 /** 216 * Bug 579190, "expected return tag when one is there". 217 * 218 * Linebreaks after return tag should be legal. 219 * 220 * @return 221 * the bug that states that linebreak should be legal 222 */ 223 int method20() 224 { 225 return 579190; 226 } 227 228 /** 229 * Bug XXXX, "two tags for the same exception" 230 * 231 * @exception java.io.IOException for some reasons 232 * @exception IOException for another reason 233 */ 234 void method21() 235 throws IOException 236 { 237 } 238 239 /** 240 * RFE 540383, "Unused throws tag for exception subclass" 241 * 242 * @exception IOException for some reasons 243 * @exception java.io.FileNotFoundException for another reasons 244 */ 245 void method22() 246 throws IOException 247 { 248 } 249 250 /** 251 * @exception WrongException exception w/o class info but matched by name 252 */ 253 void method23() throws WrongException 254 { 255 } 256 257 /** 258 * Bug 803577, "allowThrowsTagsForSubclasses/allowMissingThrowsTag interfere" 259 * 260 * no exception tag for IOException, but here is a tag for its subclass. 261 * @exception java.io.FileNotFoundException for another reasons 262 */ 263 void method24() throws IOException 264 { 265 } 266 267 /** 268 * Bug 841942, "ArrayIndexOutOfBounds in JavadocStyle". 269 * @param aParam there is no such param in the method. 270 * The problem should be reported with correct line number. 271 */ 272 273 void method25() 274 { 275 } 276 277 /** {@inheritDoc} */ 278 int method26() 279 { return 0; 280 } 281 282 /** 283 * {@inheritDoc} 284 * @return something very important. 285 */ 286 int method27(int aParam) 287 { return 0; 288 } 289 290 /** 291 * @return something very important. 292 * {@inheritDoc} 293 */ 294 int method28(int aParam) 295 { return 0; 296 } 297 298 /** 299 * {@inheritDoc} 300 * 301 * @return 1 302 */ 303 public int foo(Object _arg) { 304 305 return 1; 306 } 307 } 308 309 enum InputJavadocVariableTagsEnum 310 { 311 CONSTANT_A, // violation 312 313 /** 314 * 315 */ 316 CONSTANT_B, 317 318 CONSTANT_C // violation 319 { 320 /** 321 * 322 */ 323 public void someMethod() 324 { 325 } 326 327 public void someOtherMethod() 328 { 329 330 } 331 } 332 } 333 334 @interface InputJavadocVariableTagsAnnotation 335 { 336 String someField(); 337 int A_CONSTANT = 0; // violation 338 /** Some javadoc. */ 339 int B_CONSTANT = 1; 340 /** @return This tag is valid here and expected with Java 8 */ 341 String someField2(); 342 } 343 344 /** 345 * Some javadoc. 346 */ 347 public class InputJavadocVariableTags { 348 349 /** 350 * Constructor. 351 */ 352 public InputJavadocVariableTags() { 353 } 354 355 /** 356 * Sample method. 357 * @param arg1 first argument 358 * @param arg2 second argument 359 * @return java.lang.String the result string 360 * @throws java.lang.Exception in case of problem 361 */ 362 public final String myMethod(final String arg1, 363 final Object arg2) 364 throws Exception 365 { 366 return null; 367 } 368 } 369 370 /** 371 * Added to make this file compilable. 372 */ 373 class WrongException extends RuntimeException 374 { 375 }