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