From ade3723be128bc20ed63b1fff8ac3f596c0fc0e5 Mon Sep 17 00:00:00 2001 From: "alexey.afanasiev" Date: Mon, 30 Oct 2023 23:51:31 +0100 Subject: [PATCH] QD-7556 Fix ancestor calculation for groups GitOrigin-RevId: c58c27f3f5e16e5aa0774b1831dc89f4f4446103 --- .../InspectionCategoryGroupProvider.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/platform/inspect/src/com/intellij/codeInspection/inspectionProfile/InspectionCategoryGroupProvider.kt b/platform/inspect/src/com/intellij/codeInspection/inspectionProfile/InspectionCategoryGroupProvider.kt index 98d23bd1c854..52acf50e50fd 100644 --- a/platform/inspect/src/com/intellij/codeInspection/inspectionProfile/InspectionCategoryGroupProvider.kt +++ b/platform/inspect/src/com/intellij/codeInspection/inspectionProfile/InspectionCategoryGroupProvider.kt @@ -16,7 +16,7 @@ class InspectionCategoryGroupProvider : InspectionGroupProvider { override fun includesInspection(tool: InspectionToolWrapper<*, *>): Boolean { return try { - tool.groupPath.makeCategoryId().startsWith(category) + category.isAncestor(tool.groupPath.makeCategoryId()) } catch (e: AssertionError) { false @@ -26,8 +26,15 @@ class InspectionCategoryGroupProvider : InspectionGroupProvider { } } +private fun String.isAncestor(categoryId: String): Boolean { + if (this.isEmpty() || categoryId.isEmpty()) return false + val normalizedAncestor = this.removeSuffix("/") + "/" + val normalizedCategoryId = categoryId.removeSuffix("/") + "/" + return normalizedCategoryId.startsWith(normalizedAncestor) +} + fun Array.makeCategoryId(): String { - return map { escapeToolGroupPathElement(it) }.joinToString("/") + return joinToString("/") { escapeToolGroupPathElement(it) } } fun escapeToolGroupPathElement(path: String): String {