View Javadoc
1   /*xml
2   <module name="Checker">
3     <module name="TreeWalker">
4       <module name="DescendantToken">
5         <property name="tokens" value="METHOD_DEF"/>
6         <property name="limitedTokens" value="LITERAL_RETURN"/>
7         <property name="maximumNumber" value="2"/>
8       </module>
9     </module>
10  </module>
11  */
12  package com.puppycrawl.tools.checkstyle.checks.descendanttoken;
13  
14  // xdoc section -- start
15  class Example9 {
16    void testMethod1() {
17      int var1 = 1;
18    }
19    void testMethod2() {
20      int var1 = 1;
21      int var2 = 2;
22    }
23  
24    int testMethod3(int x) { // violation 'Count of 3 for 'METHOD_DEF' descendant'
25      if (x == -1) {
26        return -1;
27      }
28      else if (x == 0) {
29        return 0;
30      }
31      return -1;
32    }
33    int testMethod4(int x) { // violation 'Count of 3 for 'METHOD_DEF' descendant'
34      if (x == -1) {
35        return -1;
36      }
37      else if (x == 0) {
38        return 0;
39      }
40      else {
41        return x;
42      }
43    }
44  }
45  // xdoc section -- end
46