File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed
utbot-framework/src/main/kotlin/org/utbot/sarif Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -99,7 +99,17 @@ data class SarifResult(
99
99
val locations : List <SarifPhysicalLocationWrapper > = listOf(),
100
100
val relatedLocations : List <SarifRelatedPhysicalLocationWrapper > = listOf(),
101
101
val codeFlows : List <SarifCodeFlow > = listOf()
102
- )
102
+ ) {
103
+ /* *
104
+ * Returns the total number of locations in all [codeFlows].
105
+ */
106
+ fun totalCodeFlowLocations () =
107
+ codeFlows.sumBy { codeFlow ->
108
+ codeFlow.threadFlows.sumBy { threadFlow ->
109
+ threadFlow.locations.size
110
+ }
111
+ }
112
+ }
103
113
104
114
/* *
105
115
* The severity of the result. "Error" for detected unchecked exceptions.
Original file line number Diff line number Diff line change @@ -90,11 +90,25 @@ class SarifReport(
90
90
return Sarif .fromRun(
91
91
SarifRun (
92
92
SarifTool .fromRules(sarifRules.toList()),
93
- sarifResults
93
+ minimizeResults( sarifResults)
94
94
)
95
95
)
96
96
}
97
97
98
+ /* *
99
+ * Minimizes detected errors and removes duplicates.
100
+ * Between two [SarifResult]s with the same `ruleId` and `locations`
101
+ * it chooses the one with the shorter length of the execution trace.
102
+ */
103
+ private fun minimizeResults (sarifResults : List <SarifResult >): List <SarifResult > =
104
+ sarifResults.groupBy { sarifResult ->
105
+ Pair (sarifResult.ruleId, sarifResult.locations)
106
+ }.map { (_, sarifResultsGroup) ->
107
+ sarifResultsGroup.minByOrNull { sarifResult ->
108
+ sarifResult.totalCodeFlowLocations()
109
+ }!!
110
+ }
111
+
98
112
private fun processUncheckedException (
99
113
method : UtMethod <* >,
100
114
utExecution : UtExecution ,
You can’t perform that action at this time.
0 commit comments