KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > metrics > JavaNCSSCheckTestInput


1 // should give an ncss of 35
2
package com.puppycrawl.tools.checkstyle.metrics;
3
4 import java.awt.event.ItemEvent JavaDoc;
5 import java.awt.event.ItemListener JavaDoc;
6
7
8 //should give an ncss of 22
9
public class JavaNCSSCheckTestInput {
10     
11     private Object JavaDoc 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.out.println("Hello"); break;
36             default: break;
37         }
38         
39         ItemListener JavaDoc lis = new ItemListener JavaDoc() {
40
41             //should give an ncss of 2
42
public void itemStateChanged(ItemEvent JavaDoc e) {
43                 System.out.println("Hello");
44             }
45         };
46     }
47     
48     //should give an ncss of 2
49
private class TestInnerClass {
50         
51         private Object JavaDoc test;
52     }
53 }
54
55 //should give an ncss of 10
56
class TestTopLevelNestedClass {
57     
58     private Object JavaDoc 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
Popular Tags