[Kotlin] K/N forward declarations: cleanup

KTIJ-29679

GitOrigin-RevId: 9e53f6288ac371a7a13af055c651d76f27c4cd4e
This commit is contained in:
Pavel Kirpichenkov
2024-05-30 01:02:41 +00:00
committed by intellij-monorepo-bot
parent 29405e18ad
commit ebc215a944
6 changed files with 24 additions and 19 deletions
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.idea.base.projectStructure.KtNativeKlibLibraryModule
*
* @see [org.jetbrains.kotlin.idea.base.projectStructure.forwardDeclarations.KotlinForwardDeclarationsFileGenerator]
*/
class FirIdeForwardDeclarationProviderFactory : KotlinForwardDeclarationProviderFactory() {
internal class FirIdeForwardDeclarationProviderFactory : KotlinForwardDeclarationProviderFactory() {
override fun createDeclarationProvider(ktModule: KtModule): KotlinDeclarationProvider? {
if (ktModule !is KtNativeKlibLibraryModuleByModuleInfo) return null
@@ -32,7 +32,7 @@ class FirIdeForwardDeclarationProviderFactory : KotlinForwardDeclarationProvider
*
* @see [org.jetbrains.kotlin.idea.base.projectStructure.forwardDeclarations.KotlinForwardDeclarationsFileGenerator]
*/
class FirIdeForwardDeclarationPackageProviderFactory : KotlinForwardDeclarationsPackageProviderFactory() {
internal class FirIdeForwardDeclarationPackageProviderFactory : KotlinForwardDeclarationsPackageProviderFactory() {
override fun createPackageProvider(ktModule: KtModule): KotlinPackageProvider? {
if (ktModule !is KtNativeKlibLibraryModuleByModuleInfo) return null
@@ -2,7 +2,7 @@
package org.jetbrains.kotlin.idea.base.projectStructure.forwardDeclarations
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.util.registry.Registry
import com.intellij.openapi.vfs.VfsUtil
import org.jetbrains.kotlin.idea.base.projectStructure.moduleInfo.NativeKlibLibraryInfo
@@ -14,7 +14,7 @@ import java.io.File
import java.nio.file.Path
import kotlin.io.path.absolutePathString
private val LOG = Logger.getInstance(KotlinForwardDeclarationsFileGenerator::class.java)
private val LOG = logger<KotlinForwardDeclarationsFileGenerator>()
/**
* Generator of synthetic K/N forward declaration files.
@@ -27,11 +27,11 @@ private val LOG = Logger.getInstance(KotlinForwardDeclarationsFileGenerator::cla
* The generated declarations are grouped into files by package.
* The exact form of the declaration depends on the package, see [org.jetbrains.kotlin.name.NativeForwardDeclarationKind].
*
* @see
* [KotlinForwardDeclarationsWorkspaceEntity] workspace model entity for storing the information about the extra roots
* [KotlinForwardDeclarationsModelChangeService] service responsible for launching the generation
* See also:
* [KotlinForwardDeclarationsWorkspaceEntity] workspace model entity for storing the information about the extra roots.
* [KotlinForwardDeclarationsModelChangeService] service responsible for launching the generation.
*/
object KotlinForwardDeclarationsFileGenerator {
internal object KotlinForwardDeclarationsFileGenerator {
fun generateForwardDeclarationFiles(libraryInfo: NativeKlibLibraryInfo): Path? {
if (!Registry.`is`("kotlin.k2.kmp.enabled")) return null
@@ -41,8 +41,7 @@ object KotlinForwardDeclarationsFileGenerator {
private fun generateForwardDeclarationsForFqNames(groupedFqNames: Map<FqName, List<FqName>>, libraryPath: String): Path {
val root = KotlinForwardDeclarationsFileSystem.storageRootPath
val subPath = libraryPath.let { if (it.startsWith("/")) it.drop(1) else it }
val libraryLocation = root.resolve(subPath)
val libraryLocation = root.resolve(libraryPath.removePrefix("/"))
groupedFqNames.mapNotNull { (pkg, classes) ->
val kind = NativeForwardDeclarationKind.packageFqNameToKind[pkg] ?: run {
@@ -52,9 +51,9 @@ object KotlinForwardDeclarationsFileGenerator {
generateFile(libraryLocation, pkg, kind, classes)
}
val virtualRootFile = VfsUtil.findFile(root, true)
val virtualRootFile = VfsUtil.findFile(root, /* refreshIfNeeded = */ true)
virtualRootFile?.let {
VfsUtil.markDirty(true, true, it)
VfsUtil.markDirty(/* recursive = */ true, /* reloadChildren = */ true, it)
}
return libraryLocation
}
@@ -41,7 +41,7 @@ abstract class KotlinForwardDeclarationsFileSystem : NewVirtualFileSystem() {
*/
// TODO: KTIJ-29679 rethink the design or drop altogether.
// TODO: KTIJ-29679 potential problem with long paths after nesting under the storage root.
class KotlinForwardDeclarationsFileSystemImpl : KotlinForwardDeclarationsFileSystem() {
internal class KotlinForwardDeclarationsFileSystemImpl : KotlinForwardDeclarationsFileSystem() {
override fun extractRootPath(normalizedPath: String): String {
return normalizedPath // TODO: KTIJ-29679
}
@@ -11,7 +11,7 @@ import java.util.Properties
* Utility functions for grouping K/N forward declarations from a native manifest properties or a [NativeKlibLibraryInfo].
* Grouped declaration [FqName]s share the same package and so the same [org.jetbrains.kotlin.name.NativeForwardDeclarationKind].
*/
object KotlinForwardDeclarationsFqNameExtractor {
internal object KotlinForwardDeclarationsFqNameExtractor {
fun getGroupedForwardDeclarations(libraryInfo: NativeKlibLibraryInfo): Map<FqName, List<FqName>> {
val fqNames = getForwardDeclarationFqNames(libraryInfo)
return groupByPackage(fqNames)
@@ -35,7 +35,7 @@ import java.io.File
* @see [KotlinForwardDeclarationsFileGenerator]
*/
@Suppress("LightServiceMigrationCode") // K2-only service
class KotlinForwardDeclarationsModelChangeService(private val project: Project, cs: CoroutineScope) {
internal class KotlinForwardDeclarationsModelChangeService(private val project: Project, cs: CoroutineScope) {
init {
if (Registry.`is`("kotlin.k2.kmp.enabled")) {
cs.launch {
@@ -126,7 +126,7 @@ class KotlinForwardDeclarationsModelChangeService(private val project: Project,
/**
* Request [KotlinForwardDeclarationsModelChangeService] on startup to start receiving workspace model update events.
*/
class KotlinForwardDeclarationsStartupActivity : ProjectActivity {
internal class KotlinForwardDeclarationsStartupActivity : ProjectActivity {
override suspend fun execute(project: Project) {
if (!Registry.`is`("kotlin.k2.kmp.enabled")) return
@@ -11,13 +11,19 @@ import com.intellij.workspaceModel.core.fileIndex.WorkspaceFileSetRegistrar
* File Index Contributor of generated K/N forward declaration files.
* They are not part of the project and require explicit indexing registration.
*
* @see [KotlinForwardDeclarationsFileGenerator], [KotlinForwardDeclarationsModelChangeService]
* @see [KotlinForwardDeclarationsFileGenerator]
* @see [KotlinForwardDeclarationsModelChangeService]
*/
class KotlinForwardDeclarationsWorkspaceFileIndexContributor : WorkspaceFileIndexContributor<KotlinForwardDeclarationsWorkspaceEntity> {
internal class KotlinForwardDeclarationsWorkspaceFileIndexContributor :
WorkspaceFileIndexContributor<KotlinForwardDeclarationsWorkspaceEntity> {
override val entityClass: Class<KotlinForwardDeclarationsWorkspaceEntity>
get() = KotlinForwardDeclarationsWorkspaceEntity::class.java
override fun registerFileSets(entity: KotlinForwardDeclarationsWorkspaceEntity, registrar: WorkspaceFileSetRegistrar, storage: EntityStorage) {
override fun registerFileSets(
entity: KotlinForwardDeclarationsWorkspaceEntity,
registrar: WorkspaceFileSetRegistrar,
storage: EntityStorage,
) {
if (!Registry.`is`("kotlin.k2.kmp.enabled")) return
entity.forwardDeclarationRoots.forEach { fwdDeclarationRootUrl ->