1 /* 2 JavaNCSS 3 methodMaximum = 0 4 classMaximum = 1 5 fileMaximum = 2 6 recordMaximum = (default)150 7 8 9 */ 10 11 // should give an ncss of 35 12 package com.puppycrawl.tools.checkstyle.checks.metrics.javancss; // violation 'NCSS for this file is 39 (max allowed is 2).' 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 InputJavaNCSS { // violation 'NCSS for this class is 22 (max allowed is 1).' 20 21 private Object mObject; 22 23 //should count as 2 24 private void testMethod1() { // violation 'NCSS for this method is 2 (max allowed is 0).' 25 26 //should count as 1 27 int x = 1, y = 2; 28 } 29 30 //should count as 4 31 private void testMethod2() { // violation 'NCSS for this method is 4 (max allowed is 0).' 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() { // violation 'NCSS for this method is 12 (max allowed is 0).' 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) { // violation '.* is 2 (max allowed is 0).' 53 System.identityHashCode("Hello"); 54 } 55 }; 56 } 57 58 //should give an ncss of 2 59 private class TestInnerClass { // violation 'NCSS for this class is 2 (max allowed is 1).' 60 61 private Object test; 62 } 63 } 64 65 //should give an ncss of 10 66 class TestTopLevelNestedClass { // violation 'NCSS for this class is 10 (max allowed is 1).' 67 68 private Object mObject; 69 70 //should give an ncss of 8 71 private void testMethod() { // violation 'NCSS for this method is 8 (max allowed is 0).' 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 Input0 { // violation 'NCSS for this class is 4 (max allowed is 1).' 91 static { } // violation 'NCSS for this method is 1 (max allowed is 0).' 92 { } // violation 'NCSS for this method is 1 (max allowed is 0).' 93 public Input0() { } // violation 'NCSS for this method is 1 (max allowed is 0).' 94 }