ClassMetrics extends AbstractNamedMetrics { public static ClassMetrics create( final String packageFullName, final File fileInPackage, final InternalFunctionMetrics functionMetrics, final IClass classNode, final IFlexFile file, final double mxmlFactor ) { final int average = classNode == null ? 0 : ( int ) Math.round( classNode.getAverageCyclomaticComplexity() ); final int asDocs = ( classNode == null || classNode.getAsDoc() == null ? 0 : MetricUtils.computeNbOfLines( classNode.getAsDoc() .getStringValue() ) ) + ( functionMetrics == null ? 0 : functionMetrics.getAsDocsInClass() ); final int multiLineComments = ( classNode == null ? 0 : MetricUtils.computeMultiLineComments( classNode ) ) + ( functionMetrics == null ? 0 : functionMetrics.getMultipleLineCommentInClass() ); final int nonCommentStatements = computeStatements( functionMetrics, file, mxmlFactor ); return new ClassMetrics( nonCommentStatements, classNode == null ? 0 : classNode.getFunctions().size(), fileInPackage.getName().replace( ".as", "" ).replace( ".mxml", "" ), packageFullName, average, asDocs, multiLineComments, classNode ); } private  ClassMetrics( final int nonCommentStatements,
                         final int functionsToBeSet,
                         final String name,
                         final String packageName,
                         final int ccn,
                         final int asDocs,
                         final int multiLineCommentsToBeSet,
                         final IClass classNodeToBeSet ); static ClassMetrics create( final String packageFullName,
                                      final File fileInPackage,
                                      final InternalFunctionMetrics functionMetrics,
                                      final IClass classNode,
                                      final IFlexFile file,
                                      final double mxmlFactor ); String getContreteXml(); @Override String getFullName(); int getFunctions(); @Override String getMetricsName();  }
@Test public void testBug157() throws PMDException { final IFlexFile file = getTestFiles().get( "bug.FlexPMD157.as" ); final IParserNode ast = FileSetUtils.buildAst( file ); final IClass classNode = NodeFactory.createPackage( ast ).getClassNode(); final ClassMetrics classMetrics = ClassMetrics.create( "bug", new File( file.getFilePath() ), InternalFunctionMetrics.create( new ProjectMetrics(), file.getFullyQualifiedName(), classNode ), classNode, file, 0 ); assertEquals( "<object><name>bug.FlexPMD157</name><ccn>0</ccn><ncss>3</ncss><javadocs>0</javadocs>" + "<javadoc_lines>0</javadoc_lines><multi_comment_lines>0</multi_comment_lines>" + "<single_comment_lines>0</single_comment_lines><functions>0</functions></object>", classMetrics.toXmlString() ); }
@Test public void testBug181() throws PMDException { final IFlexFile file = getTestFiles().get( "bug.FlexPMD181.as" ); final IParserNode ast = FileSetUtils.buildAst( file ); final IClass classNode = NodeFactory.createPackage( ast ).getClassNode(); final ClassMetrics classMetrics = ClassMetrics.create( "bug", new File( file.getFilePath() ), InternalFunctionMetrics.create( new ProjectMetrics(), file.getFullyQualifiedName(), classNode ), classNode, file, 0 ); assertEquals( "<object><name>bug.FlexPMD181</name><ccn>3</ccn><ncss>379</ncss><javadocs>1403" + "</javadocs><javadoc_lines>1403</javadoc_lines><multi_comment_lines>4" + "</multi_comment_lines><single_comment_lines>0</single_comment_lines>" + "<functions>81</functions></object>", classMetrics.toXmlString() ); }
@Test public void testBug232() throws PMDException { final IFlexFile file = getTestFiles().get( "bug.FlexPMD232.as" ); final IParserNode ast = FileSetUtils.buildAst( file ); final IClass classNode = NodeFactory.createPackage( ast ).getClassNode(); final ClassMetrics classMetrics = ClassMetrics.create( "bug", new File( file.getFilePath() ), InternalFunctionMetrics.create( new ProjectMetrics(), file.getFullyQualifiedName(), classNode ), classNode, file, 0 ); assertEquals( "<object><name>bug.FlexPMD232</name><ccn>4</ccn><ncss>7</ncss><javadocs>0</javadocs>" + "<javadoc_lines>0</javadoc_lines><multi_comment_lines>0</multi_comment_lines>" + "<single_comment_lines>0</single_comment_lines><functions>1</functions></object>", classMetrics.toXmlString() ); }
@Test public void testBug233() throws PMDException { final IFlexFile file = getTestFiles().get( "bug.Duane.mxml" ); final IParserNode ast = FileSetUtils.buildAst( file ); final IClass classNode = NodeFactory.createPackage( ast ).getClassNode(); final ClassMetrics classMetrics = ClassMetrics.create( "bug", new File( file.getFilePath() ), InternalFunctionMetrics.create( new ProjectMetrics(), file.getFullyQualifiedName(), classNode ), classNode, file, 1 ); assertEquals( "<object><name>bug.Duane</name><ccn>1</ccn><ncss>217</ncss><javadocs>0</javadocs>" + "<javadoc_lines>0</javadoc_lines><multi_comment_lines>0</multi_comment_lines>" + "<single_comment_lines>0</single_comment_lines><functions>8</functions></object>", classMetrics.toXmlString() ); }
@Test public void testToXmlString() throws PMDException { final IFlexFile file = getTestFiles().get( "RadonDataGrid.as" ); final IParserNode ast = FileSetUtils.buildAst( file ); final IClass classNode = NodeFactory.createPackage( ast ).getClassNode(); final ClassMetrics classMetrics = ClassMetrics.create( "com.adobe.ac", new File( file.getFilePath() ), InternalFunctionMetrics.create( new ProjectMetrics(), file.getFullyQualifiedName(), classNode ), classNode, file, 0 ); assertEquals( "<object><name>com.adobe.ac.RadonDataGrid</name><ccn>3</ccn><ncss>87</ncss><javadocs>0</javadocs>" + "<javadoc_lines>0</javadoc_lines><multi_comment_lines>0</multi_comment_lines>" + "<single_comment_lines>0</single_comment_lines><functions>7</functions></object>", classMetrics.toXmlString() ); }
@Test public void testToXmlStringWithMultiLineComments() throws PMDException { final IFlexFile file = getTestFiles().get( "bug.FlexPMD60.as" ); final IParserNode ast = FileSetUtils.buildAst( file ); final IClass classNode = NodeFactory.createPackage( ast ).getClassNode(); final ClassMetrics classMetrics = ClassMetrics.create( "bug", new File( file.getFilePath() ), InternalFunctionMetrics.create( new ProjectMetrics(), file.getFullyQualifiedName(), classNode ), classNode, file, 0 ); assertEquals( "<object><name>bug.FlexPMD60</name><ccn>1</ccn><ncss>4</ncss><javadocs>9</javadocs>" + "<javadoc_lines>9</javadoc_lines><multi_comment_lines>7</multi_comment_lines>" + "<single_comment_lines>0</single_comment_lines><functions>1</functions></object>", classMetrics.toXmlString() ); }