From ebc215a94409b0fc3d50fab4c4ad048109b507c6 Mon Sep 17 00:00:00 2001 From: Pavel Kirpichenkov Date: Wed, 29 May 2024 19:24:35 +0300 Subject: [PATCH] [Kotlin] K/N forward declarations: cleanup KTIJ-29679 GitOrigin-RevId: 9e53f6288ac371a7a13af055c651d76f27c4cd4e --- ...rIdeForwardDeclarationsServiceFactories.kt | 4 ++-- .../KotlinForwardDeclarationsFileGenerator.kt | 19 +++++++++---------- .../KotlinForwardDeclarationsFileSystem.kt | 2 +- ...otlinForwardDeclarationsFqNameExtractor.kt | 2 +- ...inForwardDeclarationsModelChangeService.kt | 4 ++-- ...clarationsWorkspaceFileIndexContributor.kt | 12 +++++++++--- 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/plugins/kotlin/base/fir/analysis-api-providers/src/org/jetbrains/kotlin/idea/base/fir/analysisApiProviders/FirIdeForwardDeclarationsServiceFactories.kt b/plugins/kotlin/base/fir/analysis-api-providers/src/org/jetbrains/kotlin/idea/base/fir/analysisApiProviders/FirIdeForwardDeclarationsServiceFactories.kt index 17ff652a7bab..ab69ce5414b3 100644 --- a/plugins/kotlin/base/fir/analysis-api-providers/src/org/jetbrains/kotlin/idea/base/fir/analysisApiProviders/FirIdeForwardDeclarationsServiceFactories.kt +++ b/plugins/kotlin/base/fir/analysis-api-providers/src/org/jetbrains/kotlin/idea/base/fir/analysisApiProviders/FirIdeForwardDeclarationsServiceFactories.kt @@ -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 diff --git a/plugins/kotlin/base/project-structure/src/org/jetbrains/kotlin/idea/base/projectStructure/forwardDeclarations/KotlinForwardDeclarationsFileGenerator.kt b/plugins/kotlin/base/project-structure/src/org/jetbrains/kotlin/idea/base/projectStructure/forwardDeclarations/KotlinForwardDeclarationsFileGenerator.kt index 0fd9f6b2ffbb..11c913de9455 100644 --- a/plugins/kotlin/base/project-structure/src/org/jetbrains/kotlin/idea/base/projectStructure/forwardDeclarations/KotlinForwardDeclarationsFileGenerator.kt +++ b/plugins/kotlin/base/project-structure/src/org/jetbrains/kotlin/idea/base/projectStructure/forwardDeclarations/KotlinForwardDeclarationsFileGenerator.kt @@ -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() /** * 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>, 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 } diff --git a/plugins/kotlin/base/project-structure/src/org/jetbrains/kotlin/idea/base/projectStructure/forwardDeclarations/KotlinForwardDeclarationsFileSystem.kt b/plugins/kotlin/base/project-structure/src/org/jetbrains/kotlin/idea/base/projectStructure/forwardDeclarations/KotlinForwardDeclarationsFileSystem.kt index b3028a7e0245..8b81accdf135 100644 --- a/plugins/kotlin/base/project-structure/src/org/jetbrains/kotlin/idea/base/projectStructure/forwardDeclarations/KotlinForwardDeclarationsFileSystem.kt +++ b/plugins/kotlin/base/project-structure/src/org/jetbrains/kotlin/idea/base/projectStructure/forwardDeclarations/KotlinForwardDeclarationsFileSystem.kt @@ -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 } diff --git a/plugins/kotlin/base/project-structure/src/org/jetbrains/kotlin/idea/base/projectStructure/forwardDeclarations/KotlinForwardDeclarationsFqNameExtractor.kt b/plugins/kotlin/base/project-structure/src/org/jetbrains/kotlin/idea/base/projectStructure/forwardDeclarations/KotlinForwardDeclarationsFqNameExtractor.kt index 2ebf650ec7b1..5326c99fa92c 100644 --- a/plugins/kotlin/base/project-structure/src/org/jetbrains/kotlin/idea/base/projectStructure/forwardDeclarations/KotlinForwardDeclarationsFqNameExtractor.kt +++ b/plugins/kotlin/base/project-structure/src/org/jetbrains/kotlin/idea/base/projectStructure/forwardDeclarations/KotlinForwardDeclarationsFqNameExtractor.kt @@ -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> { val fqNames = getForwardDeclarationFqNames(libraryInfo) return groupByPackage(fqNames) diff --git a/plugins/kotlin/base/project-structure/src/org/jetbrains/kotlin/idea/base/projectStructure/forwardDeclarations/KotlinForwardDeclarationsModelChangeService.kt b/plugins/kotlin/base/project-structure/src/org/jetbrains/kotlin/idea/base/projectStructure/forwardDeclarations/KotlinForwardDeclarationsModelChangeService.kt index 4ccab06b542a..36b9870f5dd3 100644 --- a/plugins/kotlin/base/project-structure/src/org/jetbrains/kotlin/idea/base/projectStructure/forwardDeclarations/KotlinForwardDeclarationsModelChangeService.kt +++ b/plugins/kotlin/base/project-structure/src/org/jetbrains/kotlin/idea/base/projectStructure/forwardDeclarations/KotlinForwardDeclarationsModelChangeService.kt @@ -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 diff --git a/plugins/kotlin/base/project-structure/src/org/jetbrains/kotlin/idea/base/projectStructure/forwardDeclarations/KotlinForwardDeclarationsWorkspaceFileIndexContributor.kt b/plugins/kotlin/base/project-structure/src/org/jetbrains/kotlin/idea/base/projectStructure/forwardDeclarations/KotlinForwardDeclarationsWorkspaceFileIndexContributor.kt index 4f648e30229a..3b7ad46eac26 100644 --- a/plugins/kotlin/base/project-structure/src/org/jetbrains/kotlin/idea/base/projectStructure/forwardDeclarations/KotlinForwardDeclarationsWorkspaceFileIndexContributor.kt +++ b/plugins/kotlin/base/project-structure/src/org/jetbrains/kotlin/idea/base/projectStructure/forwardDeclarations/KotlinForwardDeclarationsWorkspaceFileIndexContributor.kt @@ -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 { +internal class KotlinForwardDeclarationsWorkspaceFileIndexContributor : + WorkspaceFileIndexContributor { override val entityClass: Class 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 ->