From 31a65871f284b78da67492130d0a3c821e8bf1db Mon Sep 17 00:00:00 2001 From: Marco Pennekamp Date: Wed, 28 Feb 2024 21:01:12 +0100 Subject: [PATCH] [AA] Add `KotlinDirectInheritorsProvider` - Direct inheritors are needed to calculate sealed inheritors. The new `KotlinDirectInheritorsProvider` can be used to implement a common sealed inheritors provider in LL FIR. ^KT-66013 --- .../KotlinDirectInheritorsProvider.kt | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 analysis/analysis-api-providers/src/org/jetbrains/kotlin/analysis/providers/KotlinDirectInheritorsProvider.kt diff --git a/analysis/analysis-api-providers/src/org/jetbrains/kotlin/analysis/providers/KotlinDirectInheritorsProvider.kt b/analysis/analysis-api-providers/src/org/jetbrains/kotlin/analysis/providers/KotlinDirectInheritorsProvider.kt new file mode 100644 index 00000000000..bf42ae6ab39 --- /dev/null +++ b/analysis/analysis-api-providers/src/org/jetbrains/kotlin/analysis/providers/KotlinDirectInheritorsProvider.kt @@ -0,0 +1,32 @@ +/* + * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.analysis.providers + +import com.intellij.openapi.project.Project +import com.intellij.psi.search.GlobalSearchScope +import org.jetbrains.kotlin.psi.KtClass +import org.jetbrains.kotlin.psi.KtClassOrObject + +public interface KotlinDirectInheritorsProvider { + /** + * Returns all direct inheritors of [ktClass] that can be found in the given [scope]. If [includeLocalInheritors] is `false`, only + * non-local inheritors will be returned. + * + * The implementor of [getDirectKotlinInheritors] is allowed to lazy-resolve symbols up to the `SUPER_TYPES` phase. This is required to + * check subtyping for potential inheritors. Hence, if [getDirectKotlinInheritors] is invoked during lazy resolution, it requires a + * phase of `SEALED_CLASS_INHERITORS` or later. + */ + public fun getDirectKotlinInheritors( + ktClass: KtClass, + scope: GlobalSearchScope, + includeLocalInheritors: Boolean + ): Iterable + + public companion object { + public fun getInstance(project: Project): KotlinDirectInheritorsProvider = + project.getService(KotlinDirectInheritorsProvider::class.java) + } +}