Search in sources :

Example 1 with MetricStorage

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;
}
Also used : Path(java.nio.file.Path) FileInfo(com.github._1c_syntax.bsl.languageserver.reporters.data.FileInfo) AbstractMDObjectBase(com.github._1c_syntax.mdclasses.mdo.AbstractMDObjectBase) MetricStorage(com.github._1c_syntax.bsl.languageserver.context.MetricStorage) Diagnostic(org.eclipse.lsp4j.Diagnostic) IOException(java.io.IOException) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext)

Example 2 with MetricStorage

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();
}
Also used : MetricStorage(com.github._1c_syntax.bsl.languageserver.context.MetricStorage) FileLinesContext(org.sonar.api.measures.FileLinesContext)

Aggregations

MetricStorage (com.github._1c_syntax.bsl.languageserver.context.MetricStorage)2 DocumentContext (com.github._1c_syntax.bsl.languageserver.context.DocumentContext)1 FileInfo (com.github._1c_syntax.bsl.languageserver.reporters.data.FileInfo)1 AbstractMDObjectBase (com.github._1c_syntax.mdclasses.mdo.AbstractMDObjectBase)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Diagnostic (org.eclipse.lsp4j.Diagnostic)1 FileLinesContext (org.sonar.api.measures.FileLinesContext)1