From de81d39bc1c5af09e59b7159bbabcb5b3dbc8c57 Mon Sep 17 00:00:00 2001 From: Vladimir Dolzhenko Date: Tue, 14 Oct 2025 09:11:21 +0200 Subject: [PATCH] [kotlin] KTIJ-34510 Fix file level highlighting check (cherry picked from commit 90beb591188217cb36904e85dee95f19ebf27b5f) GitOrigin-RevId: 5b8e463a80fa7a84cd2f90aae01c3ddca6140449 --- .../kotlin/idea/codeMetaInfo/models/CodeMetaInfo.kt | 10 ++++++++-- ...PackageDirectoryFileLevelProblem.kt.highlighting.k2 | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/codeMetaInfo/models/CodeMetaInfo.kt b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/codeMetaInfo/models/CodeMetaInfo.kt index f02720921411..02f0e5fd8901 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/codeMetaInfo/models/CodeMetaInfo.kt +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/codeMetaInfo/models/CodeMetaInfo.kt @@ -112,8 +112,14 @@ fun createCodeMetaInfo(obj: Any, renderConfiguration: AbstractCodeMetaInfoRender } is HighlightInfo -> { val codeMetaInfo: CodeMetaInfo = when(renderConfiguration) { - is HighlightingConfiguration -> HighlightingCodeMetaInfo(renderConfiguration, obj) - is FileLevelHighlightingConfiguration -> FileLevelHighlightingCodeMetaInfo(renderConfiguration, obj) + is HighlightingConfiguration -> { + if (obj.isFileLevelAnnotation) return emptyList() + HighlightingCodeMetaInfo(renderConfiguration, obj) + } + is FileLevelHighlightingConfiguration -> { + if (!obj.isFileLevelAnnotation) return emptyList() + FileLevelHighlightingCodeMetaInfo(renderConfiguration, obj) + } else -> error(errorMessage()) } diff --git a/plugins/kotlin/idea/tests/testData/highlighterMetaInfo/mismatchPackageDirectoryFileLevelProblem.kt.highlighting.k2 b/plugins/kotlin/idea/tests/testData/highlighterMetaInfo/mismatchPackageDirectoryFileLevelProblem.kt.highlighting.k2 index 243370ba36f1..21d500867625 100644 --- a/plugins/kotlin/idea/tests/testData/highlighterMetaInfo/mismatchPackageDirectoryFileLevelProblem.kt.highlighting.k2 +++ b/plugins/kotlin/idea/tests/testData/highlighterMetaInfo/mismatchPackageDirectoryFileLevelProblem.kt.highlighting.k2 @@ -1,4 +1,4 @@ -x +x // TOOL: org.jetbrains.kotlin.idea.k2.codeinsight.inspections.PackageDirectoryMismatchInspection // IGNORE_K1 // IMPLICIT_PACKAGE_PREFIX: "foo"