use of com.github._1c_syntax.bsl.languageserver.context.MetricStorage in project bsl-language-server by 1c-syntax.
the class AnalyzeCommand method getFileInfoFromFile.
private FileInfo getFileInfoFromFile(Path srcDir, File file) {
String textDocumentContent;
try {
textDocumentContent = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
} catch (IOException e) {
throw new RuntimeException(e);
}
DocumentContext documentContext = context.addDocument(file.toURI(), textDocumentContent, 1);
Path filePath = srcDir.relativize(Absolute.path(file));
List<Diagnostic> diagnostics = documentContext.getDiagnostics();
MetricStorage metrics = documentContext.getMetrics();
String mdoRef = "";
Optional<AbstractMDObjectBase> mdObjectBase = documentContext.getMdObject();
if (mdObjectBase.isPresent()) {
mdoRef = mdObjectBase.get().getMdoReference().getMdoRef();
}
FileInfo fileInfo = new FileInfo(filePath, mdoRef, diagnostics, metrics);
// clean up AST after diagnostic computing to free up RAM.
documentContext.clearSecondaryData();
return fileInfo;
}
use of com.github._1c_syntax.bsl.languageserver.context.MetricStorage in project sonar-bsl-plugin-community by 1c-syntax.
the class BSLCoreSensor method saveMeasures.
private void saveMeasures(InputFile inputFile, DocumentContext documentContext) {
MetricStorage metrics = documentContext.getMetrics();
context.<Integer>newMeasure().on(inputFile).forMetric(CoreMetrics.NCLOC).withValue(metrics.getNcloc()).save();
context.<Integer>newMeasure().on(inputFile).forMetric(CoreMetrics.STATEMENTS).withValue(metrics.getStatements()).save();
context.<Integer>newMeasure().on(inputFile).forMetric(CoreMetrics.FUNCTIONS).withValue(metrics.getProcedures() + metrics.getFunctions()).save();
context.<Integer>newMeasure().on(inputFile).forMetric(CoreMetrics.COGNITIVE_COMPLEXITY).withValue(metrics.getCognitiveComplexity()).save();
context.<Integer>newMeasure().on(inputFile).forMetric(CoreMetrics.COMPLEXITY).withValue(metrics.getCyclomaticComplexity()).save();
context.<Integer>newMeasure().on(inputFile).forMetric(CoreMetrics.COMMENT_LINES).withValue(metrics.getComments()).save();
FileLinesContext fileLinesContext = fileLinesContextFactory.createFor(inputFile);
for (int line : metrics.getNclocData()) {
fileLinesContext.setIntValue(CoreMetrics.NCLOC_DATA_KEY, line, 1);
}
fileLinesContext.save();
}
Aggregations