View Javadoc
1   /*
2   com.puppycrawl.tools.checkstyle.checks.coding.NestedIfDepthCheck
3   max = (default)1
4   
5   
6   */
7   
8   package com.puppycrawl.tools.checkstyle.utils.checkutil;
9   
10  public class InputCheckUtil3 {
11  
12      void foo() {
13          // nesting == 0
14          if (true) {
15          }
16  
17          // nesting == 1
18          if (true) {
19              if (true) {
20              }
21          }
22  
23          // nesting == 2
24          if (true) {
25              if (true) {
26                  if (true) { // violation 'Nested if-else depth is 2 (max allowed is 1)'
27                  }
28              }
29          }
30      }
31  
32      void fooWithElse() {
33          // nesting == 0
34          if (true) {
35          } else {
36          }
37  
38          // nesting == 1
39          if (true) {
40              if (true) {
41              } else {
42              }
43          } else {
44              if (false) {
45              } else {
46              }
47          }
48  
49          // nesting == 2
50          if (true) {
51              if (true) {
52                  if (true) { // violation 'Nested if-else depth is 2 (max allowed is 1)'
53                  } else {
54                  }
55              } else {
56                  if (false) {
57                  } else {
58                  }
59              }
60          } else {
61              if (true) {
62                  if (true) {
63                  } else {
64                  }
65              } else {
66                  if (false) {
67                  } else {
68                  }
69              }
70          }
71      }
72  }