View Javadoc
1   /*xml
2   <module name="Checker">
3     <module name="TreeWalker">
4       <module name="SimplifyBooleanReturn"/>
5     </module>
6   </module>
7   */
8   package com.puppycrawl.tools.checkstyle.checks.coding.simplifybooleanreturn;
9   
10  // xdoc section -- start
11  class Example1 {
12  
13    boolean cond;
14    int a,b;
15  
16    boolean check1() {
17      if (cond) { // violation, 'Conditional logic can be removed
18        return true;
19      } else {
20        return false;
21      }
22    }
23  
24    boolean check1Simplified() {
25      return cond;
26    }
27  
28    boolean check2() {
29      if (cond == true) { // violation, 'Conditional logic can be removed'
30        return false;
31      } else {
32        return true;
33      }
34    }
35  
36    // ok, can be simplified but doesn't return a Boolean
37    int choose1() {
38      if (cond) {
39        return a;
40      } else {
41        return b;
42      }
43    }
44  
45    int choose1Simplified() {
46      return cond ? a: b;
47    }
48  }
49  // xdoc section -- end