View Javadoc
1   /*xml
2   <module name="Checker">
3     <module name="TreeWalker">
4       <module name="ReturnCount">
5         <property name="maxForVoid" value="0"/>
6       </module>
7     </module>
8   </module>
9   */
10  package com.puppycrawl.tools.checkstyle.checks.coding.returncount;
11  
12  import java.util.function.Predicate;
13  
14  // xdoc section -- start
15  public class Example2 {
16      public Example2() {}
17      // violation below, 'max allowed for void methods/constructors/lambdas is 0'
18      public Example2(int i) { return; }
19  
20      public int signA(int x) {
21          if (x < -2) { return -1; }
22          return 0;
23      }
24      // violation below, 'max allowed for non-void methods/lambdas is 2'
25      public int signB(int x) {
26          if (x < -2) { return -1; }
27          if (x == 0) { return 0; }
28          if (x > 2) { return 2; }
29          return 1;
30      }
31      // ok below, because default non-void restriction is 2
32      final Predicate<Integer> lambdaA = i -> {
33          if (i > 5) { return true; }
34          return false;
35      };
36  
37      final Predicate<Integer> lambdaB = i -> { return i > 5; };
38  
39      public void methodA(int x) {}
40      // violation below, 'max allowed for void methods/constructors/lambdas is 0'
41      public void methodB(int x) { return; }
42  }
43  // xdoc section -- end