From 67ca6c073718509b7dd5ffa49f09b60936e68d2d Mon Sep 17 00:00:00 2001 From: Alex Plate Date: Thu, 21 Mar 2024 14:57:11 +0200 Subject: [PATCH] [Workspace Model] [IJPL-583] Cleanup details before merge GitOrigin-RevId: 314fb97916ee920e62176067d78aec3ae861a0b5 --- .../impl/ImmutableEntityStorageImpl.kt | 1 - .../storage/tests/AbstractEntitiesTest.kt | 39 ------------------- .../storage/tests/MutableStorageTest.kt | 15 ------- .../workspace/storage/tests/SampleTest.kt | 3 +- .../workspace/storage/tests/testUtils.kt | 5 +++ 5 files changed, 7 insertions(+), 56 deletions(-) diff --git a/platform/workspace/storage/src/com/intellij/platform/workspace/storage/impl/ImmutableEntityStorageImpl.kt b/platform/workspace/storage/src/com/intellij/platform/workspace/storage/impl/ImmutableEntityStorageImpl.kt index 054a6968a78a..eeea4c6a3209 100644 --- a/platform/workspace/storage/src/com/intellij/platform/workspace/storage/impl/ImmutableEntityStorageImpl.kt +++ b/platform/workspace/storage/src/com/intellij/platform/workspace/storage/impl/ImmutableEntityStorageImpl.kt @@ -231,7 +231,6 @@ internal class MutableEntityStorageImpl( entityToAdd.applyToBuilder(this) entityToAdd.changedProperty.clear() - // TODO Do not re-request entities return@addMeasuredTime this.entityDataByIdOrDie(entityToAdd.id).createEntity(this) as T } finally { diff --git a/platform/workspace/storage/tests/testSrc/com/intellij/platform/workspace/storage/tests/AbstractEntitiesTest.kt b/platform/workspace/storage/tests/testSrc/com/intellij/platform/workspace/storage/tests/AbstractEntitiesTest.kt index f122ec9635b5..8661ac781348 100644 --- a/platform/workspace/storage/tests/testSrc/com/intellij/platform/workspace/storage/tests/AbstractEntitiesTest.kt +++ b/platform/workspace/storage/tests/testSrc/com/intellij/platform/workspace/storage/tests/AbstractEntitiesTest.kt @@ -2,12 +2,9 @@ package com.intellij.platform.workspace.storage.tests import com.intellij.platform.workspace.storage.MutableEntityStorage -import com.intellij.platform.workspace.storage.impl.ModifiableWorkspaceEntityBase -import com.intellij.platform.workspace.storage.impl.asBase import com.intellij.platform.workspace.storage.impl.assertConsistency import com.intellij.platform.workspace.storage.testEntities.entities.* import com.intellij.testFramework.UsefulTestCase.assertOneElement -import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import kotlin.test.* @@ -216,42 +213,6 @@ class AbstractEntitiesTest { assertNotNull(builder.entities(HeadAbstractionEntity::class.java).single { it.data == "Info2" }.child) } - @Test - @Disabled("Change of behaviour after IJPL-583") - // Deprecation note: Now builder.entities returns entitiesImpls instead of builders that are modified - fun `entity changes visible in mutable storage`() { - var builder = MutableEntityStorage.create() - val entity = ParentEntity("ParentData", MySource) - builder.addEntity(entity) - - builder = MutableEntityStorage.from(builder.toSnapshot()) - val resultEntity = builder.entities(ParentEntity::class.java).single() - resultEntity.parentData - var firstEntityData = (entity as ModifiableWorkspaceEntityBase<*, *>).getEntityData() - var secondEntityData = resultEntity.asBase().getData() - assertSame(firstEntityData, secondEntityData) - val originalEntityData = firstEntityData - - builder.modifyEntity(resultEntity) { - this.parentData = "NewParentData" - } - val anotherResult = builder.entities(ParentEntity::class.java).single() - assertEquals(resultEntity.parentData, anotherResult.parentData) - - firstEntityData = (resultEntity as ModifiableWorkspaceEntityBase<*, *>).getEntityData() - secondEntityData = (anotherResult as ModifiableWorkspaceEntityBase<*, *>).getEntityData() - assertSame(firstEntityData, secondEntityData) - assertNotSame(firstEntityData, originalEntityData) - - builder.modifyEntity(anotherResult) { - this.parentData = "AnotherParentData" - } - val oneMoreResult = builder.entities(ParentEntity::class.java).single() - assertEquals(resultEntity.parentData, anotherResult.parentData) - assertEquals(oneMoreResult.parentData, anotherResult.parentData) - assertEquals(oneMoreResult.parentData, resultEntity.parentData) - } - @Test fun `add entity with child then steal this child with different entity`() { val builder = MutableEntityStorage.create() diff --git a/platform/workspace/storage/tests/testSrc/com/intellij/platform/workspace/storage/tests/MutableStorageTest.kt b/platform/workspace/storage/tests/testSrc/com/intellij/platform/workspace/storage/tests/MutableStorageTest.kt index aafc45b49d00..f0fdb667eea7 100644 --- a/platform/workspace/storage/tests/testSrc/com/intellij/platform/workspace/storage/tests/MutableStorageTest.kt +++ b/platform/workspace/storage/tests/testSrc/com/intellij/platform/workspace/storage/tests/MutableStorageTest.kt @@ -4,7 +4,6 @@ package com.intellij.platform.workspace.storage.tests import com.intellij.platform.workspace.storage.MutableEntityStorage import com.intellij.platform.workspace.storage.testEntities.entities.* import com.intellij.platform.workspace.storage.toBuilder -import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows import kotlin.test.assertEquals @@ -47,20 +46,6 @@ class MutableStorageTest { assertEquals("ParentData", entityTwoBuilder.data) } - @Test - @Disabled("Change of behaviour after IJPL-583") - fun `check exception if request data from entity which was removed`() { - val builder = MutableEntityStorage.create() - val sampleEntity = SampleEntity2("ParentData", false, MySource) - builder.addEntity(sampleEntity) - val newBuilder = MutableEntityStorage.from(builder.toSnapshot()) - val entityFromStore = newBuilder.entities(SampleEntity2::class.java).single() - newBuilder.removeEntity(entityFromStore) - - assertThrows { entityFromStore.data } - assertEquals("ParentData", sampleEntity.data) - } - @Test fun `check parent updates`() { val builder = MutableEntityStorage.create() diff --git a/platform/workspace/storage/tests/testSrc/com/intellij/platform/workspace/storage/tests/SampleTest.kt b/platform/workspace/storage/tests/testSrc/com/intellij/platform/workspace/storage/tests/SampleTest.kt index 970290879163..9ca99412a6b9 100644 --- a/platform/workspace/storage/tests/testSrc/com/intellij/platform/workspace/storage/tests/SampleTest.kt +++ b/platform/workspace/storage/tests/testSrc/com/intellij/platform/workspace/storage/tests/SampleTest.kt @@ -37,11 +37,12 @@ class SampleTest { val entity = builder addEntity SampleEntity2("data", true, MySource) builder.toSnapshot() - builder.modifyEntity(entity) { + val updatedEntity = builder.modifyEntity(entity) { this.data = "data2" } assertEquals("data", entity.data) + assertEquals("data2", updatedEntity.data) assertEquals("data2", builder.entities(SampleEntity2::class.java).single().data) } diff --git a/platform/workspace/storage/tests/testSrc/com/intellij/platform/workspace/storage/tests/testUtils.kt b/platform/workspace/storage/tests/testSrc/com/intellij/platform/workspace/storage/tests/testUtils.kt index 665784266e93..663cd7cad5fb 100644 --- a/platform/workspace/storage/tests/testSrc/com/intellij/platform/workspace/storage/tests/testUtils.kt +++ b/platform/workspace/storage/tests/testSrc/com/intellij/platform/workspace/storage/tests/testUtils.kt @@ -12,6 +12,7 @@ import com.intellij.platform.workspace.storage.impl.serialization.EntityStorageS import com.intellij.platform.workspace.storage.url.VirtualFileUrlManager import com.intellij.workspaceModel.ide.impl.WorkspaceModelCacheSerializer.PluginAwareEntityTypesResolver import junit.framework.TestCase.* +import org.jetbrains.annotations.ApiStatus import org.junit.Assert import java.nio.file.Files import java.util.function.BiPredicate @@ -174,6 +175,10 @@ internal fun T.from(storage: EntityStorage): T { return this.createPointer().resolve(storage)!! } +@ApiStatus.Obsolete +/** + * This function was created to simplify IJPL-583 refactoring. It should not be used in code anymore + */ internal fun , M: WorkspaceEntity> M.builderFrom(from: MutableEntityStorage): T { val pointer = this.createPointer() val entityFromBuilder = pointer.resolve(from)!!