From e1e586b158e30641f38d0362795cf6f41950e23a Mon Sep 17 00:00:00 2001 From: Alex Plate Date: Thu, 11 Jan 2024 10:18:33 +0200 Subject: [PATCH] [Workspace Model] Introduce `WorkspaceModelInternal` interface with some internal functions This is a part of IJPL-345 GitOrigin-RevId: c6879d14c8ecbc383b957cfeef2a670743636193 --- .../artifacts/ArtifactVirtualFileListener.kt | 4 +- .../workspacemodel/ArtifactBridge.kt | 3 +- .../workspacemodel/ArtifactManagerBridge.kt | 5 +- .../ArtifactModifiableModelBridge.kt | 3 +- .../artifacts/workspaceModel/ArtifactTest.kt | 5 +- .../jarRepository/RepositoryLibraryTest.kt | 4 +- .../roots/UnloadedModulesConfigurationTest.kt | 11 +-- .../backend/workspace/src/WorkspaceModel.kt | 53 ------------- .../src/impl/WorkspaceModelInternal.kt | 75 +++++++++++++++++++ .../IdeModifiableModelsProviderImpl.java | 4 +- .../project/manage/SourceFolderManagerTest.kt | 6 +- .../FileReferenceInWorkspaceEntityUpdater.kt | 7 +- .../module/ModuleBridgeLoaderService.kt | 5 +- .../ide/impl/WorkspaceModelCacheImpl.kt | 5 +- .../JpsProjectModelSynchronizer.kt | 17 +++-- .../impl/WorkspaceFileIndexDataImpl.kt | 3 +- .../ide/impl/WorkspaceModelImpl.kt | 5 +- .../library/ProjectLibraryTableBridgeImpl.kt | 5 +- .../LegacyProjectModelListenersBridge.kt | 10 +-- .../module/ModuleManagerBridgeImpl.kt | 9 ++- .../ModifiableModuleLibraryTableBridge.kt | 4 +- .../workspaceModel/ide/ModuleBridgesTest.kt | 8 +- ...WorkspaceModelBenchmarksPerformanceTest.kt | 5 +- .../workspaceModel/ide/WorkspaceModelTest.kt | 17 +++-- .../DelayedProjectSynchronizerTest.kt | 5 +- .../script/ucache/ScriptClassRootsUpdater.kt | 7 +- .../WorkspaceProjectImporter.kt | 9 ++- .../ImportMavenProjectCommand.kt | 4 +- 28 files changed, 169 insertions(+), 129 deletions(-) create mode 100644 platform/backend/workspace/src/impl/WorkspaceModelInternal.kt diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactVirtualFileListener.kt b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactVirtualFileListener.kt index 089ecfac5612..9b601dcda0f2 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactVirtualFileListener.kt +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactVirtualFileListener.kt @@ -18,6 +18,7 @@ import com.intellij.packaging.impl.artifacts.workspacemodel.ArtifactBridge import com.intellij.packaging.impl.artifacts.workspacemodel.ArtifactManagerBridge.Companion.artifactsMap import com.intellij.packaging.impl.elements.FileOrDirectoryCopyPackagingElement import com.intellij.platform.backend.workspace.WorkspaceModel.Companion.getInstance +import com.intellij.platform.backend.workspace.impl.internal import com.intellij.platform.backend.workspace.useQueryCacheWorkspaceModelApi import com.intellij.platform.backend.workspace.workspaceModel import com.intellij.platform.diagnostic.telemetry.Compiler @@ -28,7 +29,6 @@ import com.intellij.platform.workspace.storage.query.entities import com.intellij.platform.workspace.storage.query.flatMap import com.intellij.platform.workspace.storage.query.groupBy import com.intellij.util.PathUtil -import com.intellij.workspaceModel.ide.impl.WorkspaceModelImpl import io.opentelemetry.api.metrics.Meter import java.util.concurrent.atomic.AtomicLong @@ -87,7 +87,7 @@ internal class ArtifactVirtualFileListener(private val project: Project) : BulkF } private val parentPathToArtifacts: Map> - get() = (getInstance(project) as WorkspaceModelImpl).entityStorage.cachedValue(parentPathsToArtifacts) + get() = getInstance(project).internal.entityStorage.cachedValue(parentPathsToArtifacts) private fun propertyChanged(event: VFilePropertyChangeEvent) = propertyChangedMs.addMeasuredTimeMillis { if (VirtualFile.PROP_NAME == event.propertyName) { diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/workspacemodel/ArtifactBridge.kt b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/workspacemodel/ArtifactBridge.kt index e257f82422fd..433d1efa003b 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/workspacemodel/ArtifactBridge.kt +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/workspacemodel/ArtifactBridge.kt @@ -16,6 +16,7 @@ import com.intellij.packaging.impl.artifacts.workspacemodel.packaging.elements import com.intellij.platform.backend.workspace.WorkspaceModel import com.intellij.platform.backend.workspace.WorkspaceModelChangeListener import com.intellij.platform.backend.workspace.WorkspaceModelTopics +import com.intellij.platform.backend.workspace.impl.internal import com.intellij.platform.backend.workspace.virtualFile import com.intellij.platform.diagnostic.telemetry.Compiler import com.intellij.platform.diagnostic.telemetry.TelemetryManager @@ -265,7 +266,7 @@ open class ArtifactBridge( fun setActualStorage() { if (entityStorage is VersionedEntityStorageOnBuilder) { - entityStorage = (WorkspaceModel.getInstance(project) as WorkspaceModelImpl).entityStorage + entityStorage = WorkspaceModel.getInstance(project).internal.entityStorage } } diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/workspacemodel/ArtifactManagerBridge.kt b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/workspacemodel/ArtifactManagerBridge.kt index 7947d98f6404..b90796aeecb9 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/workspacemodel/ArtifactManagerBridge.kt +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/workspacemodel/ArtifactManagerBridge.kt @@ -23,6 +23,7 @@ import com.intellij.packaging.impl.artifacts.ArtifactPointerManagerImpl import com.intellij.packaging.impl.artifacts.DefaultPackagingElementResolvingContext import com.intellij.packaging.impl.artifacts.InvalidArtifact import com.intellij.packaging.impl.artifacts.workspacemodel.packaging.elements +import com.intellij.platform.backend.workspace.impl.internal import com.intellij.platform.backend.workspace.workspaceModel import com.intellij.platform.diagnostic.telemetry.Compiler import com.intellij.platform.diagnostic.telemetry.TelemetryManager @@ -231,7 +232,7 @@ class ArtifactManagerBridge(private val project: Project) : ArtifactManager(), D artifactWithDiffs.forEach { it.setActualStorage() } artifactWithDiffs.clear() - val entityStorage = (project.workspaceModel as WorkspaceModelImpl).entityStorage + val entityStorage = project.workspaceModel.internal.entityStorage added.forEach { bridge -> bridge.elementsWithDiff.forEach { it.setStorage(entityStorage, project, HashSet(), PackagingElementInitializer) } bridge.elementsWithDiff.clear() @@ -292,7 +293,7 @@ class ArtifactManagerBridge(private val project: Project) : ArtifactManager(), D .entities(ArtifactEntity::class.java) .mapNotNull { if (artifactsMap.getDataByEntity(it) == null) { - createArtifactBridge(it, (workspaceModel as WorkspaceModelImpl).entityStorage, project) + createArtifactBridge(it, workspaceModel.internal.entityStorage, project) } else null } diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/workspacemodel/ArtifactModifiableModelBridge.kt b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/workspacemodel/ArtifactModifiableModelBridge.kt index 346aa802369a..d90ccff21a96 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/workspacemodel/ArtifactModifiableModelBridge.kt +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/workspacemodel/ArtifactModifiableModelBridge.kt @@ -16,6 +16,7 @@ import com.intellij.packaging.impl.artifacts.workspacemodel.ArtifactManagerBridg import com.intellij.packaging.impl.artifacts.workspacemodel.ArtifactManagerBridge.Companion.artifactsMap import com.intellij.packaging.impl.artifacts.workspacemodel.ArtifactManagerBridge.Companion.mutableArtifactsMap import com.intellij.platform.backend.workspace.WorkspaceModel +import com.intellij.platform.backend.workspace.impl.internal import com.intellij.platform.diagnostic.telemetry.Compiler import com.intellij.platform.diagnostic.telemetry.TelemetryManager import com.intellij.platform.diagnostic.telemetry.helpers.addMeasuredTimeMillis @@ -260,7 +261,7 @@ class ArtifactModifiableModelBridge( } } - val entityStorage = (WorkspaceModel.getInstance(project) as WorkspaceModelImpl).entityStorage + val entityStorage = WorkspaceModel.getInstance(project).internal.entityStorage added.forEach { bridge -> bridge.elementsWithDiff.forEach { it.setStorage(entityStorage, project, HashSet(), PackagingElementInitializer) } bridge.elementsWithDiff.clear() diff --git a/java/compiler/tests/com/intellij/compiler/artifacts/workspaceModel/ArtifactTest.kt b/java/compiler/tests/com/intellij/compiler/artifacts/workspaceModel/ArtifactTest.kt index be90de6c3014..e337cb1b64ae 100644 --- a/java/compiler/tests/com/intellij/compiler/artifacts/workspaceModel/ArtifactTest.kt +++ b/java/compiler/tests/com/intellij/compiler/artifacts/workspaceModel/ArtifactTest.kt @@ -29,6 +29,7 @@ import com.intellij.packaging.impl.artifacts.workspacemodel.forThisAndFullTree import com.intellij.packaging.impl.artifacts.workspacemodel.toElement import com.intellij.packaging.impl.elements.* import com.intellij.platform.backend.workspace.WorkspaceModel +import com.intellij.platform.backend.workspace.impl.internal import com.intellij.platform.workspace.jps.entities.LibraryId import com.intellij.platform.workspace.jps.entities.LibraryTableId import com.intellij.platform.workspace.jps.entities.ModuleId @@ -558,7 +559,7 @@ class ArtifactTest : ArtifactsTestCase() { } val threads = List(10) { Callable { - rootEntity!!.toElement(project, (WorkspaceModel.getInstance(project) as WorkspaceModelImpl).entityStorage) + rootEntity!!.toElement(project, WorkspaceModel.getInstance(project).internal.entityStorage) } } @@ -581,7 +582,7 @@ class ArtifactTest : ArtifactsTestCase() { } ArtifactsTestingState.testLevel = it + 1 try { - rootEntity!!.toElement(project, (WorkspaceModel.getInstance(project) as WorkspaceModelImpl).entityStorage) + rootEntity!!.toElement(project, WorkspaceModel.getInstance(project).internal.entityStorage) } catch (e: IllegalStateException) { if (e.message?.contains("Exception on level") != true) { error("Unexpected exception") diff --git a/java/idea-ui/testSrc/com/intellij/jarRepository/RepositoryLibraryTest.kt b/java/idea-ui/testSrc/com/intellij/jarRepository/RepositoryLibraryTest.kt index 392f71d6c31d..6019b424bf74 100644 --- a/java/idea-ui/testSrc/com/intellij/jarRepository/RepositoryLibraryTest.kt +++ b/java/idea-ui/testSrc/com/intellij/jarRepository/RepositoryLibraryTest.kt @@ -9,12 +9,12 @@ import com.intellij.openapi.roots.libraries.Library import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar import com.intellij.openapi.vfs.VfsUtil import com.intellij.platform.backend.workspace.WorkspaceModel +import com.intellij.platform.backend.workspace.impl.internal import com.intellij.testFramework.ApplicationRule import com.intellij.testFramework.DisposableRule import com.intellij.testFramework.RuleChain import com.intellij.testFramework.rules.ProjectModelRule import com.intellij.testFramework.rules.TempDirectory -import com.intellij.workspaceModel.ide.impl.WorkspaceModelImpl import org.jetbrains.idea.maven.utils.library.RepositoryLibraryProperties import org.jetbrains.idea.maven.utils.library.RepositoryUtils import org.junit.Assert.* @@ -124,5 +124,5 @@ class RepositoryLibraryTest { assertTrue(workspaceVersion() == modelVersionBefore) } - private fun workspaceVersion() = (WorkspaceModel.getInstance(projectRule.project) as WorkspaceModelImpl).entityStorage.version + private fun workspaceVersion() = WorkspaceModel.getInstance(projectRule.project).internal.entityStorage.version } \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/roots/UnloadedModulesConfigurationTest.kt b/java/java-tests/testSrc/com/intellij/roots/UnloadedModulesConfigurationTest.kt index e7fae4bd4304..12abeac6a1c7 100644 --- a/java/java-tests/testSrc/com/intellij/roots/UnloadedModulesConfigurationTest.kt +++ b/java/java-tests/testSrc/com/intellij/roots/UnloadedModulesConfigurationTest.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.roots import com.intellij.configurationStore.runInAllowSaveMode @@ -16,6 +16,7 @@ import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.io.FileUtilRt import com.intellij.openapi.vfs.VfsUtilCore import com.intellij.platform.backend.workspace.WorkspaceModel +import com.intellij.platform.backend.workspace.impl.internal import com.intellij.platform.ide.progress.runWithModalProgressBlocking import com.intellij.platform.workspace.jps.entities.LibraryEntity import com.intellij.platform.workspace.jps.entities.ModuleEntity @@ -26,7 +27,7 @@ import java.nio.file.Paths class UnloadedModulesConfigurationTest : JavaModuleTestCase() { private val unloadedModuleEntities: List - get() = WorkspaceModel.getInstance(project).currentSnapshotOfUnloadedEntities.entities(ModuleEntity::class.java).toList() + get() = WorkspaceModel.getInstance(project).internal.currentSnapshotOfUnloadedEntities.entities(ModuleEntity::class.java).toList() fun `test load project`() { val projectPath = FileUtilRt.toSystemIndependentName(File(PathManagerEx.getTestDataPath(), "moduleRootManager/unloadedModules").absolutePath) @@ -44,7 +45,7 @@ class UnloadedModulesConfigurationTest : JavaModuleTestCase() { assertEquals("$projectDirUrl/dep", assertOneElement(dep.contentRoots).url) assertEquals("util", assertOneElement(dep.dependencyModuleNames)) - assertSameElements(WorkspaceModel.getInstance(project).currentSnapshotOfUnloadedEntities.entities( + assertSameElements(WorkspaceModel.getInstance(project).internal.currentSnapshotOfUnloadedEntities.entities( ModuleEntity::class.java).map { it.name }.toList(), "dep", "util") } @@ -173,14 +174,14 @@ class UnloadedModulesConfigurationTest : JavaModuleTestCase() { assertEmpty(entityStorage.entities(LibraryEntity::class.java).toList()) assertEquals("a", unloadedModuleEntities.single().name) - val unloadedStorage = WorkspaceModel.getInstance(project).currentSnapshotOfUnloadedEntities + val unloadedStorage = WorkspaceModel.getInstance(project).internal.currentSnapshotOfUnloadedEntities assertEquals("lib", unloadedStorage.entities(LibraryEntity::class.java).single().name) runWithModalProgressBlocking(project, "") { moduleManager.setUnloadedModules(listOf()) } assertEmpty(unloadedModuleEntities) - assertEmpty(WorkspaceModel.getInstance(project).currentSnapshotOfUnloadedEntities.entities(LibraryEntity::class.java).toList()) + assertEmpty(WorkspaceModel.getInstance(project).internal.currentSnapshotOfUnloadedEntities.entities(LibraryEntity::class.java).toList()) assertEquals("lib", WorkspaceModel.getInstance(project).currentSnapshot.entities(LibraryEntity::class.java).single().name) } } \ No newline at end of file diff --git a/platform/backend/workspace/src/WorkspaceModel.kt b/platform/backend/workspace/src/WorkspaceModel.kt index 7e83e0fc55ca..a87953704bcb 100644 --- a/platform/backend/workspace/src/WorkspaceModel.kt +++ b/platform/backend/workspace/src/WorkspaceModel.kt @@ -51,14 +51,6 @@ public interface WorkspaceModel { @get:ApiStatus.Experimental public val changesEventFlow: Flow - /** - * Returns a snapshot of the storage containing unloaded entities. - * Unloaded entities must be ignored by almost all code in the IDE, so this property isn't supposed for general use. - * - * Currently, unloaded entities correspond to modules which are unloaded using 'Load/Unload Modules' action. - */ - public val currentSnapshotOfUnloadedEntities: ImmutableEntityStorage - /** * Modifies the current model by calling [updater] and applying it to the storage. Requires write action. * @@ -67,12 +59,6 @@ public interface WorkspaceModel { */ public fun updateProjectModel(description: @NonNls String, updater: (MutableEntityStorage) -> Unit) - /** - * Modifies the current model of unloaded entities by calling [updater] and applying it to the storage. - * @param description describes the reason for the change, used for logging purposes only. - */ - public fun updateUnloadedEntities(description: @NonNls String, updater: (MutableEntityStorage) -> Unit) - /** * **Asynchronous** modification of the current model by calling [updater] and applying it to the storage. * @@ -81,45 +67,6 @@ public interface WorkspaceModel { @ApiStatus.Experimental public suspend fun update(description: @NonNls String, updater: (MutableEntityStorage) -> Unit) - /** - * Get builder that can be updated in background and applied later and a project model. - * - * @see [WorkspaceModel.replaceProjectModel] - */ - public fun getBuilderSnapshot(): BuilderSnapshot - - /** - * Replace current project model with the new version from storage snapshot. - * - * This operation requires write lock. - * The snapshot replacement is performed using positive lock. If the project model was updated since [getBuilderSnapshot], snapshot - * won't be applied and this method will return false. In this case client should get a newer version of snapshot builder, apply changes - * and try to call [replaceProjectModel]. - * Keep in mind that you may not need to start the full builder update process (e.g. gradle sync) and the newer version of the builder - * can be updated using [MutableEntityStorage.applyChangesFrom] or [MutableEntityStorage.replaceBySource], but you have to be - * sure that the changes will be applied to the new builder correctly. - * - * The calculation of changes will be performed during [BuilderSnapshot.getStorageReplacement]. This method only replaces the project model - * and sends corresponding events. - * - * Example: - * ``` - * val builderSnapshot = projectModel.getBuilderSnapshot() - * - * update(builderSnapshot) - * - * val storageSnapshot = builderSnapshot.getStorageReplacement() - * val updated = writeLock { projectModel.replaceProjectModel(storageSnapshot) } - * - * if (!updated) error("Project model updates too fast") - * ``` - * - * Future plans: add some kind of ordering for async updates of the project model - * - * @see [WorkspaceModel.getBuilderSnapshot] - */ - public fun replaceProjectModel(replacement: StorageReplacement): Boolean - public companion object { @JvmStatic public fun getInstance(project: Project): WorkspaceModel = project.service() diff --git a/platform/backend/workspace/src/impl/WorkspaceModelInternal.kt b/platform/backend/workspace/src/impl/WorkspaceModelInternal.kt new file mode 100644 index 000000000000..df2e5941261f --- /dev/null +++ b/platform/backend/workspace/src/impl/WorkspaceModelInternal.kt @@ -0,0 +1,75 @@ +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.platform.backend.workspace.impl + +import com.intellij.platform.backend.workspace.BuilderSnapshot +import com.intellij.platform.backend.workspace.StorageReplacement +import com.intellij.platform.backend.workspace.WorkspaceModel +import com.intellij.platform.workspace.storage.ImmutableEntityStorage +import com.intellij.platform.workspace.storage.MutableEntityStorage +import com.intellij.platform.workspace.storage.impl.VersionedEntityStorageImpl +import org.jetbrains.annotations.ApiStatus +import org.jetbrains.annotations.NonNls + +/** + * This interface is created only for internal use. + */ +@ApiStatus.Internal +public interface WorkspaceModelInternal: WorkspaceModel { + public val entityStorage: VersionedEntityStorageImpl + + /** + * Returns a snapshot of the storage containing unloaded entities. + * Unloaded entities must be ignored by almost all code in the IDE, so this property isn't supposed for general use. + * + * Currently, unloaded entities correspond to modules which are unloaded using 'Load/Unload Modules' action. + */ + public val currentSnapshotOfUnloadedEntities: ImmutableEntityStorage + + /** + * Modifies the current model of unloaded entities by calling [updater] and applying it to the storage. + * @param description describes the reason for the change, used for logging purposes only. + */ + public fun updateUnloadedEntities(description: @NonNls String, updater: (MutableEntityStorage) -> Unit) + + /** + * Get builder that can be updated in background and applied later and a project model. + * + * @see [WorkspaceModel.replaceProjectModel] + */ + public fun getBuilderSnapshot(): BuilderSnapshot + + /** + * Replace current project model with the new version from storage snapshot. + * + * This operation requires write lock. + * The snapshot replacement is performed using positive lock. If the project model was updated since [getBuilderSnapshot], snapshot + * won't be applied and this method will return false. In this case client should get a newer version of snapshot builder, apply changes + * and try to call [replaceProjectModel]. + * Keep in mind that you may not need to start the full builder update process (e.g. gradle sync) and the newer version of the builder + * can be updated using [MutableEntityStorage.applyChangesFrom] or [MutableEntityStorage.replaceBySource], but you have to be + * sure that the changes will be applied to the new builder correctly. + * + * The calculation of changes will be performed during [BuilderSnapshot.getStorageReplacement]. This method only replaces the project model + * and sends corresponding events. + * + * Example: + * ``` + * val builderSnapshot = projectModel.getBuilderSnapshot() + * + * update(builderSnapshot) + * + * val storageSnapshot = builderSnapshot.getStorageReplacement() + * val updated = writeLock { projectModel.replaceProjectModel(storageSnapshot) } + * + * if (!updated) error("Project model updates too fast") + * ``` + * + * Future plans: add some kind of ordering for async updates of the project model + * + * @see [WorkspaceModel.getBuilderSnapshot] + */ + public fun replaceProjectModel(replacement: StorageReplacement): Boolean +} + +@get:ApiStatus.Internal +public val WorkspaceModel.internal: WorkspaceModelInternal get() = this as WorkspaceModelInternal \ No newline at end of file diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/IdeModifiableModelsProviderImpl.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/IdeModifiableModelsProviderImpl.java index 3a4288966205..783dfd7d7ae0 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/IdeModifiableModelsProviderImpl.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/IdeModifiableModelsProviderImpl.java @@ -22,11 +22,11 @@ import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Key; import com.intellij.platform.backend.workspace.WorkspaceModel; +import com.intellij.platform.backend.workspace.impl.WorkspaceModelInternal; import com.intellij.platform.workspace.storage.EntityStorageKt; import com.intellij.platform.workspace.storage.MutableEntityStorage; import com.intellij.platform.workspace.storage.VersionedEntityStorage; import com.intellij.util.containers.ClassMap; -import com.intellij.workspaceModel.ide.impl.WorkspaceModelImpl; import com.intellij.workspaceModel.ide.impl.legacyBridge.facet.FacetManagerBridge; import com.intellij.workspaceModel.ide.impl.legacyBridge.library.LibraryBridge; import com.intellij.workspaceModel.ide.impl.legacyBridge.module.ModuleManagerBridgeImpl; @@ -213,7 +213,7 @@ public class IdeModifiableModelsProviderImpl extends AbstractIdeModifiableModels public MutableEntityStorage getActualStorageBuilder() { if (diff != null) return diff; - VersionedEntityStorage storage = ((WorkspaceModelImpl)WorkspaceModel.getInstance(myProject)).getEntityStorage(); + VersionedEntityStorage storage = ((WorkspaceModelInternal)WorkspaceModel.getInstance(myProject)).getEntityStorage(); LOG.info("Ide modifiable models provider, create builder from version " + storage.getVersion()); var initialStorage = storage.getCurrent(); return diff = MutableEntityStorage.from(EntityStorageKt.toSnapshot(initialStorage)); diff --git a/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/service/project/manage/SourceFolderManagerTest.kt b/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/service/project/manage/SourceFolderManagerTest.kt index 9731a60b855c..356508bee003 100644 --- a/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/service/project/manage/SourceFolderManagerTest.kt +++ b/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/service/project/manage/SourceFolderManagerTest.kt @@ -12,10 +12,10 @@ import com.intellij.openapi.vfs.VfsUtilCore import com.intellij.platform.backend.workspace.WorkspaceModel import com.intellij.platform.backend.workspace.WorkspaceModelChangeListener import com.intellij.platform.backend.workspace.WorkspaceModelTopics +import com.intellij.platform.backend.workspace.impl.internal import com.intellij.platform.workspace.storage.VersionedStorageChange import com.intellij.testFramework.HeavyPlatformTestCase import com.intellij.testFramework.PlatformTestUtil -import com.intellij.workspaceModel.ide.impl.WorkspaceModelImpl import junit.framework.TestCase import org.assertj.core.api.BDDAssertions.then import org.jetbrains.jps.model.java.JavaSourceRootType @@ -90,7 +90,7 @@ class SourceFolderManagerTest: HeavyPlatformTestCase() { manager.addSourceFolder(secondModule, secondFolderUrl, JavaSourceRootType.SOURCE) var notificationsCount = 0 - val version = (WorkspaceModel.getInstance(project) as WorkspaceModelImpl).entityStorage.version + val version = WorkspaceModel.getInstance(project).internal.entityStorage.version project.messageBus.connect().subscribe(WorkspaceModelTopics.CHANGED, object : WorkspaceModelChangeListener { override fun changed(event: VersionedStorageChange) { notificationsCount++ @@ -99,7 +99,7 @@ class SourceFolderManagerTest: HeavyPlatformTestCase() { LocalFileSystem.getInstance().refresh(false) manager.consumeBulkOperationsState { PlatformTestUtil.waitForFuture(it, 1000)} TestCase.assertTrue(notificationsCount == 1) - TestCase.assertTrue(version + 1 == (WorkspaceModel.getInstance(project) as WorkspaceModelImpl).entityStorage.version) + TestCase.assertTrue(version + 1 == WorkspaceModel.getInstance(project).internal.entityStorage.version) } private fun createModuleWithContentRoot(dir: File, moduleName: String = "topModule"): Module { diff --git a/platform/lang-impl/src/com/intellij/workspaceModel/ide/impl/FileReferenceInWorkspaceEntityUpdater.kt b/platform/lang-impl/src/com/intellij/workspaceModel/ide/impl/FileReferenceInWorkspaceEntityUpdater.kt index 561df6078a23..d8c80abf9fe1 100644 --- a/platform/lang-impl/src/com/intellij/workspaceModel/ide/impl/FileReferenceInWorkspaceEntityUpdater.kt +++ b/platform/lang-impl/src/com/intellij/workspaceModel/ide/impl/FileReferenceInWorkspaceEntityUpdater.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.workspaceModel.ide.impl import com.google.common.io.Files @@ -16,6 +16,7 @@ import com.intellij.openapi.vfs.newvfs.events.VFileEvent import com.intellij.openapi.vfs.newvfs.events.VFileMoveEvent import com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent import com.intellij.platform.backend.workspace.WorkspaceModel +import com.intellij.platform.backend.workspace.impl.internal import com.intellij.platform.workspace.jps.entities.ModuleId import com.intellij.platform.workspace.jps.entities.modifyEntity import com.intellij.platform.workspace.jps.serialization.impl.ModulePath @@ -80,9 +81,9 @@ internal class FileReferenceInWorkspaceEntityUpdater(private val project: Projec diff.modifyEntity(moduleEntity) { this.name = newModuleName } } } - val unloadedModule = workspaceModel.currentSnapshotOfUnloadedEntities.resolve(oldModuleId) + val unloadedModule = workspaceModel.internal.currentSnapshotOfUnloadedEntities.resolve(oldModuleId) if (unloadedModule != null) { - workspaceModel.updateUnloadedEntities(description) { diff -> + workspaceModel.internal.updateUnloadedEntities(description) { diff -> diff.modifyEntity(unloadedModule) { this.name = newModuleName } } } diff --git a/platform/lang-impl/src/com/intellij/workspaceModel/ide/impl/legacyBridge/module/ModuleBridgeLoaderService.kt b/platform/lang-impl/src/com/intellij/workspaceModel/ide/impl/legacyBridge/module/ModuleBridgeLoaderService.kt index 8ce46ee71188..06752bd9da3c 100644 --- a/platform/lang-impl/src/com/intellij/workspaceModel/ide/impl/legacyBridge/module/ModuleBridgeLoaderService.kt +++ b/platform/lang-impl/src/com/intellij/workspaceModel/ide/impl/legacyBridge/module/ModuleBridgeLoaderService.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.workspaceModel.ide.impl.legacyBridge.module import com.intellij.openapi.application.writeAction @@ -14,6 +14,7 @@ import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar import com.intellij.platform.PlatformProjectOpenProcessor.Companion.PROJECT_LOADED_FROM_CACHE_BUT_HAS_NO_MODULES import com.intellij.platform.backend.workspace.WorkspaceModel import com.intellij.platform.backend.workspace.WorkspaceModelTopics +import com.intellij.platform.backend.workspace.impl.internal import com.intellij.platform.diagnostic.telemetry.helpers.addElapsedTimeMillis import com.intellij.platform.diagnostic.telemetry.impl.span import com.intellij.platform.workspace.jps.entities.ModuleEntity @@ -123,7 +124,7 @@ private suspend fun loadModules(project: Project, moduleManager.unloadNewlyAddedModulesIfPossible(targetBuilder, targetUnloadedEntitiesBuilder) } val entities = (targetBuilder ?: moduleManager.entityStore.current).entities(ModuleEntity::class.java).toList() - val unloadedEntities = (targetUnloadedEntitiesBuilder ?: WorkspaceModel.getInstance(project).currentSnapshotOfUnloadedEntities) + val unloadedEntities = (targetUnloadedEntitiesBuilder ?: WorkspaceModel.getInstance(project).internal.currentSnapshotOfUnloadedEntities) .entities(ModuleEntity::class.java) .toList() moduleManager.loadModules(loadedEntities = entities, diff --git a/platform/platform-impl/src/com/intellij/workspaceModel/ide/impl/WorkspaceModelCacheImpl.kt b/platform/platform-impl/src/com/intellij/workspaceModel/ide/impl/WorkspaceModelCacheImpl.kt index 8168897923c3..c71d02594b6f 100644 --- a/platform/platform-impl/src/com/intellij/workspaceModel/ide/impl/WorkspaceModelCacheImpl.kt +++ b/platform/platform-impl/src/com/intellij/workspaceModel/ide/impl/WorkspaceModelCacheImpl.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.workspaceModel.ide.impl import com.intellij.openapi.Disposable @@ -13,6 +13,7 @@ import com.intellij.platform.backend.workspace.WorkspaceModel import com.intellij.platform.backend.workspace.WorkspaceModelCache import com.intellij.platform.backend.workspace.WorkspaceModelChangeListener import com.intellij.platform.backend.workspace.WorkspaceModelTopics +import com.intellij.platform.backend.workspace.impl.internal import com.intellij.platform.workspace.storage.ImmutableEntityStorage import com.intellij.platform.workspace.storage.MutableEntityStorage import com.intellij.platform.workspace.storage.VersionedStorageChange @@ -95,7 +96,7 @@ class WorkspaceModelCacheImpl(private val project: Project, coroutineScope: Coro private fun doCacheSaving() { val storage = WorkspaceModel.getInstance(project).currentSnapshot - val unloadedStorage = WorkspaceModel.getInstance(project).currentSnapshotOfUnloadedEntities + val unloadedStorage = WorkspaceModel.getInstance(project).internal.currentSnapshotOfUnloadedEntities if (!storage.isConsistent || !unloadedStorage.isConsistent) { invalidateProjectCache() } diff --git a/platform/platform-impl/src/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsProjectModelSynchronizer.kt b/platform/platform-impl/src/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsProjectModelSynchronizer.kt index c52c09491e36..17658cb3921e 100644 --- a/platform/platform-impl/src/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsProjectModelSynchronizer.kt +++ b/platform/platform-impl/src/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsProjectModelSynchronizer.kt @@ -32,6 +32,7 @@ import com.intellij.platform.backend.workspace.WorkspaceModel import com.intellij.platform.backend.workspace.WorkspaceModelChangeListener import com.intellij.platform.backend.workspace.WorkspaceModelTopics import com.intellij.platform.backend.workspace.WorkspaceModelUnloadedStorageChangeListener +import com.intellij.platform.backend.workspace.impl.internal import com.intellij.platform.diagnostic.telemetry.helpers.addElapsedTimeMillis import com.intellij.platform.diagnostic.telemetry.helpers.addMeasuredTimeMillis import com.intellij.platform.workspace.jps.* @@ -160,12 +161,12 @@ class JpsProjectModelSynchronizer(private val project: Project) : Disposable { // Update builder of unloaded entities if ((reloadingResult.unloadedEntityBuilder as MutableEntityStorageInstrumentation).hasChanges()) { - WorkspaceModel.getInstance(project).updateUnloadedEntities(description) { builder -> + WorkspaceModel.getInstance(project).internal.updateUnloadedEntities(description) { builder -> builder.replaceBySource(affectedEntityFilter, reloadingResult.unloadedEntityBuilder.toSnapshot()) } } - val unloadedBuilder = MutableEntityStorage.from(WorkspaceModel.getInstance(project).currentSnapshotOfUnloadedEntities) + val unloadedBuilder = MutableEntityStorage.from(WorkspaceModel.getInstance(project).internal.currentSnapshotOfUnloadedEntities) WorkspaceModel.getInstance(project).updateProjectModel(description) { updater -> val storage = reloadingResult.builder.toSnapshot() updater.replaceBySource(affectedEntityFilter, storage) @@ -330,11 +331,11 @@ class JpsProjectModelSynchronizer(private val project: Project) : Disposable { || entitySource is DummyParentEntitySource } if ((projectEntities.unloadedEntitiesBuilder as MutableEntityStorageInstrumentation).hasChanges()) { - WorkspaceModel.getInstance(project).updateUnloadedEntities(description) { updater -> + WorkspaceModel.getInstance(project).internal.updateUnloadedEntities(description) { updater -> updater.replaceBySource(sourceFilter, projectEntities.unloadedEntitiesBuilder) } } - val unloadedBuilder = MutableEntityStorage.from(WorkspaceModel.getInstance(project).currentSnapshotOfUnloadedEntities) + val unloadedBuilder = MutableEntityStorage.from(WorkspaceModel.getInstance(project).internal.currentSnapshotOfUnloadedEntities) WorkspaceModel.getInstance(project).updateProjectModel(description) { updater -> updater.replaceBySource(sourceFilter, projectEntities.builder) childActivity = childActivity?.endAndStart("unloaded modules loading") @@ -366,7 +367,7 @@ class JpsProjectModelSynchronizer(private val project: Project) : Disposable { @OptIn(EntityStorageInstrumentationApi::class) private fun addUnloadedModuleEntities(diff: MutableEntityStorage) { if ((diff as MutableEntityStorageInstrumentation).hasChanges()) { - WorkspaceModel.getInstance(project).updateUnloadedEntities("Add new unloaded modules") { updater -> + WorkspaceModel.getInstance(project).internal.updateUnloadedEntities("Add new unloaded modules") { updater -> updater.applyChangesFrom(diff) } } @@ -408,7 +409,7 @@ class JpsProjectModelSynchronizer(private val project: Project) : Disposable { return@addMeasuredTimeMillis } val storage = WorkspaceModel.getInstance(project).currentSnapshot - val unloadedEntitiesStorage = WorkspaceModel.getInstance(project).currentSnapshotOfUnloadedEntities + val unloadedEntitiesStorage = WorkspaceModel.getInstance(project).internal.currentSnapshotOfUnloadedEntities val affectedSources = synchronized(sourcesToSave) { val copy = HashSet(sourcesToSave) sourcesToSave.clear() @@ -424,7 +425,7 @@ class JpsProjectModelSynchronizer(private val project: Project) : Disposable { newSerializers.changeEntitySourcesToDirectoryBasedFormat(it) } val moduleSources = WorkspaceModel.getInstance(project).currentSnapshot.entities(ModuleEntity::class.java).map { it.entitySource } - val unloadedModuleSources = WorkspaceModel.getInstance(project).currentSnapshotOfUnloadedEntities.entities( + val unloadedModuleSources = WorkspaceModel.getInstance(project).internal.currentSnapshotOfUnloadedEntities.entities( ModuleEntity::class.java).map { it.entitySource } synchronized(sourcesToSave) { // trigger save for modules.xml @@ -437,7 +438,7 @@ class JpsProjectModelSynchronizer(private val project: Project) : Disposable { @TestOnly fun markAllEntitiesAsDirty() { val allSources = WorkspaceModel.getInstance(project).currentSnapshot.entitiesBySource { true }.mapTo(HashSet()) { it.entitySource } + - WorkspaceModel.getInstance(project).currentSnapshotOfUnloadedEntities.entitiesBySource { true }.mapTo( + WorkspaceModel.getInstance(project).internal.currentSnapshotOfUnloadedEntities.entitiesBySource { true }.mapTo( HashSet()) { it.entitySource } synchronized(sourcesToSave) { sourcesToSave.addAll(allSources) diff --git a/platform/projectModel-impl/src/com/intellij/workspaceModel/core/fileIndex/impl/WorkspaceFileIndexDataImpl.kt b/platform/projectModel-impl/src/com/intellij/workspaceModel/core/fileIndex/impl/WorkspaceFileIndexDataImpl.kt index e38a1a2a02a1..6d285b55d2b8 100644 --- a/platform/projectModel-impl/src/com/intellij/workspaceModel/core/fileIndex/impl/WorkspaceFileIndexDataImpl.kt +++ b/platform/projectModel-impl/src/com/intellij/workspaceModel/core/fileIndex/impl/WorkspaceFileIndexDataImpl.kt @@ -10,6 +10,7 @@ import com.intellij.openapi.roots.impl.RootFileSupplier import com.intellij.openapi.vfs.* import com.intellij.openapi.vfs.newvfs.events.VFileEvent import com.intellij.platform.backend.workspace.WorkspaceModel +import com.intellij.platform.backend.workspace.impl.internal import com.intellij.platform.diagnostic.telemetry.helpers.addElapsedTimeNanosec import com.intellij.platform.diagnostic.telemetry.helpers.addMeasuredTimeMillis import com.intellij.platform.diagnostic.telemetry.helpers.addMeasuredTimeNanosec @@ -62,7 +63,7 @@ internal class WorkspaceFileIndexDataImpl(private val contributorList: List WorkspaceModel.getInstance(project).currentSnapshot to contributors - EntityStorageKind.UNLOADED -> WorkspaceModel.getInstance(project).currentSnapshotOfUnloadedEntities to contributorsForUnloaded + EntityStorageKind.UNLOADED -> WorkspaceModel.getInstance(project).internal.currentSnapshotOfUnloadedEntities to contributorsForUnloaded } val registrar = StoreFileSetsRegistrarImpl(storageKind) diff --git a/platform/projectModel-impl/src/com/intellij/workspaceModel/ide/impl/WorkspaceModelImpl.kt b/platform/projectModel-impl/src/com/intellij/workspaceModel/ide/impl/WorkspaceModelImpl.kt index 4c4175e0a727..c63406f51d44 100644 --- a/platform/projectModel-impl/src/com/intellij/workspaceModel/ide/impl/WorkspaceModelImpl.kt +++ b/platform/projectModel-impl/src/com/intellij/workspaceModel/ide/impl/WorkspaceModelImpl.kt @@ -12,6 +12,7 @@ import com.intellij.openapi.extensions.ExtensionPointName import com.intellij.openapi.project.Project import com.intellij.openapi.util.registry.Registry import com.intellij.platform.backend.workspace.* +import com.intellij.platform.backend.workspace.impl.WorkspaceModelInternal import com.intellij.platform.diagnostic.telemetry.helpers.addElapsedTimeMillis import com.intellij.platform.diagnostic.telemetry.helpers.addMeasuredTimeMillis import com.intellij.platform.workspace.storage.* @@ -36,12 +37,12 @@ import java.util.concurrent.atomic.AtomicLong import kotlin.system.measureTimeMillis @ApiStatus.Internal -open class WorkspaceModelImpl(private val project: Project, private val cs: CoroutineScope) : WorkspaceModel, Disposable { +open class WorkspaceModelImpl(private val project: Project, private val cs: CoroutineScope) : WorkspaceModelInternal, Disposable { @Volatile var loadedFromCache = false protected set - val entityStorage: VersionedEntityStorageImpl + final override val entityStorage: VersionedEntityStorageImpl private val unloadedEntitiesStorage: VersionedEntityStorageImpl private val updatesFlow = MutableSharedFlow() diff --git a/platform/projectModel-impl/src/com/intellij/workspaceModel/ide/impl/legacyBridge/library/ProjectLibraryTableBridgeImpl.kt b/platform/projectModel-impl/src/com/intellij/workspaceModel/ide/impl/legacyBridge/library/ProjectLibraryTableBridgeImpl.kt index eb32dc2f1c51..4046325dd856 100644 --- a/platform/projectModel-impl/src/com/intellij/workspaceModel/ide/impl/legacyBridge/library/ProjectLibraryTableBridgeImpl.kt +++ b/platform/projectModel-impl/src/com/intellij/workspaceModel/ide/impl/legacyBridge/library/ProjectLibraryTableBridgeImpl.kt @@ -16,6 +16,7 @@ import com.intellij.platform.backend.workspace.BridgeInitializer import com.intellij.platform.backend.workspace.WorkspaceModel import com.intellij.platform.backend.workspace.WorkspaceModelChangeListener import com.intellij.platform.backend.workspace.WorkspaceModelTopics +import com.intellij.platform.backend.workspace.impl.internal import com.intellij.platform.workspace.jps.entities.LibraryEntity import com.intellij.platform.workspace.jps.entities.LibraryId import com.intellij.platform.workspace.jps.entities.LibraryTableId @@ -44,7 +45,7 @@ class ProjectLibraryTableBridgeInitializer : BridgeInitializer { libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(project), project = project, initialId = addChange.entity.symbolicId, - initialEntityStorage = (WorkspaceModel.getInstance(project) as WorkspaceModelImpl).entityStorage, + initialEntityStorage = WorkspaceModel.getInstance(project).internal.entityStorage, targetBuilder = builder ) } @@ -56,7 +57,7 @@ class ProjectLibraryTableBridgeImpl( private val parentProject: Project ) : ProjectLibraryTableBridge, Disposable { - private val entityStorage: VersionedEntityStorage = (WorkspaceModel.getInstance(parentProject) as WorkspaceModelImpl).entityStorage + private val entityStorage: VersionedEntityStorage = WorkspaceModel.getInstance(parentProject).internal.entityStorage private val dispatcher = EventDispatcher.create(LibraryTable.Listener::class.java) diff --git a/platform/projectModel-impl/src/com/intellij/workspaceModel/ide/impl/legacyBridge/module/LegacyProjectModelListenersBridge.kt b/platform/projectModel-impl/src/com/intellij/workspaceModel/ide/impl/legacyBridge/module/LegacyProjectModelListenersBridge.kt index feb4214d956f..8b01ae7e0580 100644 --- a/platform/projectModel-impl/src/com/intellij/workspaceModel/ide/impl/legacyBridge/module/LegacyProjectModelListenersBridge.kt +++ b/platform/projectModel-impl/src/com/intellij/workspaceModel/ide/impl/legacyBridge/module/LegacyProjectModelListenersBridge.kt @@ -13,12 +13,12 @@ import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.SimpleModificationTracker import com.intellij.platform.backend.workspace.WorkspaceModel import com.intellij.platform.backend.workspace.WorkspaceModelChangeListener +import com.intellij.platform.backend.workspace.impl.internal import com.intellij.platform.workspace.jps.entities.LibraryEntity import com.intellij.platform.workspace.jps.entities.ModuleEntity import com.intellij.platform.workspace.jps.entities.ModuleId import com.intellij.platform.workspace.storage.EntityChange import com.intellij.platform.workspace.storage.VersionedStorageChange -import com.intellij.workspaceModel.ide.impl.WorkspaceModelImpl import com.intellij.workspaceModel.ide.impl.legacyBridge.library.LibraryBridgeImpl import com.intellij.workspaceModel.ide.impl.legacyBridge.library.ProjectLibraryTableBridgeImpl.Companion.libraryMap import com.intellij.workspaceModel.ide.impl.legacyBridge.module.ModuleManagerBridgeImpl.Companion.filterModuleLibraryChanges @@ -115,7 +115,7 @@ internal class LegacyProjectModelListenersBridge( removeUnloadedModuleWithId(change.entity.symbolicId) val alreadyCreatedModule = change.entity.findModule(event.storageAfter) val module = if (alreadyCreatedModule != null) { - alreadyCreatedModule.entityStorage = (WorkspaceModel.getInstance(project) as WorkspaceModelImpl).entityStorage + alreadyCreatedModule.entityStorage = WorkspaceModel.getInstance(project).internal.entityStorage alreadyCreatedModule.diff = null alreadyCreatedModule } @@ -152,9 +152,9 @@ internal class LegacyProjectModelListenersBridge( } private fun removeUnloadedModuleWithId(moduleId: ModuleId) { - val unloadedEntity = WorkspaceModel.getInstance(project).currentSnapshotOfUnloadedEntities.resolve(moduleId) + val unloadedEntity = WorkspaceModel.getInstance(project).internal.currentSnapshotOfUnloadedEntities.resolve(moduleId) if (unloadedEntity != null) { - WorkspaceModel.getInstance(project).updateUnloadedEntities( + WorkspaceModel.getInstance(project).internal.updateUnloadedEntities( "Remove module '${moduleId.name}' from unloaded storage because a module with same name is added") { it.removeEntity(unloadedEntity) } @@ -184,7 +184,7 @@ internal class LegacyProjectModelListenersBridge( is EntityChange.Added -> { val library = event.storageAfter.libraryMap.getDataByEntity(change.entity) if (library != null) { - (library as LibraryBridgeImpl).entityStorage = (WorkspaceModel.getInstance(project) as WorkspaceModelImpl).entityStorage + (library as LibraryBridgeImpl).entityStorage = WorkspaceModel.getInstance(project).internal.entityStorage library.clearTargetBuilder() } } diff --git a/platform/projectModel-impl/src/com/intellij/workspaceModel/ide/impl/legacyBridge/module/ModuleManagerBridgeImpl.kt b/platform/projectModel-impl/src/com/intellij/workspaceModel/ide/impl/legacyBridge/module/ModuleManagerBridgeImpl.kt index 9ad7b6904ae8..d105d0b66645 100644 --- a/platform/projectModel-impl/src/com/intellij/workspaceModel/ide/impl/legacyBridge/module/ModuleManagerBridgeImpl.kt +++ b/platform/projectModel-impl/src/com/intellij/workspaceModel/ide/impl/legacyBridge/module/ModuleManagerBridgeImpl.kt @@ -26,6 +26,7 @@ import com.intellij.openapi.roots.ModuleRootManager import com.intellij.openapi.roots.ex.ProjectRootManagerEx import com.intellij.openapi.util.Disposer import com.intellij.platform.backend.workspace.* +import com.intellij.platform.backend.workspace.impl.internal import com.intellij.platform.diagnostic.telemetry.helpers.addMeasuredTimeMillis import com.intellij.platform.workspace.jps.CustomModuleEntitySource import com.intellij.platform.workspace.jps.JpsFileDependentEntitySource @@ -125,7 +126,7 @@ abstract class ModuleManagerBridgeImpl(private val project: Project, return entityStore.cachedValue(if (includeTests) dependencyGraphWithTestsValue else dependencyGraphWithoutTestsValue) } - val entityStore: VersionedEntityStorage = (WorkspaceModel.getInstance(project) as WorkspaceModelImpl).entityStorage + val entityStore: VersionedEntityStorage = WorkspaceModel.getInstance(project).internal.entityStorage suspend fun loadModules(loadedEntities: List, unloadedEntities: List, @@ -300,7 +301,7 @@ abstract class ModuleManagerBridgeImpl(private val project: Project, val moduleEntitiesToUnload = mainStorage.entities(ModuleEntity::class.java) .filter { unloadedModulesNameHolder.isUnloaded(it.name) } .toList() - val unloadedEntityStorage = WorkspaceModel.getInstance(project).currentSnapshotOfUnloadedEntities + val unloadedEntityStorage = WorkspaceModel.getInstance(project).internal.currentSnapshotOfUnloadedEntities val moduleEntitiesToLoad = unloadedEntityStorage.entities(ModuleEntity::class.java) .filter { !unloadedModulesNameHolder.isUnloaded(it.name) } .toList() @@ -335,7 +336,7 @@ abstract class ModuleManagerBridgeImpl(private val project: Project, WorkspaceModel.getInstance(project).updateProjectModel("Update unloaded modules") { builder -> addAndRemoveModules(builder, moduleEntitiesToLoad, moduleEntitiesToUnload, unloadedEntityStorage) } - WorkspaceModel.getInstance(project).updateUnloadedEntities("Update unloaded modules") { builder -> + WorkspaceModel.getInstance(project).internal.updateUnloadedEntities("Update unloaded modules") { builder -> addAndRemoveModules(builder, moduleEntitiesToUnload, moduleEntitiesToLoad, mainStorage) } } @@ -381,7 +382,7 @@ abstract class ModuleManagerBridgeImpl(private val project: Project, unloadedModules.forEach { this.moduleNameToUnloadedModuleDescription.remove(it.name) } UnloadedModulesListStorage.getInstance(project).setUnloadedModuleNames(this.moduleNameToUnloadedModuleDescription.keys) - WorkspaceModel.getInstance(project).updateUnloadedEntities("Remove unloaded modules") { builder -> + WorkspaceModel.getInstance(project).internal.updateUnloadedEntities("Remove unloaded modules") { builder -> val namesToRemove = unloadedModules.mapTo(HashSet()) { it.name } val entitiesToRemove = builder.entities(ModuleEntity::class.java).filter { it.name in namesToRemove }.toList() for (moduleEntity in entitiesToRemove) { diff --git a/platform/projectModel-impl/src/com/intellij/workspaceModel/ide/impl/legacyBridge/module/roots/ModifiableModuleLibraryTableBridge.kt b/platform/projectModel-impl/src/com/intellij/workspaceModel/ide/impl/legacyBridge/module/roots/ModifiableModuleLibraryTableBridge.kt index 834127caa99c..1deea4247af7 100644 --- a/platform/projectModel-impl/src/com/intellij/workspaceModel/ide/impl/legacyBridge/module/roots/ModifiableModuleLibraryTableBridge.kt +++ b/platform/projectModel-impl/src/com/intellij/workspaceModel/ide/impl/legacyBridge/module/roots/ModifiableModuleLibraryTableBridge.kt @@ -10,9 +10,9 @@ import com.intellij.openapi.roots.libraries.Library import com.intellij.openapi.roots.libraries.PersistentLibraryKind import com.intellij.openapi.util.Disposer import com.intellij.platform.backend.workspace.WorkspaceModel +import com.intellij.platform.backend.workspace.impl.internal import com.intellij.platform.workspace.jps.entities.* import com.intellij.platform.workspace.jps.serialization.impl.LibraryNameGenerator -import com.intellij.workspaceModel.ide.impl.WorkspaceModelImpl import com.intellij.workspaceModel.ide.impl.legacyBridge.LegacyBridgeModifiableBase import com.intellij.workspaceModel.ide.impl.legacyBridge.library.LibraryBridge import com.intellij.workspaceModel.ide.impl.legacyBridge.library.LibraryBridgeImpl @@ -195,7 +195,7 @@ internal class ModifiableModuleLibraryTableBridge(private val modifiableModel: M internal fun disposeOriginalLibrariesAndUpdateCopies() { if (copyToOriginal.isEmpty()) return - val storage = (WorkspaceModel.getInstance(modifiableModel.project) as WorkspaceModelImpl).entityStorage + val storage = WorkspaceModel.getInstance(modifiableModel.project).internal.entityStorage copyToOriginal.forEach { (copyBridge, originBridge) -> // It's possible if we removed old library, its copy will be disposed [ModifiableModuleLibraryTableBridge.removeLibrary] // but original bridge will be disposed in during events handling. This method will be called the last thus both of them will be disposed diff --git a/platform/workspace/jps/tests/testSrc/com/intellij/workspaceModel/ide/ModuleBridgesTest.kt b/platform/workspace/jps/tests/testSrc/com/intellij/workspaceModel/ide/ModuleBridgesTest.kt index 28a53c9bd9c1..2804fbb26c49 100644 --- a/platform/workspace/jps/tests/testSrc/com/intellij/workspaceModel/ide/ModuleBridgesTest.kt +++ b/platform/workspace/jps/tests/testSrc/com/intellij/workspaceModel/ide/ModuleBridgesTest.kt @@ -16,6 +16,7 @@ import com.intellij.openapi.util.NlsSafe import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.vfs.VfsUtilCore import com.intellij.platform.backend.workspace.* +import com.intellij.platform.backend.workspace.impl.internal import com.intellij.platform.workspace.jps.JpsEntitySourceFactory import com.intellij.platform.workspace.jps.JpsProjectFileEntitySource import com.intellij.platform.workspace.jps.entities.* @@ -34,7 +35,6 @@ import com.intellij.testFramework.rules.TempDirectory import com.intellij.testFramework.workspaceModel.updateProjectModel import com.intellij.util.io.write import com.intellij.util.ui.UIUtil -import com.intellij.workspaceModel.ide.impl.WorkspaceModelImpl import com.intellij.workspaceModel.ide.impl.WorkspaceModelInitialTestContent import com.intellij.workspaceModel.ide.impl.jps.serialization.toConfigLocation import com.intellij.workspaceModel.ide.impl.legacyBridge.module.ModuleManagerBridgeImpl @@ -89,7 +89,7 @@ class ModuleBridgesTest { val module = projectModel.createModule() as ModuleBridge assertTrue(moduleManager.modules.contains(module)) - assertSame((WorkspaceModel.getInstance(project) as WorkspaceModelImpl).entityStorage, module.entityStorage) + assertSame(WorkspaceModel.getInstance(project).internal.entityStorage, module.entityStorage) val contentRootUrl = temporaryDirectoryRule.newDirectoryPath("contentRoot").toVirtualFileUrl(virtualFileManager) @@ -688,7 +688,7 @@ class ModuleBridgesTest { withContext(Dispatchers.EDT) { assertTrue(moduleFile.readText().contains(antLibraryFolder)) - val entityStore = (WorkspaceModel.getInstance(project) as WorkspaceModelImpl).entityStorage + val entityStore = WorkspaceModel.getInstance(project).internal.entityStorage assertEquals(1, entityStore.current.entities(ContentRootEntity::class.java).count()) assertEquals(1, entityStore.current.entities(JavaSourceRootPropertiesEntity::class.java).count()) @@ -716,7 +716,7 @@ class ModuleBridgesTest { contentEntry.addSourceFolder("$url/$antLibraryFolder", false) } - val entityStore = (WorkspaceModel.getInstance(project) as WorkspaceModelImpl).entityStorage + val entityStore = WorkspaceModel.getInstance(project).internal.entityStorage assertEquals(1, entityStore.current.entities(ContentRootEntity::class.java).count()) assertEquals(1, entityStore.current.entities(SourceRootEntity::class.java).count()) diff --git a/platform/workspace/jps/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceModelBenchmarksPerformanceTest.kt b/platform/workspace/jps/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceModelBenchmarksPerformanceTest.kt index 17b129632b7e..400c7dc2b2b2 100644 --- a/platform/workspace/jps/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceModelBenchmarksPerformanceTest.kt +++ b/platform/workspace/jps/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceModelBenchmarksPerformanceTest.kt @@ -8,6 +8,7 @@ import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.registry.Registry import com.intellij.openapi.vfs.VfsUtil import com.intellij.platform.backend.workspace.WorkspaceModel +import com.intellij.platform.backend.workspace.impl.internal import com.intellij.platform.backend.workspace.workspaceModel import com.intellij.platform.workspace.jps.JpsProjectConfigLocation import com.intellij.platform.workspace.jps.OrphanageWorkerEntitySource @@ -434,9 +435,9 @@ class WorkspaceModelBenchmarksPerformanceTest { PlatformTestUtil.startPerformanceTest(testInfo.displayName, 100500) { runWriteActionAndWait { repeat(1000) { - val builderSnapshot = WorkspaceModel.getInstance(projectModel.project).getBuilderSnapshot() + val builderSnapshot = WorkspaceModel.getInstance(projectModel.project).internal.getBuilderSnapshot() builderSnapshot.builder addEntity ModuleEntity("Module$it", emptyList(), MySource) - WorkspaceModel.getInstance(projectModel.project).replaceProjectModel(builderSnapshot.getStorageReplacement()) + WorkspaceModel.getInstance(projectModel.project).internal.replaceProjectModel(builderSnapshot.getStorageReplacement()) } } } diff --git a/platform/workspace/jps/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceModelTest.kt b/platform/workspace/jps/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceModelTest.kt index 0e3668b9f26b..fa2380a2bf70 100644 --- a/platform/workspace/jps/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceModelTest.kt +++ b/platform/workspace/jps/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceModelTest.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.workspaceModel.ide import com.intellij.openapi.application.* @@ -9,13 +9,14 @@ import com.intellij.openapi.util.use import com.intellij.platform.backend.workspace.WorkspaceModel import com.intellij.platform.backend.workspace.WorkspaceModelChangeListener import com.intellij.platform.backend.workspace.WorkspaceModelTopics +import com.intellij.platform.backend.workspace.impl.internal +import com.intellij.platform.workspace.jps.entities.ModuleEntity +import com.intellij.platform.workspace.storage.EntitySource +import com.intellij.platform.workspace.storage.VersionedStorageChange import com.intellij.testFramework.ApplicationRule import com.intellij.testFramework.rules.ProjectModelRule import com.intellij.testFramework.workspaceModel.updateProjectModel import com.intellij.workspaceModel.ide.impl.WorkspaceModelImpl -import com.intellij.platform.workspace.storage.EntitySource -import com.intellij.platform.workspace.storage.VersionedStorageChange -import com.intellij.platform.workspace.jps.entities.ModuleEntity import junit.framework.Assert.* import org.junit.Assert import org.junit.ClassRule @@ -53,13 +54,13 @@ class WorkspaceModelTest { @Test fun `async model update`() { val model = WorkspaceModel.getInstance(projectModel.project) - val builderSnapshot = model.getBuilderSnapshot() + val builderSnapshot = model.internal.getBuilderSnapshot() builderSnapshot.builder addEntity ModuleEntity("MyModule", emptyList(), object : EntitySource {}) val replacement = builderSnapshot.getStorageReplacement() val updated = runWriteActionAndWait { - model.replaceProjectModel(replacement) + model.internal.replaceProjectModel(replacement) } assertTrue(updated) @@ -71,7 +72,7 @@ class WorkspaceModelTest { @Test fun `async model update with fail`() { val model = WorkspaceModel.getInstance(projectModel.project) - val builderSnapshot = model.getBuilderSnapshot() + val builderSnapshot = model.internal.getBuilderSnapshot() builderSnapshot.builder addEntity ModuleEntity("MyModule", emptyList(), object : EntitySource {}) val replacement = builderSnapshot.getStorageReplacement() @@ -83,7 +84,7 @@ class WorkspaceModelTest { } val updated = runWriteActionAndWait { - WorkspaceModel.getInstance(projectModel.project).replaceProjectModel(replacement) + WorkspaceModel.getInstance(projectModel.project).internal.replaceProjectModel(replacement) } assertFalse(updated) diff --git a/platform/workspace/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/DelayedProjectSynchronizerTest.kt b/platform/workspace/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/DelayedProjectSynchronizerTest.kt index 8201d70fd9d1..96a19361c746 100644 --- a/platform/workspace/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/DelayedProjectSynchronizerTest.kt +++ b/platform/workspace/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/DelayedProjectSynchronizerTest.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.workspaceModel.ide.impl.jps.serialization import com.intellij.facet.mock.AnotherMockFacetType @@ -15,6 +15,7 @@ import com.intellij.openapi.project.ex.ProjectManagerEx import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar import com.intellij.openapi.util.Disposer import com.intellij.platform.backend.workspace.WorkspaceModel +import com.intellij.platform.backend.workspace.impl.internal import com.intellij.platform.workspace.jps.JpsImportedEntitySource import com.intellij.platform.workspace.jps.JpsProjectFileEntitySource import com.intellij.platform.workspace.jps.entities.FacetEntity @@ -94,7 +95,7 @@ class DelayedProjectSynchronizerTest { private fun checkSerializersConsistency(project: Project) { val storage = WorkspaceModel.getInstance(project).currentSnapshot val serializers = JpsProjectModelSynchronizer.getInstance(project).getSerializers() - val unloadedEntitiesStorage = WorkspaceModel.getInstance(project).currentSnapshotOfUnloadedEntities + val unloadedEntitiesStorage = WorkspaceModel.getInstance(project).internal.currentSnapshotOfUnloadedEntities serializers.checkConsistency(getJpsProjectConfigLocation(project)!!, storage, unloadedEntitiesStorage, VirtualFileUrlManager.getInstance(project)) } diff --git a/plugins/kotlin/base/scripting/src/org/jetbrains/kotlin/idea/core/script/ucache/ScriptClassRootsUpdater.kt b/plugins/kotlin/base/scripting/src/org/jetbrains/kotlin/idea/core/script/ucache/ScriptClassRootsUpdater.kt index 9492123f5b76..07e867ccae31 100644 --- a/plugins/kotlin/base/scripting/src/org/jetbrains/kotlin/idea/core/script/ucache/ScriptClassRootsUpdater.kt +++ b/plugins/kotlin/base/scripting/src/org/jetbrains/kotlin/idea/core/script/ucache/ScriptClassRootsUpdater.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// 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.core.script.ucache @@ -16,6 +16,7 @@ import com.intellij.openapi.projectRoots.Sdk import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.VirtualFileManager import com.intellij.platform.backend.workspace.WorkspaceModel +import com.intellij.platform.backend.workspace.impl.internal import com.intellij.psi.PsiManager import com.intellij.refactoring.suggested.createSmartPointer import com.intellij.testFramework.LightVirtualFile @@ -293,14 +294,14 @@ abstract class ScriptClassRootsUpdater( ) { if (project.isDisposed) return - val builderSnapshot = WorkspaceModel.getInstance(project).getBuilderSnapshot() + val builderSnapshot = WorkspaceModel.getInstance(project).internal.getBuilderSnapshot() builderSnapshot.syncScriptEntities(project, filesToAddOrUpdate, filesToRemove) // time-consuming call val replacement = builderSnapshot.getStorageReplacement() runInEdt(ModalityState.nonModal()) { val replaced = runWriteAction { if (project.isDisposed) false - else WorkspaceModel.getInstance(project).replaceProjectModel(replacement) + else WorkspaceModel.getInstance(project).internal.replaceProjectModel(replacement) } if (!replaced) { // initiate update once again diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/workspaceModel/WorkspaceProjectImporter.kt b/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/workspaceModel/WorkspaceProjectImporter.kt index fe1dc66e0f43..3bd617ea588c 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/workspaceModel/WorkspaceProjectImporter.kt +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/workspaceModel/WorkspaceProjectImporter.kt @@ -27,6 +27,7 @@ import com.intellij.openapi.vfs.LocalFileSystem import com.intellij.openapi.vfs.VfsUtil import com.intellij.openapi.vfs.VirtualFile import com.intellij.platform.backend.workspace.WorkspaceModel +import com.intellij.platform.backend.workspace.impl.internal import com.intellij.platform.workspace.jps.JpsImportedEntitySource import com.intellij.platform.workspace.jps.entities.* import com.intellij.platform.workspace.jps.serialization.impl.FileInDirectorySourceNames @@ -605,7 +606,7 @@ internal class WorkspaceProjectImporter( prepareInBackground: (current: MutableEntityStorage) -> Unit, afterApplyInWriteAction: (storage: EntityStorage) -> Unit = {}) { val workspaceModel = WorkspaceModel.getInstance(project) - val prevStorageVersion = (WorkspaceModel.getInstance(project) as WorkspaceModelImpl).entityStorage.version + val prevStorageVersion = WorkspaceModel.getInstance(project).internal.entityStorage.version var attempts = 0 var durationInBackground = 0L @@ -618,7 +619,7 @@ internal class WorkspaceProjectImporter( attempts++ val beforeBG = System.nanoTime() - val snapshot = workspaceModel.getBuilderSnapshot() + val snapshot = workspaceModel.internal.getBuilderSnapshot() val builder = snapshot.builder prepareInBackground(builder) durationInBackground += System.nanoTime() - beforeBG @@ -629,7 +630,7 @@ internal class WorkspaceProjectImporter( updated = true } else { - updated = workspaceModel.replaceProjectModel(snapshot.getStorageReplacement()) + updated = workspaceModel.internal.replaceProjectModel(snapshot.getStorageReplacement()) durationOfWorkspaceUpdate = System.nanoTime() - beforeWA } if (updated) afterApplyInWriteAction(workspaceModel.currentSnapshot) @@ -657,7 +658,7 @@ internal class WorkspaceProjectImporter( durationInWriteActionNano = durationInWriteAction, durationOfWorkspaceUpdateCallNano = durationOfWorkspaceUpdate, attempts = attempts) - val newStorageVersion = (WorkspaceModel.getInstance(project) as WorkspaceModelImpl).entityStorage.version + val newStorageVersion = WorkspaceModel.getInstance(project).internal.entityStorage.version LOG.info("Project model updated to version ${newStorageVersion} (attempts: $attempts, previous version: $prevStorageVersion)") } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/performancePlugin/ImportMavenProjectCommand.kt b/plugins/maven/src/main/java/org/jetbrains/idea/maven/performancePlugin/ImportMavenProjectCommand.kt index a51ed08a7b03..341c71e10367 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/performancePlugin/ImportMavenProjectCommand.kt +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/performancePlugin/ImportMavenProjectCommand.kt @@ -12,9 +12,9 @@ import com.intellij.openapi.ui.playback.PlaybackContext import com.intellij.openapi.ui.playback.commands.AbstractCommand import com.intellij.openapi.util.ActionCallback import com.intellij.platform.backend.workspace.WorkspaceModel +import com.intellij.platform.backend.workspace.impl.internal import com.intellij.util.DisposeAwareRunnable import com.intellij.workspaceModel.ide.JpsProjectLoadingManager -import com.intellij.workspaceModel.ide.impl.WorkspaceModelImpl import com.jetbrains.performancePlugin.utils.ActionCallbackProfilerStopper import org.jetbrains.concurrency.Promise import org.jetbrains.concurrency.toPromise @@ -61,7 +61,7 @@ class ImportMavenProjectCommand(text: String, line: Int) : AbstractCommand(text, context.message("Import of the maven project has been finished", line) projectTrackerSettings.autoReloadType = currentAutoReloadType DumbService.getInstance(project).runWhenSmart(DisposeAwareRunnable.create(runnable, project)) - val storageVersion = (WorkspaceModel.getInstance(project) as WorkspaceModelImpl).entityStorage.version + val storageVersion = WorkspaceModel.getInstance(project).internal.entityStorage.version val storage = WorkspaceModel.getInstance(project).currentSnapshot //val sourceRoots = storage.entities(SourceRootEntity::class.java).map { it.url.url }.toList() context.message("Entity storage version: $storageVersion, snapshot: $storage", line)