View Javadoc
1   package com.github.sevntu.checkstyle.checks.coding;
2   public class InputReturnCountExtendedCheckMethods
3   {
4   
5       int a = 0;
6   
7       public int oneReturnInMethod() {
8           return a;
9       }
10  
11      public int oneReturnInMethod2() {
12          for (int i = 0; i < 10; i++) {
13              System.out.println();
14              int a = 1;
15              if (a != 2 && true) {
16                  if (true | false) {
17                      if (a - a != 0) {
18                          a += 1;
19                      }
20                  }
21              }
22          }
23          return a + a * a;
24      }
25  
26      public int twoReturnsInMethod() {
27          System.out.println();
28          int a = 1;
29          if (a != 4) {
30              return 1;
31          }
32          else {
33              System.out.println(a);
34              return 2;
35          }
36      }
37  
38      public int threeReturnsInMethod() {
39          System.out.println();
40          int a = 1;
41          if (a != 4)
42          {
43              return 1;
44          }
45          else
46          {
47              if (a - 1 != 2) {
48                  this.a = 0;
49                  return 6;
50              }
51              else {
52                  System.out.println();
53                  return 2;
54              }
55          }
56      }
57  
58      public int fourReturnsInMethod() {
59          System.out.println();
60          int a = 1;
61          if (a != 4)  {
62              if (a != 6) {
63                  return 1;
64              }
65              else {
66                  a++;
67              }
68              return 4;
69          }
70          else {
71              if (a - 1 != 2) {
72                  this.a = 0;
73                  return 6;
74              }
75              else {
76                  System.out.println();
77                  return 2;
78              }
79          }
80      }
81  
82      // exclusive test method with the "return" depth = 3 
83      public int r() {
84         do {
85             if(true) {
86                 if(true)return 5;
87             }
88         } while(true);
89      }
90      
91      //exclusive test for "try-catch block processing"
92      public int nm()
93      {
94          if (true) {
95              try {
96              }
97              catch (Exception e) {
98                  if (true)
99                      return 5;
100             }
101         }
102         return a;
103     }
104 
105     public void returnFromLiteral() {
106         if (true) {
107             return;
108         }
109 
110         switch (hashCode()) {
111         case 0:
112             return;
113         }
114 
115         if (false) {
116             for (;;) {
117                 return;
118             }
119         }
120 
121         if (false) {
122             do {
123                 return;
124             } while (false);
125         }
126 
127         if (false)
128             while (true) {
129                 return;
130             }
131 
132         try {
133             return;
134         } catch (Exception e) {
135         }
136     }
137 
138     public void doNothing() {
139         return;
140     }
141 }