View Javadoc
1   /*
2   NPathComplexity
3   max = 20
4   
5   
6   */
7   
8   package com.puppycrawl.tools.checkstyle.checks.metrics.npathcomplexity;
9   
10  public class InputNPathComplexityCheckCount{
11      public void method() { // violation 'NPath Complexity is 30 (max allowed is 20)'
12          try {}
13          catch (IllegalArgumentException ex) {}
14          try {}
15          catch (IllegalArgumentException ex) {}
16          try {}
17          catch (IllegalArgumentException ex) {}
18          try {}
19          catch (IllegalArgumentException ex) {}
20      }
21  
22      int method2() throws InterruptedException {
23          // violation above 'NPath Complexity is 72 (max allowed is 20)'
24          int x = 1;
25          int a = 2;
26          while (true) {
27              try {
28                  if (x > 0) {
29                      break;
30                  } else if (x < 0) {
31                      ;
32                  } else {
33                      break;
34                  }
35                  switch (a)
36                  {
37                  case 0:
38                      break;
39                  default:
40                      break;
41                  }
42              }
43              catch (Exception e)
44              {
45                  break;
46              }
47          }
48  
49          synchronized (this) {
50              do {
51                  x = 2;
52              } while (x == 2);
53          }
54  
55          this.wait(666);
56  
57          for (int k = 0; k < 1; k++) {
58              String innerBlockVariable = "";
59          }
60  
61          if (System.currentTimeMillis() > 1000)
62              return 1;
63          else
64              return 2;
65      }
66  
67      void method3(char c, int i) { // violation 'NPath Complexity is 23 (max allowed is 20)'
68          while (true) {
69              switch (c) {
70              case 'a':
71              case 'b':
72                  i++;
73              case 'c':
74                  break;
75              case 'd':
76                  return;
77              case 'e':
78                  continue;
79              case 'f':
80                  if (true) return;
81              case 'g':
82                  try {
83                      i++;
84                      break;
85                  } catch (RuntimeException e) {
86                  } catch (Error e) {
87                      return;
88                  }
89              case 'h':
90                  switch (i) {
91                  case 1:
92                      continue;
93                  case 2:
94                      i++;
95                  case 3:
96                      return;
97                  }
98              case 'i':
99                  switch (i) {
100                 case 1:
101                     continue;
102                 case 2:
103                     i++;
104                     break;
105                 case 3:
106                     return;
107                 }
108                 break;
109             case 'A':
110                 i++;
111             case 'B':
112                 i++;
113             default:
114                 i++;
115                 break;
116             }
117         }
118     }
119 }