View Javadoc
1   /*
2   NestedIfDepth
3   max = (default)1
4   
5   
6   */
7   
8   package com.puppycrawl.tools.checkstyle.checks.coding.nestedifdepth;
9   
10  public class InputNestedIfDepthDefault
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
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
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  
73      void method() {
74          // nesting == 2
75          if (true) {
76              if (true) {
77                  if (true) { // violation
78                  } else {
79                  }
80              } else
81                  if (false) {
82                  }
83                  else System.out.println();
84          } else
85              if (true) {
86                  if (true) {
87                  } else System.out.println();
88              } else
89                  if (false) {
90                  } else System.out.println();
91      }
92  
93       public void test6() {
94           byte tmpByte[];
95  
96           if (true) {
97                   if (true) {
98                       tmpByte = new byte[0];
99                   }
100          } else {
101              if (true) {
102                  if (true) { // violation 'Nested if-else depth is 2 (max allowed is 1)'
103                      tmpByte = new byte[1];
104                  }
105              }
106              if (false) {
107                  if (true) { // violation 'Nested if-else depth is 2 (max allowed is 1)'
108                      tmpByte = new byte[2];
109                  }
110              }
111          }
112      }
113 }