From 150686e456f6e69701995d37492e104065663a36 Mon Sep 17 00:00:00 2001 From: Akash Yadav Date: Tue, 10 Nov 2026 14:23:16 +0000 Subject: [PATCH] Add patch to let embedders search only the sealed class's package for inheritors --- ...rs-search-only-the-sealed-class-s-pa.patch | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 patches/0012-feat-let-embedders-search-only-the-sealed-class-s-pa.patch diff --git a/patches/0012-feat-let-embedders-search-only-the-sealed-class-s-pa.patch b/patches/0012-feat-let-embedders-search-only-the-sealed-class-s-pa.patch new file mode 100644 index 0000000..39ea6a7 --- /dev/null +++ b/patches/0012-feat-let-embedders-search-only-the-sealed-class-s-pa.patch @@ -0,0 +1,64 @@ +From f000c3fc39450cec9eb35426bbf608534649aab4 Mon Sep 17 00:00:00 2001 +From: Akash Yadav +Date: Tue, 10 Nov 2026 14:23:08 +0000 +Subject: [PATCH] feat: let embedders search only the sealed class's package + for inheritors + +--- + .../KotlinDirectInheritorsProvider.kt | 17 +++++++++++++++++ + .../fir/providers/LLSealedInheritorsProvider.kt | 7 +++---- + 2 files changed, 20 insertions(+), 4 deletions(-) + +diff --git a/analysis/analysis-api-platform-interface/src/org/jetbrains/kotlin/analysis/api/platform/declarations/KotlinDirectInheritorsProvider.kt b/analysis/analysis-api-platform-interface/src/org/jetbrains/kotlin/analysis/api/platform/declarations/KotlinDirectInheritorsProvider.kt +index a3eff7054e20..7092f44b4dd9 100644 +--- a/analysis/analysis-api-platform-interface/src/org/jetbrains/kotlin/analysis/api/platform/declarations/KotlinDirectInheritorsProvider.kt ++++ b/analysis/analysis-api-platform-interface/src/org/jetbrains/kotlin/analysis/api/platform/declarations/KotlinDirectInheritorsProvider.kt +@@ -33,6 +33,23 @@ public interface KotlinDirectInheritorsProvider : KotlinPlatformComponent { + includeLocalInheritors: Boolean = true, + ): Iterable + ++ /** ++ * Returns the direct *Kotlin* inheritors of [ktClass] in [scope] that are declared in the same package as [ktClass]. ++ * ++ * Sealed class inheritors must share the sealed class's package, so this is all the sealed inheritors search needs. The default ++ * filters [getDirectKotlinInheritors]; an implementation that can search a single package should override it. The contract of ++ * [getDirectKotlinInheritors] applies otherwise. ++ */ ++ public fun getSamePackageDirectKotlinInheritors( ++ ktClass: KtClass, ++ scope: GlobalSearchScope, ++ includeLocalInheritors: Boolean = true, ++ ): Iterable { ++ val packageFqName = ktClass.containingKtFile.packageFqName ++ return getDirectKotlinInheritors(ktClass, scope, includeLocalInheritors) ++ .filter { it.containingKtFile.packageFqName == packageFqName } ++ } ++ + public companion object { + public fun getInstance(project: Project): KotlinDirectInheritorsProvider = project.service() + } +diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/providers/LLSealedInheritorsProvider.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/providers/LLSealedInheritorsProvider.kt +index f69568a842f8..951671ab38db 100644 +--- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/providers/LLSealedInheritorsProvider.kt ++++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/providers/LLSealedInheritorsProvider.kt +@@ -95,14 +95,13 @@ internal class LLSealedInheritorsProvider(private val project: Project) : Sealed + targetModule.contentScope + } + +- return searchInScope(targetKtClass, targetFirClass.classId, scope) ++ return searchInScope(targetKtClass, scope) + } + +- private fun searchInScope(ktClass: KtClass, classId: ClassId, scope: GlobalSearchScope): List = ++ private fun searchInScope(ktClass: KtClass, scope: GlobalSearchScope): List = + KotlinDirectInheritorsProvider.getInstance(project) +- .getDirectKotlinInheritors(ktClass, scope, includeLocalInheritors = false) ++ .getSamePackageDirectKotlinInheritors(ktClass, scope, includeLocalInheritors = false) + .mapNotNull { it.getClassId() } +- .filter { it.packageFqName == classId.packageFqName } + // Enforce a deterministic order on the result, e.g. for stable test output. + .sortedBy { it.toString() } + .ifEmpty { emptyList() } +-- +2.53.0 +