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