View Javadoc
1   /*
2   JavadocMethod
3   allowedAnnotations = (default)Override
4   validateThrows = true
5   accessModifiers = (default)public, protected, package, private
6   allowMissingParamTags = (default)false
7   allowMissingReturnTag = (default)false
8   tokens = (default)METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF, COMPACT_CTOR_DEF
9   
10  
11  */
12  
13  package com.puppycrawl.tools.checkstyle.checks.javadoc.javadocmethod;
14  
15  public class InputJavadocMethodThrowsDetectionOne {
16  
17      void noJavadoc() {
18          // no javadoc, no violations
19          throw new UnsupportedOperationException("");
20      }
21  
22      /** Simple, trivial case. */
23      void topLevel() {
24          // violation below 'Expected @throws tag for 'UnsupportedOperationException'.'
25          throw new UnsupportedOperationException("");
26      }
27  
28      /**
29       * Example raised in issue 8117.
30       *
31       * @param x some input for control flow statements
32       * @return 0 if there were no problems
33       */
34      int nestedWithinIf(int x) {
35          if (x > 0) {
36              // violation below 'Expected @throws tag for 'UnsupportedOperationException'.'
37              throw new UnsupportedOperationException("");
38          }
39          if (x < 0) {
40              // violation below 'Expected @throws tag for 'IllegalArgumentException'.'
41              throw new IllegalArgumentException("");
42          }
43          return 0;
44      }
45  
46      /**
47       * Some regression cases have comments in front.
48       *
49       * @param x some input for control flow statements
50       */
51      void nestedWithinIfLeadingComment(int x) {
52          if (x > 0) {
53              // some comment in front
54              // violation below 'Expected @throws tag for 'UnsupportedOperationException'.'
55              throw new UnsupportedOperationException("");
56          }
57          if (x < 0) {
58              // some comment in front
59              // violation below 'Expected @throws tag for 'IllegalArgumentException'.'
60              throw new IllegalArgumentException("");
61          }
62      }
63  
64      /**
65       * Check if-else block.
66       *
67       * @param x some input for control flow statements
68       */
69      void nestedWithinIfElse(int x) {
70          if (x > 0) {
71              // violation below 'Expected @throws tag for 'UnsupportedOperationException'.'
72              throw new UnsupportedOperationException("");
73          }
74          else {
75              // violation below 'Expected @throws tag for 'IllegalArgumentException'.'
76              throw new IllegalArgumentException("");
77          }
78      }
79  
80      /**
81       * Check if-else-if block.
82       *
83       * @param x some input for control flow statements
84       */
85      void nestedWithinIfElseIf(int x) {
86          if (x > 0) {
87              // violation below 'Expected @throws tag for 'UnsupportedOperationException'.'
88              throw new UnsupportedOperationException("");
89          }
90          else if (x < 0) {
91              // violation below 'Expected @throws tag for 'IllegalArgumentException'.'
92              throw new IllegalArgumentException("");
93          }
94      }
95  
96  }