View Javadoc
1   package integrationTests;
2   
3   /**
4    * The Class IfElseStatements.
5    */
6   @SuppressWarnings("ControlFlowStatementWithoutBraces")
7   public final class IfElseStatements {
8   
9       /**
10       * Simple if.
11       *
12       * @param b
13       *            the b
14       */
15      void simpleIf(boolean b) {
16          if (b) {
17              System.gc();
18              System.runFinalization();
19          }
20      }
21  
22      /**
23       * If and else.
24       *
25       * @param b
26       *            the b
27       */
28      void ifAndElse(boolean b) {
29          if (b) {
30              System.gc();
31          } else {
32              System.runFinalization();
33          }
34      }
35  
36      /**
37       * Single line if.
38       *
39       * @param b
40       *            the b
41       */
42      void singleLineIf(boolean b) {
43          // @formatter:off
44          if (b) { System.gc(); }
45          // @formatter:on
46      }
47  
48      /**
49       * Single line if and else.
50       *
51       * @param b
52       *            the b
53       */
54      void singleLineIfAndElse(boolean b) {
55          // @formatter:off
56          if (b) { System.gc(); } else { System.runFinalization(); }
57          // @formatter:on
58      }
59  
60      /**
61       * Method with four different paths and simple lines.
62       *
63       * @param b
64       *            the b
65       * @param i
66       *            the i
67       */
68      void methodWithFourDifferentPathsAndSimpleLines(boolean b, int i) {
69          if (b) {
70              System.gc();
71          } else {
72              System.runFinalization();
73          }
74  
75          if (i > 0) {
76              System.gc();
77          }
78      }
79  
80      /**
81       * Method with four different paths and segmented lines.
82       *
83       * @param b
84       *            the b
85       * @param i
86       *            the i
87       */
88      void methodWithFourDifferentPathsAndSegmentedLines(boolean b, int i) {
89          if (b) {
90              System.gc();
91          } else {
92              System.runFinalization();
93          }
94  
95          if (i > 0) {
96              System.gc();
97          } else {
98              System.runFinalization();
99          }
100     }
101 
102     /**
103      * If else with complex boolean condition.
104      *
105      * @param a
106      *            the a
107      * @param b
108      *            the b
109      *
110      * @return true, if successful
111      */
112     boolean ifElseWithComplexBooleanCondition(boolean a, boolean b) {
113         // noinspection RedundantIfStatement
114         if (a || b) {
115             return true;
116         }
117         return false;
118     }
119 
120     /**
121      * Return input.
122      *
123      * @param x
124      *            the x
125      * @param a
126      *            the a
127      * @param b
128      *            the b
129      * @param c
130      *            the c
131      *
132      * @return the int
133      */
134     // Must return the same value of x as it was called with. Some paths will fail that requirement.
135     @SuppressWarnings({ "AssignmentToMethodParameter" })
136     int returnInput(int x, boolean a, boolean b, boolean c) {
137         if (a) {
138             x++;
139         }
140 
141         if (b) {
142             x--;
143         }
144 
145         if (c) {
146             // noinspection SillyAssignment
147             x = x;
148         }
149 
150         return x;
151     }
152 
153     /**
154      * Nested if.
155      *
156      * @param a
157      *            the a
158      * @param b
159      *            the b
160      *
161      * @return the int
162      */
163     int nestedIf(boolean a, boolean b) {
164         int i = 1;
165 
166         if (a && b) {
167             i = 2;
168         }
169 
170         return i;
171     }
172 
173     /**
174      * If else with nested if.
175      *
176      * @param a
177      *            the a
178      * @param b
179      *            the b
180      *
181      * @return the int
182      */
183     int ifElseWithNestedIf(boolean a, boolean b) {
184         int i = 1;
185 
186         if (!a) {
187             return 3;
188         }
189         if (b) {
190             i = 2;
191         }
192 
193         return i;
194     }
195 
196     /**
197      * Nested if else.
198      *
199      * @param a
200      *            the a
201      * @param b
202      *            the b
203      *
204      * @return the int
205      */
206     int nestedIfElse(boolean a, boolean b) {
207         int i = 1;
208 
209         if (a) {
210             if (b) {
211                 i = 2;
212             } else {
213                 i = 3;
214             }
215         } else if (b) {
216             i = 4;
217         }
218 
219         return i;
220     }
221 
222     /**
223      * Block comment with method signature: infeasiblePaths(boolean a).
224      *
225      * @param a
226      *            the a
227      */
228     void infeasiblePaths(boolean a) {
229         if (a) {
230             System.gc();
231         }
232 
233         if (a) {
234             System.runFinalization();
235         }
236     }
237 
238     /**
239      * Another single line if and else.
240      *
241      * @param b
242      *            the b
243      *
244      * @return the int
245      */
246     int anotherSingleLineIfAndElse(boolean b) {
247         // @formatter:off
248         int r; if (b) { r = 1; } else { r = 2; } return r;
249         // @formatter:on
250     }
251 
252     /**
253      * Yet another single line if and else.
254      *
255      * @param b
256      *            the b
257      *
258      * @return the int
259      */
260     int yetAnotherSingleLineIfAndElse(boolean b) {
261         // @formatter:off
262         if (b) { return 1; } return 2;
263         // @formatter:on
264     }
265 
266     /**
267      * If with boolean and operator.
268      *
269      * @param b1
270      *            the b 1
271      * @param b2
272      *            the b 2
273      */
274     void ifWithBooleanAndOperator(boolean b1, boolean b2) {
275         if (b1 && b2) {
276             System.gc();
277         }
278     }
279 
280     /**
281      * If with boolean or operator.
282      *
283      * @param b1
284      *            the b 1
285      * @param b2
286      *            the b 2
287      */
288     void ifWithBooleanOrOperator(boolean b1, boolean b2) {
289         if (b1 || b2) {
290             System.gc();
291         }
292     }
293 
294     /**
295      * Another if with boolean and operator.
296      *
297      * @param b1
298      *            the b 1
299      * @param b2
300      *            the b 2
301      */
302     void anotherIfWithBooleanAndOperator(boolean b1, boolean b2) {
303         if (b1 && b2) {
304             System.gc();
305         }
306     }
307 
308     /**
309      * If spanning multiple lines.
310      *
311      * @param b
312      *            the b
313      * @param i
314      *            the i
315      */
316     void ifSpanningMultipleLines(boolean b, int i) {
317         // @formatter:off
318         if (
319            b ||
320            i > 0
321         ) {
322             System.gc();
323         }
324         // @formatter:on
325     }
326 
327     /**
328      * Method to be called from custom runner test.
329      *
330      * @param s
331      *            the s
332      *
333      * @return the class loader
334      */
335     ClassLoader methodToBeCalledFromCustomRunnerTest(String s) {
336         instanceField = s;
337 
338         if (s.isEmpty()) {
339             return null;
340         }
341 
342         return getClass().getClassLoader();
343     }
344 
345     /** The instance field. */
346     String instanceField;
347 }