[Workspace Model] [IJPL-583] Changes in storage to support builders without entity interfaces

GitOrigin-RevId: a12dbd8c4c017d140be9c7c538e4327211b0a455
This commit is contained in:
Alex Plate
2024-03-25 13:27:42 +00:00
committed by intellij-monorepo-bot
parent 42316412d7
commit 43eaaef8b8
3 changed files with 10 additions and 4 deletions
@@ -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.platform.workspace.storage
import com.intellij.platform.workspace.storage.impl.AbstractEntityStorage
@@ -24,7 +24,7 @@ public fun <T : WorkspaceEntity> T.createEntityTreeCopy(requireTopLevelEntity: B
val newEntity = entityData.createDetachedEntity(emptyList())
val copied = HashSet<EntityId>()
val deferred = HashSet<EntityId>()
val parents = FList.emptyList<WorkspaceEntity>().prepend(newEntity)
val parents = FList.emptyList<WorkspaceEntity.Builder<*>>().prepend(newEntity)
val parentInterfaces = FList.emptyList<Class<out WorkspaceEntity>>().prepend(entityData.getEntityInterface())
copyChildren(id, parents, parentInterfaces, originalSnapshot, copied, deferred)
deferred.removeAll(copied)
@@ -34,7 +34,7 @@ public fun <T : WorkspaceEntity> T.createEntityTreeCopy(requireTopLevelEntity: B
}
private fun copyChildren(oldEntityId: EntityId,
parents: FList<WorkspaceEntity>,
parents: FList<WorkspaceEntity.Builder<*>>,
parentInterfaces: FList<Class<out WorkspaceEntity>>,
originalSnapshot: AbstractEntityStorage,
copied: MutableSet<EntityId>,
@@ -570,6 +570,10 @@ public abstract class WorkspaceEntityData<E : WorkspaceEntity> : Cloneable, Seri
throw NotImplementedError()
}
public open fun createDetachedEntity(parents: List<WorkspaceEntity.Builder<*>>): WorkspaceEntity.Builder<*> {
throw NotImplementedError()
}
public open fun getRequiredParents(): List<Class<out WorkspaceEntity>> {
throw NotImplementedError()
}
@@ -199,11 +199,13 @@ internal class ReplaceBySourceAsTree {
private fun addElement(parents: Set<EntityId>?, replaceWithDataSource: EntityId, replaceToTarget: HashBiMap<EntityId, EntityId>) {
val targetParents = mutableListOf<WorkspaceEntity>()
val targetParentBuilders = mutableListOf<WorkspaceEntity.Builder<*>>()
parents?.forEach { parent ->
targetParents += targetStorage.entityDataByIdOrDie(parent).createEntity(targetStorage)
targetParentBuilders += targetStorage.entityDataByIdOrDie(parent).wrapAsModifiable(targetStorage)
}
val modifiableEntity = replaceWithStorage.entityDataByIdOrDie(replaceWithDataSource).createDetachedEntity(targetParents)
val modifiableEntity = replaceWithStorage.entityDataByIdOrDie(replaceWithDataSource).createDetachedEntity(targetParentBuilders)
modifiableEntity as ModifiableWorkspaceEntityBase<out WorkspaceEntity, out WorkspaceEntityData<*>>
// We actually bind parents in [createDetachedEntity], but we can't do it for external entities (that are defined in a separate module)