Source source = getSource();
for (int line = 1; line <= source.getNumberOfLines(); line++) {
- int linesOfCode = source.getMeasure(Metric.LINES_OF_CODE, line, line);
- measures.setIntValue(CoreMetrics.NCLOC_DATA_KEY, line, linesOfCode);
+ int lineOfCode = source.getMeasure(Metric.LINES_OF_CODE, line, line);
+ measures.setIntValue(CoreMetrics.NCLOC_DATA_KEY, line, lineOfCode);
+
+ int comment = source.getMeasure(Metric.COMMENT_LINES, line, line);
+ measures.setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, line, comment);
}
measures.save();
}
verify(measures).setIntValue(CoreMetrics.NCLOC_DATA_KEY, 1, 1);
verify(measures).setIntValue(CoreMetrics.NCLOC_DATA_KEY, 2, 0);
verify(measures).setIntValue(CoreMetrics.NCLOC_DATA_KEY, 3, 1);
+
+ verify(measures).setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, 1, 0);
+ verify(measures).setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, 18, 1);
+
verify(measures).save();
}
public static final String NCLOC_DATA_KEY = "ncloc_data";
/**
+ * Information about lines of code in file.
+ * Key-value pairs, where key - is a number of line, and value - is an indicator of whether line contains code (1) or not (0).
+ *
+ * @see org.sonar.api.measures.FileLinesContext
* @since 2.14
*/
@Beta
.setDomain(DOMAIN_SIZE)
.create();
+ /**
+ * @since 2.14
+ */
+ @Beta
+ public static final String COMMENT_LINES_DATA_KEY = "comment_lines_data";
+
+ /**
+ * Information about comments in file.
+ * Key-value pairs, where key - is a number of line, and value - is an indicator of whether line contains comment (1) or not (0).
+ *
+ * @see org.sonar.api.measures.FileLinesContext
+ * @since 2.14
+ */
+ @Beta
+ public static final Metric COMMENT_LINES_DATA = new Metric.Builder(COMMENT_LINES_DATA_KEY, "comment_lines_data", Metric.ValueType.DATA)
+ .setHidden(true)
+ .setDomain(DOMAIN_DOCUMENTATION)
+ .create();
+
//--------------------------------------------------------------------------------------------------------------------
//
// OTHERS