1   // should give an ncss of 35
2   package com.puppycrawl.tools.checkstyle.checks.metrics.javancss;
3   
4   import java.awt.event.ItemEvent;
5   import java.awt.event.ItemListener;
6   
7   
8   //should give an ncss of 22
9   public class InputJavaNCSS {
10      
11      private Object mObject;
12      
13      //should count as 2
14      private void testMethod1() {
15          
16          //should count as 1
17          int x = 1, y = 2;
18      }
19      
20      //should count as 4
21      private void testMethod2() {
22          
23          int abc = 0;
24          
25          //should count as 2
26          testLabel: abc = 1;  
27      }    
28       
29      //should give an ncss of 12
30      private void testMethod3() {
31          
32          int a = 0;
33          switch (a) {
34              case 1: //falls through
35              case 2: System.identityHashCode("Hello"); break;
36              default: break;
37          }
38          
39          ItemListener lis = new ItemListener() {
40  
41              //should give an ncss of 2
42              public void itemStateChanged(ItemEvent e) {          
43                  System.identityHashCode("Hello");
44              }
45          };  
46      }
47      
48      //should give an ncss of 2
49      private class TestInnerClass {
50          
51          private Object test;
52      } 
53  }
54  
55  //should give an ncss of 10
56  class TestTopLevelNestedClass {
57      
58      private Object mObject;
59      
60      //should give an ncss of 8
61      private void testMethod() {
62          
63          for (int i=0; i<10; i++) {
64              
65              if (i==0) {
66                  
67                  //should count as 1
68                  int x = 1, y = 2;
69              }
70              else {
71                  int abc = 0;
72                  
73                  //should count as 2
74                  testLabel: abc = 1;      
75              }
76          }
77      }
78  }
79  
80  class Input0 {
81      static { }
82      { }
83      public Input0() { }
84  }