From b921e2699a517a35140aef55b41f4596433ef9dc Mon Sep 17 00:00:00 2001 From: Nikita Stroganov Date: Tue, 21 Mar 2023 11:46:00 +0300 Subject: [PATCH] Fix utbot inspection on inner classes --- .../src/main/kotlin/org/utbot/sarif/DataClasses.kt | 3 +++ .../src/main/kotlin/org/utbot/sarif/SarifReport.kt | 2 +- .../org/utbot/intellij/plugin/sarif/SarifReportIdea.kt | 5 +++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/utbot-framework/src/main/kotlin/org/utbot/sarif/DataClasses.kt b/utbot-framework/src/main/kotlin/org/utbot/sarif/DataClasses.kt index 2d4b2f0692..9731658270 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/sarif/DataClasses.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/sarif/DataClasses.kt @@ -47,6 +47,9 @@ data class Sarif( .writerWithDefaultPrettyPrinter() .writeValueAsString(this) + operator fun plus(other: Sarif): Sarif = + this.copy(runs = this.runs + other.runs) + @JsonIgnore fun getAllResults(): List = runs.flatMap { it.results } diff --git a/utbot-framework/src/main/kotlin/org/utbot/sarif/SarifReport.kt b/utbot-framework/src/main/kotlin/org/utbot/sarif/SarifReport.kt index 1df35ccd1e..99d807caf1 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/sarif/SarifReport.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/sarif/SarifReport.kt @@ -29,7 +29,7 @@ class SarifReport( */ fun mergeReports(reports: List): String = reports.fold(Sarif.empty()) { sarif: Sarif, report: String -> - sarif.copy(runs = sarif.runs + Sarif.fromJson(report).runs) + sarif + Sarif.fromJson(report) }.toJson() /** diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/sarif/SarifReportIdea.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/sarif/SarifReportIdea.kt index 86d56cc951..7a24088189 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/sarif/SarifReportIdea.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/sarif/SarifReportIdea.kt @@ -44,8 +44,9 @@ object SarifReportIdea { IntelliJApiHelper.run(IntelliJApiHelper.Target.THREAD_POOL, indicator, "Save SARIF report for ${classId.name}") { try { val sarifReportAsJson = proc.writeSarif(reportFilePath, testSetsId, generatedTestsCode, sourceFinding) - val sarifReport = Sarif.fromJson(sarifReportAsJson) - srcClassPathToSarifReport[srcClassPath] = sarifReport + val newSarifReport = Sarif.fromJson(sarifReportAsJson) + val oldSarifReport = srcClassPathToSarifReport[srcClassPath] ?: Sarif.empty() + srcClassPathToSarifReport[srcClassPath] = oldSarifReport + newSarifReport } catch (e: Exception) { logger.error { e } } finally {