@Test public void comment_lines() throws Exception { CommentLineVisitor comment = new CommentLineVisitor(parse("metrics/comments.php")); assertThat(comment.commentLineNumber()).isEqualTo(3); assertThat(comment.commentLines()).contains(3, 7, 11); assertThat(comment.noSonarLines()).containsOnly(14); }
private void setLineAndCommentMeasures() { LineVisitor lineVisitor = new LineVisitor(context().tree()); CommentLineVisitor commentVisitor = new CommentLineVisitor(context().tree()); int linesNumber = lineVisitor.getLinesNumber(); fileMeasures.setLinesNumber(linesNumber); fileMeasures.setLinesOfCodeNumber(lineVisitor.getLinesOfCodeNumber()); fileMeasures.setCommentLinesNumber(commentVisitor.commentLineNumber()); fileMeasures.setNoSonarLines(commentVisitor.noSonarLines()); Set<Integer> linesOfCode = lineVisitor.getLinesOfCode(); Set<Integer> commentLines = commentVisitor.commentLines(); for (int line = 1; line <= linesNumber; line++) { fileLinesContext.setIntValue( CoreMetrics.NCLOC_DATA_KEY, line, linesOfCode.contains(line) ? 1 : 0); fileLinesContext.setIntValue( CoreMetrics.COMMENT_LINES_DATA_KEY, line, commentLines.contains(line) ? 1 : 0); } fileLinesContext.save(); }