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