[LL] Implement a common LLSealedInheritorsProvider

- The new `LLSealedInheritorsProvider` is based on the previous
  sealed inheritors provider implementation in the IDE. It uses the
  new direct inheritors provider and the module dependents provider to
  implement the same functionality that was previously confined to the
  IDE. With this design we avoid duplication of complex logic such as
  the KMP handling in `searchInheritors`.
- The implementation is designed to work in the production Standalone
  mode and the aforementioned services have already been implemented for
  Standalone in prior commits. Now we can get rid of the problematic
  `SealedClassInheritorsProviderForTests` and tests should more closely
  match production behavior.
- In IDE mode tests, `LLSealedInheritorsProvider` is used with
  Standalone Analysis API provider implementations. This is in line with
  the rest of the test infrastructure, where Standalone AA providers are
  generally used, as IDE providers aren't available.
- `KotlinSealedInheritorsProvider` is made obsolete by the common sealed
  inheritors provider.

^KT-66013 fixed
^KT-64505 fixed
This commit is contained in:
Marco Pennekamp
2024-02-28 21:35:59 +01:00
committed by Space Team
parent 48229f7faa
commit 1374bc8e2d
20 changed files with 123 additions and 296 deletions
@@ -1,36 +0,0 @@
/*
* 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 org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.psi.KtClass
/**
* [KotlinSealedInheritorsProvider] provides a list of direct inheritors for sealed [KtClass]es (which may be a class or an interface). It
* may be created with [KotlinSealedInheritorsProviderFactory].
*
* Implementations of this service should consider caching the results. The [KotlinSealedInheritorsProvider] is tied to the lifetime of its
* owning session, so it will be invalidated automatically with the session.
*/
public interface KotlinSealedInheritorsProvider {
/**
* Returns the sealed inheritors of [ktClass], which may be a class or an interface. [ktClass] is guaranteed to be sealed.
*/
public fun getSealedInheritors(ktClass: KtClass): List<ClassId>
}
public interface KotlinSealedInheritorsProviderFactory {
/**
* Creates a [KotlinSealedInheritorsProvider] for a session.
*/
public fun createSealedInheritorsProvider(): KotlinSealedInheritorsProvider
public companion object {
public fun getInstance(project: Project): KotlinSealedInheritorsProviderFactory? =
project.getService(KotlinSealedInheritorsProviderFactory::class.java)
}
}