From c570ed8e651e3f534d39ce5aaa0cc862df1dc25f Mon Sep 17 00:00:00 2001 From: Alex Plate Date: Tue, 9 Jun 2020 12:55:27 +0300 Subject: [PATCH] [Workspace Model] Add entity source editing to propertyBased tests GitOrigin-RevId: 8a68c9ce3b6757328c2d5333daa034ba663b04a2 --- .../propertyBased/EntityManipulations.kt | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/workspaceModel/storage/propertyBased/EntityManipulations.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/workspaceModel/storage/propertyBased/EntityManipulations.kt index d85698442e65..0e26cf2d96d3 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/workspaceModel/storage/propertyBased/EntityManipulations.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/workspaceModel/storage/propertyBased/EntityManipulations.kt @@ -20,7 +20,8 @@ internal fun getEntityManipulation(workspace: WorkspaceEntityStorageBuilderImpl) return Generator.anyOf( RemoveSomeEntity.create(workspace), EntityManipulation.addManipulations(workspace), - EntityManipulation.modifyManipulations(workspace) + EntityManipulation.modifyManipulations(workspace), + ChangeEntitySource.create(workspace) ) } @@ -65,6 +66,27 @@ private class RemoveSomeEntity(private val storage: WorkspaceEntityStorageBuilde } } +private class ChangeEntitySource(private val storage: WorkspaceEntityStorageBuilderImpl) : ImperativeCommand { + override fun performCommand(env: ImperativeCommand.Environment) { + val id = env.generateValue(EntityIdGenerator.create(storage), null) ?: run { + env.logMessage("Tried to change entity source, but entity to change isn't found") + return + } + val newSource = env.generateValue(sources, null) + val entity = storage.entityDataByIdOrDie(id).createEntity(storage) + val oldEntitySource = entity.entitySource + storage.changeSource(entity, newSource) + + env.logMessage("Entity source changed. Entity: $entity, Old source: $oldEntitySource, New source: $newSource") + } + + companion object { + fun create(workspace: WorkspaceEntityStorageBuilderImpl): Generator { + return Generator.constant(ChangeEntitySource(workspace)) + } + } +} + internal abstract class AddEntity(protected val storage: WorkspaceEntityStorageBuilderImpl, private val entityDescription: String) : ImperativeCommand { abstract fun makeEntity(source: EntitySource, someProperty: String, env: ImperativeCommand.Environment): WorkspaceEntity?