mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[Workspace Model] Add simple modifications of entities
GitOrigin-RevId: 34e1123ae6e5f43d49a8de31a4563838690facca
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ec8fbf3ea8
commit
13ac4c9d21
-1
@@ -44,7 +44,6 @@ internal class ModifiableSampleEntity : ModifiableWorkspaceEntityBase<SampleEnti
|
||||
var stringProperty: String by EntityDataDelegation()
|
||||
var stringListProperty: List<String> by EntityDataDelegation()
|
||||
var fileProperty: VirtualFileUrl by EntityDataDelegation()
|
||||
|
||||
}
|
||||
|
||||
internal fun WorkspaceEntityStorageBuilder.addSampleEntity(stringProperty: String,
|
||||
|
||||
+98
-14
@@ -12,7 +12,33 @@ import org.jetbrains.jetCheck.ImperativeCommand
|
||||
import org.junit.Assert
|
||||
|
||||
internal fun getEntityManipulation(workspace: WorkspaceEntityStorageBuilderImpl): Generator<ImperativeCommand>? {
|
||||
return Generator.anyOf(RemoveSomeEntity.create(workspace), EntityManipulation.addManipulations(workspace))
|
||||
return Generator.anyOf(
|
||||
RemoveSomeEntity.create(workspace),
|
||||
EntityManipulation.addManipulations(workspace),
|
||||
EntityManipulation.modifyManipulations(workspace)
|
||||
)
|
||||
}
|
||||
|
||||
internal interface EntityManipulation {
|
||||
fun addManipulation(storage: WorkspaceEntityStorageBuilderImpl): AddEntity
|
||||
fun modifyManipulation(storage: WorkspaceEntityStorageBuilderImpl): ModifyEntity<out WorkspaceEntity>
|
||||
|
||||
companion object {
|
||||
fun addManipulations(storage: WorkspaceEntityStorageBuilderImpl): Generator<AddEntity> {
|
||||
return Generator.sampledFrom(manipulations.map { it.addManipulation(storage) })
|
||||
}
|
||||
|
||||
fun modifyManipulations(storage: WorkspaceEntityStorageBuilderImpl): Generator<ModifyEntity<*>> {
|
||||
return Generator.sampledFrom(manipulations.map { it.modifyManipulation(storage) })
|
||||
}
|
||||
|
||||
private val manipulations = listOf(
|
||||
SampleEntityManipulation,
|
||||
ParentEntityManipulation,
|
||||
ChildEntityManipulation,
|
||||
ChildWithOptionalParentManipulation
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Common for all entities
|
||||
@@ -48,21 +74,21 @@ internal abstract class AddEntity(protected val storage: WorkspaceEntityStorageB
|
||||
}
|
||||
}
|
||||
|
||||
internal interface EntityManipulation {
|
||||
fun addManipulation(storage: WorkspaceEntityStorageBuilderImpl): AddEntity
|
||||
//fun modify(storage: WorkspaceEntityStorageBuilderImpl)
|
||||
internal abstract class ModifyEntity<E : WorkspaceEntity>(protected val storage: WorkspaceEntityStorageBuilderImpl,
|
||||
private val entityDescription: String,
|
||||
private val classId: Int) : ImperativeCommand {
|
||||
abstract fun modifyEntity(entity: E, someProperty: String, env: ImperativeCommand.Environment): Boolean
|
||||
|
||||
companion object {
|
||||
fun addManipulations(storage: WorkspaceEntityStorageBuilderImpl): Generator<AddEntity> {
|
||||
return Generator.sampledFrom(manipulations.map { it.addManipulation(storage) })
|
||||
}
|
||||
final override fun performCommand(env: ImperativeCommand.Environment) {
|
||||
env.logMessage("Trying to modify $entityDescription entity")
|
||||
val property = env.generateValue(randomNames, null)
|
||||
|
||||
private val manipulations = listOf(
|
||||
SampleEntityManipulation,
|
||||
ParentEntityManipulation,
|
||||
ChildEntityManipulation,
|
||||
ChildWithOptionalParentManipulation
|
||||
)
|
||||
val entityId = env.generateValue(EntityIdOfFamilyGenerator.create(storage, classId), null)
|
||||
if (entityId == null) return
|
||||
|
||||
val entity = storage.entityDataByIdOrDie(entityId).createEntity(storage) as E
|
||||
modifyEntity(entity, property, env)
|
||||
env.logMessage("----------------------------------")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,6 +103,21 @@ private object ChildWithOptionalParentManipulation : EntityManipulation {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun modifyManipulation(storage: WorkspaceEntityStorageBuilderImpl): ModifyEntity<ChildWithOptionalParentEntity> {
|
||||
return object : ModifyEntity<ChildWithOptionalParentEntity>(storage, "ChildWithOptionalParent",
|
||||
ChildWithOptionalParentEntity::class.java.toClassId()) {
|
||||
override fun modifyEntity(entity: ChildWithOptionalParentEntity, someProperty: String, env: ImperativeCommand.Environment): Boolean {
|
||||
val selectedModification = env.generateValue(Generator.integers(0, 0), null)
|
||||
val modification: ModifiableChildWithOptionalParentEntity.() -> Unit = when (selectedModification) {
|
||||
0 -> { -> childProperty = env.generateValue(randomNames, "Change childProperty to %s") }
|
||||
else -> error("Undefined modification")
|
||||
}
|
||||
storage.modifyEntity(ModifiableChildWithOptionalParentEntity::class.java, entity, modification)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private object ChildEntityManipulation : EntityManipulation {
|
||||
@@ -90,6 +131,20 @@ private object ChildEntityManipulation : EntityManipulation {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun modifyManipulation(storage: WorkspaceEntityStorageBuilderImpl): ModifyEntity<ChildEntity> {
|
||||
return object : ModifyEntity<ChildEntity>(storage, "Child", ChildEntity::class.java.toClassId()) {
|
||||
override fun modifyEntity(entity: ChildEntity, someProperty: String, env: ImperativeCommand.Environment): Boolean {
|
||||
val selectedModification = env.generateValue(Generator.integers(0, 0), null)
|
||||
val modification: ModifiableChildEntity.() -> Unit = when (selectedModification) {
|
||||
0 -> { -> childProperty = env.generateValue(randomNames, "Change childProperty to %s") }
|
||||
else -> error("Undefined modification")
|
||||
}
|
||||
storage.modifyEntity(ModifiableChildEntity::class.java, entity, modification)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private object ParentEntityManipulation : EntityManipulation {
|
||||
@@ -100,6 +155,20 @@ private object ParentEntityManipulation : EntityManipulation {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun modifyManipulation(storage: WorkspaceEntityStorageBuilderImpl): ModifyEntity<ParentEntity> {
|
||||
return object : ModifyEntity<ParentEntity>(storage, "Parent", ParentEntity::class.java.toClassId()) {
|
||||
override fun modifyEntity(entity: ParentEntity, someProperty: String, env: ImperativeCommand.Environment): Boolean {
|
||||
val selectedModification = env.generateValue(Generator.integers(0, 0), null)
|
||||
val modification: ModifiableParentEntity.() -> Unit = when (selectedModification) {
|
||||
0 -> { -> parentProperty = env.generateValue(randomNames, "Change parentProperty to %s") }
|
||||
else -> error("Undefined modification")
|
||||
}
|
||||
storage.modifyEntity(ModifiableParentEntity::class.java, entity, modification)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private object SampleEntityManipulation : EntityManipulation {
|
||||
@@ -110,5 +179,20 @@ private object SampleEntityManipulation : EntityManipulation {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun modifyManipulation(storage: WorkspaceEntityStorageBuilderImpl): ModifyEntity<SampleEntity> {
|
||||
return object : ModifyEntity<SampleEntity>(storage, "Sample", SampleEntity::class.java.toClassId()) {
|
||||
override fun modifyEntity(entity: SampleEntity, someProperty: String, env: ImperativeCommand.Environment): Boolean {
|
||||
val selectedModification = env.generateValue(Generator.integers(0, 1), null)
|
||||
val modification: ModifiableSampleEntity.() -> Unit = when (selectedModification) {
|
||||
0 -> { -> booleanProperty = env.generateValue(Generator.booleans(), "Change booleanProperty to %s") }
|
||||
1 -> { -> stringProperty = env.generateValue(randomNames, "Change stringProperty to %s") }
|
||||
else -> error("Undefined modification")
|
||||
}
|
||||
storage.modifyEntity(ModifiableSampleEntity::class.java, entity, modification)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user