mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
[workspace file index] move JvmPackageRootData to Java plugin and make it public
Kotlin plugin needs to contribute its directories to PackageIndex, so we need to have a public API for that. It's better to put it to Java plugin from the beginning, since corresponding functionality will be removed from the platform as soon as we get rid of platform API which allows plugins to access it. GitOrigin-RevId: d66adf78641383312478950bb040bdf66ffd1eb2
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f1c257b3b4
commit
c8c61b308d
@@ -0,0 +1,14 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.java.workspaceModel.fileIndex
|
||||
|
||||
import com.intellij.workspaceModel.core.fileIndex.impl.JvmPackageRootDataInternal
|
||||
|
||||
/**
|
||||
* Implement this interface in your implementation of [com.intellij.workspaceModel.core.fileIndex.WorkspaceFileSetData] if the root of the
|
||||
* corresponding file set is a JVM package and may contain *.class files or source files compiled to *.class files. This information will
|
||||
* be used by [com.intellij.openapi.roots.PackageIndex] to match package names to directories.
|
||||
*/
|
||||
interface JvmPackageRootData: JvmPackageRootDataInternal {
|
||||
override val packagePrefix: String
|
||||
get() = ""
|
||||
}
|
||||
@@ -62,7 +62,7 @@ internal class NonIncrementalContributors(private val project: Project,
|
||||
sets.forEach { set ->
|
||||
fileSets.putValue(root, set)
|
||||
val fileSet = set as? WorkspaceFileSetImpl
|
||||
if (fileSet != null && fileSet.data is JvmPackageRootData) {
|
||||
if (fileSet != null && fileSet.data is JvmPackageRootDataInternal) {
|
||||
fileSetsByPackagePrefix.addFileSet("", fileSet)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,12 +270,12 @@ internal class WorkspaceFileIndexData(private val contributorList: List<Workspac
|
||||
if (!dir.isDirectory) return null
|
||||
|
||||
val fileSet = when (val info = getFileInfo(dir, true, true, true, true)) {
|
||||
is WorkspaceFileSetWithCustomData<*> -> info.takeIf { it.data is JvmPackageRootData }
|
||||
is MultipleWorkspaceFileSets -> info.find(JvmPackageRootData::class.java)
|
||||
is WorkspaceFileSetWithCustomData<*> -> info.takeIf { it.data is JvmPackageRootDataInternal }
|
||||
is MultipleWorkspaceFileSets -> info.find(JvmPackageRootDataInternal::class.java)
|
||||
else -> null
|
||||
} ?: return null
|
||||
|
||||
val packagePrefix = (fileSet.data as JvmPackageRootData).packagePrefix
|
||||
val packagePrefix = (fileSet.data as JvmPackageRootDataInternal).packagePrefix
|
||||
val packageName = VfsUtilCore.getRelativePath(dir, fileSet.root, '.')
|
||||
?: error("${dir.presentableUrl} is not under ${fileSet.root.presentableUrl}")
|
||||
return when {
|
||||
@@ -318,7 +318,7 @@ internal class WorkspaceFileIndexData(private val contributorList: List<Workspac
|
||||
customData: WorkspaceFileSetData?) {
|
||||
val fileSet = WorkspaceFileSetImpl(root, kind, entity.createReference(), storageKind, customData ?: DummyWorkspaceFileSetData)
|
||||
fileSets.putValue(root, fileSet)
|
||||
if (customData is JvmPackageRootData) {
|
||||
if (customData is JvmPackageRootDataInternal) {
|
||||
fileSetsByPackagePrefix.addFileSet(customData.packagePrefix, fileSet)
|
||||
}
|
||||
}
|
||||
@@ -369,7 +369,7 @@ internal class WorkspaceFileIndexData(private val contributorList: List<Workspac
|
||||
entity: WorkspaceEntity,
|
||||
customData: WorkspaceFileSetData?) {
|
||||
fileSets.removeValueIf(root) { it is WorkspaceFileSetImpl && isOriginatedFrom(it, entity) }
|
||||
if (customData is JvmPackageRootData) {
|
||||
if (customData is JvmPackageRootDataInternal) {
|
||||
fileSetsByPackagePrefix.removeByPrefixAndReference(customData.packagePrefix, entity.createReference())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,10 +85,10 @@ class LibraryRootFileIndexContributor : WorkspaceFileIndexContributor<LibraryEnt
|
||||
}
|
||||
|
||||
internal class LibrarySourceRootFileSetData(projectLibraryId: LibraryId?, packagePrefix: String)
|
||||
: LibraryRootFileSetData(projectLibraryId, packagePrefix), ModuleOrLibrarySourceRootData, JvmPackageRootData
|
||||
: LibraryRootFileSetData(projectLibraryId, packagePrefix), ModuleOrLibrarySourceRootData, JvmPackageRootDataInternal
|
||||
|
||||
internal open class LibraryRootFileSetData(private val projectLibraryId: LibraryId?,
|
||||
override val packagePrefix: String) : UnloadableFileSetData, JvmPackageRootData {
|
||||
override val packagePrefix: String) : UnloadableFileSetData, JvmPackageRootDataInternal {
|
||||
override fun isUnloaded(project: Project): Boolean {
|
||||
return projectLibraryId != null && !ModuleDependencyIndex.getInstance(project).hasDependencyOn(projectLibraryId)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.intellij.workspaceModel.ide.impl.legacyBridge.module.roots.SourceRoot
|
||||
import com.intellij.workspaceModel.ide.impl.virtualFile
|
||||
import com.intellij.workspaceModel.storage.EntityStorage
|
||||
import com.intellij.workspaceModel.storage.bridgeEntities.*
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
|
||||
class ContentRootFileIndexContributor : WorkspaceFileIndexContributor<ContentRootEntity>, PlatformInternalWorkspaceFileIndexContributor {
|
||||
override val entityClass: Class<ContentRootEntity>
|
||||
@@ -68,7 +69,13 @@ interface ModuleContentOrSourceRootData: WorkspaceFileSetData {
|
||||
*/
|
||||
interface ModuleOrLibrarySourceRootData: WorkspaceFileSetData
|
||||
|
||||
internal interface JvmPackageRootData: WorkspaceFileSetData {
|
||||
/**
|
||||
* Marks files sets which correspond to JVM packages. This interface will be removed from the platform when we get rid of Java-specific
|
||||
* methods like [com.intellij.openapi.roots.ProjectFileIndex.getPackageNameByDirectory] in the platform API, so plugins must use
|
||||
* [com.intellij.java.workspaceModel.fileIndex.JvmPackageRootData] instead.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
interface JvmPackageRootDataInternal: WorkspaceFileSetData {
|
||||
val packagePrefix: String
|
||||
}
|
||||
|
||||
@@ -80,4 +87,4 @@ internal data class ModuleSourceRootData(
|
||||
val rootType: String,
|
||||
override val packagePrefix: String,
|
||||
val forGeneratedSources: Boolean
|
||||
) : ModuleContentOrSourceRootData, ModuleOrLibrarySourceRootData, JvmPackageRootData
|
||||
) : ModuleContentOrSourceRootData, ModuleOrLibrarySourceRootData, JvmPackageRootDataInternal
|
||||
|
||||
Reference in New Issue
Block a user