[Kotlin] K/N forward declarations: don't use the short fwd prefix

Improves search

KTIJ-29679

GitOrigin-RevId: 8c4e6bdfbcc4e09dca1ac6cfe65bada1ac2f548c
This commit is contained in:
Pavel Kirpichenkov
2024-05-30 01:02:36 +00:00
committed by intellij-monorepo-bot
parent 2dd7b7a9c5
commit 29405e18ad
13 changed files with 32 additions and 34 deletions
@@ -15,7 +15,7 @@ import com.intellij.util.indexing.hints.BaseFileTypeInputFilter
import com.intellij.util.indexing.hints.BaseGlobalFileTypeInputFilter
import com.intellij.util.indexing.hints.FileTypeSubstitutionStrategy.BEFORE_SUBSTITUTION
import org.jetbrains.kotlin.idea.KotlinFileType
import org.jetbrains.kotlin.idea.base.projectStructure.fwdDeclaration.KotlinForwardDeclarationsFileSystem
import org.jetbrains.kotlin.idea.base.projectStructure.forwardDeclarations.KotlinForwardDeclarationsFileSystem
private const val KOTLIN_DOT_FILE_EXTENSION = ".${KotlinFileType.EXTENSION}"
@@ -16,13 +16,13 @@ import org.jetbrains.kotlin.idea.base.projectStructure.KtNativeKlibLibraryModule
* FIR IDE declaration provider factory implementation for Kotlin/Native forward declarations.
* Delegates to the regular factory, but uses a narrow [GlobalSearchScope] that contains only generated declarations of the [KtModule].
*
* @see [org.jetbrains.kotlin.idea.base.projectStructure.fwdDeclaration.KotlinForwardDeclarationsFileGenerator]
* @see [org.jetbrains.kotlin.idea.base.projectStructure.forwardDeclarations.KotlinForwardDeclarationsFileGenerator]
*/
class FirIdeForwardDeclarationProviderFactory : KotlinForwardDeclarationProviderFactory() {
override fun createDeclarationProvider(ktModule: KtModule): KotlinDeclarationProvider? {
if (ktModule !is KtNativeKlibLibraryModuleByModuleInfo) return null
return ktModule.project.createDeclarationProvider(ktModule.fwdDeclarationsScope, ktModule)
return ktModule.project.createDeclarationProvider(ktModule.forwardDeclarationsScope, ktModule)
}
}
@@ -30,12 +30,12 @@ class FirIdeForwardDeclarationProviderFactory : KotlinForwardDeclarationProvider
* FIR IDE package provider factory for Kotlin/Native forward declarations.
* Delegates to the regular factory, but uses a narrow [GlobalSearchScope] that contains only generated declarations of the [KtModule].
*
* @see [org.jetbrains.kotlin.idea.base.projectStructure.fwdDeclaration.KotlinForwardDeclarationsFileGenerator]
* @see [org.jetbrains.kotlin.idea.base.projectStructure.forwardDeclarations.KotlinForwardDeclarationsFileGenerator]
*/
class FirIdeForwardDeclarationPackageProviderFactory : KotlinForwardDeclarationsPackageProviderFactory() {
override fun createPackageProvider(ktModule: KtModule): KotlinPackageProvider? {
if (ktModule !is KtNativeKlibLibraryModuleByModuleInfo) return null
return ktModule.project.createPackageProvider(ktModule.fwdDeclarationsScope)
return ktModule.project.createPackageProvider(ktModule.forwardDeclarationsScope)
}
}
@@ -1,15 +1,13 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.base.projectStructure.fwdDeclaration
package org.jetbrains.kotlin.idea.base.projectStructure.forwardDeclarations
import com.intellij.platform.workspace.jps.entities.LibraryEntity
import com.intellij.platform.workspace.storage.EntitySource
import com.intellij.platform.workspace.storage.EntityType
import com.intellij.platform.workspace.storage.GeneratedCodeApiVersion
import com.intellij.platform.workspace.storage.GeneratedCodeImplVersion
import com.intellij.platform.workspace.storage.MutableEntityStorage
import com.intellij.platform.workspace.storage.WorkspaceEntity
import com.intellij.platform.workspace.storage.annotations.Child
import com.intellij.platform.workspace.storage.impl.ConnectionId
import com.intellij.platform.workspace.storage.impl.EntityLink
import com.intellij.platform.workspace.storage.impl.ModifiableWorkspaceEntityBase
@@ -1,5 +1,5 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.base.projectStructure.fwdDeclaration
package org.jetbrains.kotlin.idea.base.projectStructure.forwardDeclarations
import com.intellij.platform.workspace.storage.impl.ConnectionId
import com.intellij.platform.workspace.storage.metadata.impl.MetadataStorageBase
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.config.SourceKotlinRootType
import org.jetbrains.kotlin.config.TestSourceKotlinRootType
import org.jetbrains.kotlin.idea.KotlinFileType
import org.jetbrains.kotlin.idea.base.projectStructure.fwdDeclaration.kotlinForwardDeclarationsWorkspaceEntity
import org.jetbrains.kotlin.idea.base.projectStructure.forwardDeclarations.kotlinForwardDeclarationsWorkspaceEntity
import org.jetbrains.kotlin.idea.base.projectStructure.moduleInfo.*
import org.jetbrains.kotlin.idea.base.projectStructure.scope.LibrarySourcesScope
import org.jetbrains.kotlin.idea.base.util.minus
@@ -198,13 +198,13 @@ class KtNativeKlibLibraryModuleByModuleInfo(
) : KtLibraryModuleByModuleInfo(nativeLibraryInfo) {
override val contentScope: GlobalSearchScope
get() = GlobalSearchScope.union(
listOf(mainScope, fwdDeclarationsScope)
listOf(mainScope, forwardDeclarationsScope)
)
val mainScope: GlobalSearchScope
get() = nativeLibraryInfo.contentScope
val fwdDeclarationsScope: GlobalSearchScope
val forwardDeclarationsScope: GlobalSearchScope
get() {
val rootDirectories = getGeneratedFwdDeclarationRoots(nativeLibraryInfo)
@@ -1,6 +1,6 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.base.projectStructure.fwdDeclaration
package org.jetbrains.kotlin.idea.base.projectStructure.forwardDeclarations
import com.intellij.platform.workspace.jps.entities.LibraryEntity
import com.intellij.platform.workspace.storage.EntitySource
@@ -1,6 +1,6 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.base.projectStructure.fwdDeclaration
package org.jetbrains.kotlin.idea.base.projectStructure.forwardDeclarations
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.util.registry.Registry
@@ -35,7 +35,7 @@ object KotlinForwardDeclarationsFileGenerator {
fun generateForwardDeclarationFiles(libraryInfo: NativeKlibLibraryInfo): Path? {
if (!Registry.`is`("kotlin.k2.kmp.enabled")) return null
val groupedClasses = KotlinForwardDeclarationsFqNameExtractor.getGroupedFwdDeclarations(libraryInfo).ifEmpty { return null }
val groupedClasses = KotlinForwardDeclarationsFqNameExtractor.getGroupedForwardDeclarations(libraryInfo).ifEmpty { return null }
return generateForwardDeclarationsForFqNames(groupedClasses, libraryInfo.libraryRoot)
}
@@ -1,6 +1,6 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.base.projectStructure.fwdDeclaration
package org.jetbrains.kotlin.idea.base.projectStructure.forwardDeclarations
import com.intellij.openapi.application.PathManager
import com.intellij.openapi.util.io.FileAttributes
@@ -1,6 +1,6 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.base.projectStructure.fwdDeclaration
package org.jetbrains.kotlin.idea.base.projectStructure.forwardDeclarations
import org.jetbrains.kotlin.idea.base.projectStructure.moduleInfo.NativeKlibLibraryInfo
import org.jetbrains.kotlin.library.KLIB_PROPERTY_INCLUDED_FORWARD_DECLARATIONS
@@ -12,32 +12,32 @@ import java.util.Properties
* Grouped declaration [FqName]s share the same package and so the same [org.jetbrains.kotlin.name.NativeForwardDeclarationKind].
*/
object KotlinForwardDeclarationsFqNameExtractor {
fun getGroupedFwdDeclarations(libraryInfo: NativeKlibLibraryInfo): Map<FqName, List<FqName>> {
val fqNames = getFwdDeclarationFqNames(libraryInfo)
fun getGroupedForwardDeclarations(libraryInfo: NativeKlibLibraryInfo): Map<FqName, List<FqName>> {
val fqNames = getForwardDeclarationFqNames(libraryInfo)
return groupByPackage(fqNames)
}
fun getGroupedFwdDeclarations(properties: Properties): Map<FqName, List<FqName>> {
val fqNames = getFwdDeclarationFqNames(properties)
fun getGroupedForwardDeclarations(properties: Properties): Map<FqName, List<FqName>> {
val fqNames = getForwardDeclarationFqNames(properties)
return groupByPackage(fqNames)
}
fun getPackageFqNames(libraryInfo: NativeKlibLibraryInfo): List<FqName> {
return getGroupedFwdDeclarations(libraryInfo).keys.toList()
return getGroupedForwardDeclarations(libraryInfo).keys.toList()
}
internal fun groupByPackage(declarations: List<FqName>): Map<FqName, List<FqName>> =
declarations.groupBy(FqName::parent)
private fun getFwdDeclarationFqNames(libraryInfo: NativeKlibLibraryInfo): List<FqName> {
return getFwdDeclarationFqNames(libraryInfo.resolvedKotlinLibrary.manifestProperties)
private fun getForwardDeclarationFqNames(libraryInfo: NativeKlibLibraryInfo): List<FqName> {
return getForwardDeclarationFqNames(libraryInfo.resolvedKotlinLibrary.manifestProperties)
}
private fun getFwdDeclarationFqNames(properties: Properties): List<FqName> {
val fwdDeclarations = properties[KLIB_PROPERTY_INCLUDED_FORWARD_DECLARATIONS]?.toString().orEmpty()
private fun getForwardDeclarationFqNames(properties: Properties): List<FqName> {
val forwardDeclarations = properties[KLIB_PROPERTY_INCLUDED_FORWARD_DECLARATIONS]?.toString().orEmpty()
.split(" ")
.filter { it.isNotEmpty() }
return fwdDeclarations.map(::FqName)
return forwardDeclarations.map(::FqName)
}
}
@@ -1,5 +1,5 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.base.projectStructure.fwdDeclaration
package org.jetbrains.kotlin.idea.base.projectStructure.forwardDeclarations
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
@@ -1,5 +1,5 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.base.projectStructure.fwdDeclaration
package org.jetbrains.kotlin.idea.base.projectStructure.forwardDeclarations
import com.intellij.openapi.util.registry.Registry
import com.intellij.platform.workspace.storage.EntityStorage
@@ -3,7 +3,7 @@
package org.jetbrains.kotlin.idea
import junit.framework.TestCase
import org.jetbrains.kotlin.idea.base.projectStructure.fwdDeclaration.KotlinForwardDeclarationsFqNameExtractor
import org.jetbrains.kotlin.idea.base.projectStructure.forwardDeclarations.KotlinForwardDeclarationsFqNameExtractor
import org.jetbrains.kotlin.name.FqName
class ForwardDeclarationFqNameExtractorTest : TestCase() {
@@ -3,13 +3,13 @@
<psi.classFileDecompiler implementation="org.jetbrains.kotlin.analysis.decompiler.konan.K2KotlinNativeMetadataDecompiler"/>
<projectService
serviceImplementation="org.jetbrains.kotlin.idea.base.projectStructure.fwdDeclaration.KotlinForwardDeclarationsModelChangeService"/>
serviceImplementation="org.jetbrains.kotlin.idea.base.projectStructure.forwardDeclarations.KotlinForwardDeclarationsModelChangeService"/>
<postStartupActivity
implementation="org.jetbrains.kotlin.idea.base.projectStructure.fwdDeclaration.KotlinForwardDeclarationsStartupActivity"/>
implementation="org.jetbrains.kotlin.idea.base.projectStructure.forwardDeclarations.KotlinForwardDeclarationsStartupActivity"/>
<workspaceModel.fileIndexContributor
implementation="org.jetbrains.kotlin.idea.base.projectStructure.fwdDeclaration.KotlinForwardDeclarationsWorkspaceFileIndexContributor"/>
<virtualFileSystem implementationClass="org.jetbrains.kotlin.idea.base.projectStructure.fwdDeclaration.KotlinForwardDeclarationsFileSystemImpl"
implementation="org.jetbrains.kotlin.idea.base.projectStructure.forwardDeclarations.KotlinForwardDeclarationsWorkspaceFileIndexContributor"/>
<virtualFileSystem implementationClass="org.jetbrains.kotlin.idea.base.projectStructure.forwardDeclarations.KotlinForwardDeclarationsFileSystemImpl"
key="fwd" physical="false"/>
</extensions>
</idea-plugin>