[Workspace Model] Cleanup test entities

GitOrigin-RevId: a8a1e0e33cbc5db9cd98a9dc90b7845bfd2347e9
This commit is contained in:
Alex Plate
2023-04-28 12:26:27 +00:00
committed by intellij-monorepo-bot
parent a8270fb3cb
commit 18f8d9db5f
8 changed files with 57 additions and 340 deletions
@@ -1,12 +1,11 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.workspaceModel.storage.entities.unknowntypes.test.api
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.workspaceModel.storage.entities.test.api
import com.intellij.workspaceModel.storage.EntityInformation
import com.intellij.workspaceModel.storage.EntitySource
import com.intellij.workspaceModel.storage.EntityStorage
import com.intellij.workspaceModel.storage.GeneratedCodeApiVersion
import com.intellij.workspaceModel.storage.GeneratedCodeImplVersion
import com.intellij.workspaceModel.storage.MutableEntityStorage
import com.intellij.workspaceModel.storage.WorkspaceEntity
import com.intellij.workspaceModel.storage.impl.ConnectionId
@@ -14,11 +13,14 @@ import com.intellij.workspaceModel.storage.impl.ModifiableWorkspaceEntityBase
import com.intellij.workspaceModel.storage.impl.UsedClassesCollector
import com.intellij.workspaceModel.storage.impl.WorkspaceEntityBase
import com.intellij.workspaceModel.storage.impl.WorkspaceEntityData
import java.util.*
import java.util.Date
import org.jetbrains.deft.ObjBuilder
import org.jetbrains.deft.Type
@GeneratedCodeApiVersion(1)
@GeneratedCodeImplVersion(1)
open class UnknownFieldEntityImpl : UnknownFieldEntity, WorkspaceEntityBase() {
open class UnknownFieldEntityImpl(val dataSource: UnknownFieldEntityData) : UnknownFieldEntity, WorkspaceEntityBase() {
companion object {
@@ -28,19 +30,18 @@ open class UnknownFieldEntityImpl : UnknownFieldEntity, WorkspaceEntityBase() {
}
@JvmField
var _data: Date? = null
override val data: Date
get() = _data!!
get() = dataSource.data
override val entitySource: EntitySource
get() = dataSource.entitySource
override fun connectionIdList(): List<ConnectionId> {
return connections
}
override val entitySource: EntitySource
get() = TODO("Not yet implemented")
class Builder(result: UnknownFieldEntityData?) : ModifiableWorkspaceEntityBase<UnknownFieldEntity, UnknownFieldEntityData>(result), UnknownFieldEntity.Builder {
class Builder(result: UnknownFieldEntityData?) : ModifiableWorkspaceEntityBase<UnknownFieldEntity, UnknownFieldEntityData>(
result), UnknownFieldEntity.Builder {
constructor() : this(UnknownFieldEntityData())
override fun applyToBuilder(builder: MutableEntityStorage) {
@@ -58,6 +59,9 @@ open class UnknownFieldEntityImpl : UnknownFieldEntity, WorkspaceEntityBase() {
this.snapshot = builder
addToBuilder()
this.id = getEntityData().createEntityId()
// After adding entity data to the builder, we need to unbind it and move the control over entity data to builder
// Builder may switch to snapshot at any moment and lock entity data to modification
this.currentEntityData = null
// Process linked entities that are connected without a builder
processLinkedEntities(builder)
@@ -66,12 +70,12 @@ open class UnknownFieldEntityImpl : UnknownFieldEntity, WorkspaceEntityBase() {
fun checkInitialization() {
val _diff = diff
if (!getEntityData().isEntitySourceInitialized()) {
error("Field WorkspaceEntity#entitySource should be initialized")
}
if (!getEntityData().isDataInitialized()) {
error("Field UnknownFieldEntity#data should be initialized")
}
if (!getEntityData().isEntitySourceInitialized()) {
error("Field UnknownFieldEntity#entitySource should be initialized")
}
}
override fun connectionIdList(): List<ConnectionId> {
@@ -81,31 +85,30 @@ open class UnknownFieldEntityImpl : UnknownFieldEntity, WorkspaceEntityBase() {
// Relabeling code, move information from dataSource to this builder
override fun relabel(dataSource: WorkspaceEntity, parents: Set<WorkspaceEntity>?) {
dataSource as UnknownFieldEntity
this.data = dataSource.data
this.entitySource = dataSource.entitySource
if (parents != null) {
}
if (this.entitySource != dataSource.entitySource) this.entitySource = dataSource.entitySource
if (this.data != dataSource.data) this.data = dataSource.data
updateChildToParentReferences(parents)
}
override var data: Date
get() = getEntityData().data
set(value) {
checkModificationAllowed()
getEntityData().data = value
changedProperty.add("data")
}
override var entitySource: EntitySource
get() = getEntityData().entitySource
set(value) {
checkModificationAllowed()
getEntityData().entitySource = value
getEntityData(true).entitySource = value
changedProperty.add("entitySource")
}
override var data: Date
get() = getEntityData().data
set(value) {
checkModificationAllowed()
getEntityData(true).data = value
changedProperty.add("data")
}
override fun getEntityClass(): Class<UnknownFieldEntity> = UnknownFieldEntity::class.java
}
}
@@ -117,22 +120,19 @@ class UnknownFieldEntityData : WorkspaceEntityData<UnknownFieldEntity>() {
override fun wrapAsModifiable(diff: MutableEntityStorage): WorkspaceEntity.Builder<UnknownFieldEntity> {
val modifiable = UnknownFieldEntityImpl.Builder(null)
modifiable.allowModifications {
modifiable.diff = diff
modifiable.snapshot = diff
modifiable.id = createEntityId()
modifiable.entitySource = this.entitySource
}
modifiable.changedProperty.clear()
modifiable.diff = diff
modifiable.snapshot = diff
modifiable.id = createEntityId()
return modifiable
}
override fun createEntity(snapshot: EntityStorage): UnknownFieldEntity {
val entity = UnknownFieldEntityImpl()
entity._data = data
entity.snapshot = snapshot
entity.id = createEntityId()
return entity
return getCached(snapshot) {
val entity = UnknownFieldEntityImpl(this)
entity.snapshot = snapshot
entity.id = createEntityId()
entity
}
}
override fun getEntityInterface(): Class<out WorkspaceEntity> {
@@ -157,18 +157,18 @@ class UnknownFieldEntityData : WorkspaceEntityData<UnknownFieldEntity>() {
override fun equals(other: Any?): Boolean {
if (other == null) return false
if (this::class != other::class) return false
if (this.javaClass != other.javaClass) return false
other as UnknownFieldEntityData
if (this.data != other.data) return false
if (this.entitySource != other.entitySource) return false
if (this.data != other.data) return false
return true
}
override fun equalsIgnoringEntitySource(other: Any?): Boolean {
if (other == null) return false
if (this::class != other::class) return false
if (this.javaClass != other.javaClass) return false
other as UnknownFieldEntityData
@@ -189,7 +189,7 @@ class UnknownFieldEntityData : WorkspaceEntityData<UnknownFieldEntity>() {
}
override fun collectClassUsagesData(collector: UsedClassesCollector) {
collector.add(Date::class.java)
this.data?.let { collector.addDataToInspect(it) }
collector.sameForAllEntities = true
}
}
@@ -1,192 +0,0 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.workspaceModel.storage.entity
import com.intellij.workspaceModel.storage.*
import com.intellij.workspaceModel.storage.entities.model.api.*
import com.intellij.workspaceModel.storage.impl.ConnectionId
import com.intellij.workspaceModel.storage.impl.ModifiableWorkspaceEntityBase
import com.intellij.workspaceModel.storage.impl.WorkspaceEntityBase
import com.intellij.workspaceModel.storage.impl.WorkspaceEntityData
@GeneratedCodeApiVersion(1)
@GeneratedCodeImplVersion(1)
open class TestEntityImpl: TestEntity, WorkspaceEntityBase() {
companion object {
val connections = listOf<ConnectionId>(
)
}
@JvmField var _name: String? = null
override val name: String
get() = _name!!
override var count: Int = 0
@JvmField var _anotherField: One? = null
override val anotherField: One
get() = _anotherField!!
override fun connectionIdList(): List<ConnectionId> {
return connections
}
override val entitySource: EntitySource
get() = TODO("Not yet implemented")
class Builder(result: TestEntityData?): ModifiableWorkspaceEntityBase<TestEntity, TestEntityData>(result), TestEntity.Builder {
constructor(): this(TestEntityData())
override fun applyToBuilder(builder: MutableEntityStorage) {
if (this.diff != null) {
if (existsInBuilder(builder)) {
this.diff = builder
return
}
else {
error("Entity TestEntity is already created in a different builder")
}
}
this.diff = builder
this.snapshot = builder
addToBuilder()
this.id = getEntityData().createEntityId()
// Process linked entities that are connected without a builder
processLinkedEntities(builder)
checkInitialization() // TODO uncomment and check failed tests
}
fun checkInitialization() {
val _diff = diff
if (!getEntityData().isNameInitialized()) {
error("Field TestEntity#name should be initialized")
}
if (!getEntityData().isEntitySourceInitialized()) {
error("Field TestEntity#entitySource should be initialized")
}
if (!getEntityData().isAnotherFieldInitialized()) {
error("Field TestEntity#anotherField should be initialized")
}
}
override fun connectionIdList(): List<ConnectionId> {
return connections
}
override var name: String
get() = getEntityData().name
set(value) {
checkModificationAllowed()
getEntityData().name = value
changedProperty.add("name")
}
override var entitySource: EntitySource
get() = getEntityData().entitySource
set(value) {
checkModificationAllowed()
getEntityData().entitySource = value
changedProperty.add("entitySource")
}
override var count: Int
get() = getEntityData().count
set(value) {
checkModificationAllowed()
getEntityData().count = value
changedProperty.add("count")
}
override var anotherField: One
get() = getEntityData().anotherField
set(value) {
checkModificationAllowed()
getEntityData().anotherField = value
changedProperty.add("anotherField")
}
override fun getEntityClass(): Class<TestEntity> = TestEntity::class.java
}
}
class TestEntityData : WorkspaceEntityData<TestEntity>() {
lateinit var name: String
var count: Int = 0
lateinit var anotherField: One
fun isNameInitialized(): Boolean = ::name.isInitialized
fun isAnotherFieldInitialized(): Boolean = ::anotherField.isInitialized
override fun wrapAsModifiable(diff: MutableEntityStorage): WorkspaceEntity.Builder<TestEntity> {
val modifiable = TestEntityImpl.Builder(null)
modifiable.allowModifications {
modifiable.diff = diff
modifiable.snapshot = diff
modifiable.id = createEntityId()
modifiable.entitySource = this.entitySource
}
modifiable.changedProperty.clear()
return modifiable
}
override fun createEntity(snapshot: EntityStorage): TestEntity {
val entity = TestEntityImpl()
entity._name = name
entity.count = count
entity._anotherField = anotherField
entity.snapshot = snapshot
entity.id = createEntityId()
return entity
}
override fun getEntityInterface(): Class<out WorkspaceEntity> {
return TestEntity::class.java
}
override fun serialize(ser: EntityInformation.Serializer) {
}
override fun deserialize(de: EntityInformation.Deserializer) {
}
override fun equals(other: Any?): Boolean {
if (other == null) return false
if (this::class != other::class) return false
other as TestEntityData
if (this.name != other.name) return false
if (this.entitySource != other.entitySource) return false
if (this.count != other.count) return false
if (this.anotherField != other.anotherField) return false
return true
}
override fun equalsIgnoringEntitySource(other: Any?): Boolean {
if (other == null) return false
if (this::class != other::class) return false
other as TestEntityData
if (this.name != other.name) return false
if (this.count != other.count) return false
if (this.anotherField != other.anotherField) return false
return true
}
override fun hashCode(): Int {
var result = entitySource.hashCode()
result = 31 * result + name.hashCode()
result = 31 * result + count.hashCode()
result = 31 * result + anotherField.hashCode()
return result
}
}
@@ -1,50 +0,0 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.workspaceModel.storage.entities.model.api
import com.intellij.workspaceModel.storage.WorkspaceEntity
import com.intellij.workspaceModel.storage.EntitySource
import com.intellij.workspaceModel.storage.GeneratedCodeApiVersion
import com.intellij.workspaceModel.storage.MutableEntityStorage
import org.jetbrains.deft.ObjBuilder
import org.jetbrains.deft.Type
import org.jetbrains.deft.annotations.Child
interface TestEntity: WorkspaceEntity {
val name: String
val count: Int
val anotherField: One
//region generated code
//@formatter:off
@GeneratedCodeApiVersion(1)
interface Builder: TestEntity, WorkspaceEntity.Builder<TestEntity>, ObjBuilder<TestEntity> {
override var name: String
override var entitySource: EntitySource
override var count: Int
override var anotherField: One
}
companion object: Type<TestEntity, Builder>() {
operator fun invoke(name: String, count: Int, anotherField: One, entitySource: EntitySource, init: (Builder.() -> Unit)? = null): TestEntity {
val builder = builder()
builder.name = name
builder.entitySource = entitySource
builder.count = count
builder.anotherField = anotherField
init?.invoke(builder)
return builder
}
}
//@formatter:on
//endregion
}
//region generated code
fun MutableEntityStorage.modifyEntity(entity: TestEntity, modification: TestEntity.Builder.() -> Unit) = modifyEntity(TestEntity.Builder::class.java, entity, modification)
var TestEntity.Builder.anotherTest: @Child AnotherTest?
by WorkspaceEntity.extension()
//endregion
data class One(val foo: String, val bar: String)
@@ -1,22 +0,0 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.workspaceModel.storage.entities.model.api
import com.intellij.workspaceModel.storage.WorkspaceEntity
import com.intellij.workspaceModel.storage.bridgeEntities.ModuleDependencyItem
import org.jetbrains.deft.annotations.Child
interface FooEntity: WorkspaceEntity {
val name: String
val moduleDependency: ModuleDependencyItem.Exportable.ModuleDependency
}
interface AnotherTest: WorkspaceEntity {
val name: String
val testField: TestEntity
}
val TestEntity.anotherTest: @Child AnotherTest?
by WorkspaceEntity.extension()
@@ -1,13 +1,13 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.workspaceModel.storage.entities.unknowntypes.test.api
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.workspaceModel.storage.entities.test.api
import com.intellij.workspaceModel.storage.WorkspaceEntity
import java.util.Date
import com.intellij.workspaceModel.storage.EntitySource
import com.intellij.workspaceModel.storage.GeneratedCodeApiVersion
import com.intellij.workspaceModel.storage.MutableEntityStorage
import com.intellij.workspaceModel.storage.WorkspaceEntity
import org.jetbrains.deft.ObjBuilder
import org.jetbrains.deft.Type
import java.util.*
interface UnknownFieldEntity : WorkspaceEntity {
@@ -16,11 +16,14 @@ interface UnknownFieldEntity : WorkspaceEntity {
//region generated code
@GeneratedCodeApiVersion(1)
interface Builder : UnknownFieldEntity, WorkspaceEntity.Builder<UnknownFieldEntity>, ObjBuilder<UnknownFieldEntity> {
override var data: Date
override var entitySource: EntitySource
override var data: Date
}
companion object : Type<UnknownFieldEntity, Builder>() {
@JvmOverloads
@JvmStatic
@JvmName("create")
operator fun invoke(data: Date, entitySource: EntitySource, init: (Builder.() -> Unit)? = null): UnknownFieldEntity {
val builder = builder()
builder.data = data
@@ -0,0 +1,4 @@
import com.intellij.workspaceModel.storage.EntitySource
internal object MySource : EntitySource
internal object AnotherSource : EntitySource
@@ -1,26 +0,0 @@
import com.intellij.workspaceModel.storage.EntitySource
import java.io.File
//import kotlin.test.assertEquals
internal object MySource : EntitySource
internal object AnotherSource : EntitySource
//internal fun generateEntities() {
// val deftRoot = File("").absoluteFile
//
// val dir = deftRoot.resolve("community/platform/workspaceModel/codegen/test/testSrc/com/intellij/workspaceModel/model")
// CodeWriter().generate(dir, "ext", "ext/impl", "org.jetbrains.deft.IntellijWsTestIjExt")
//}
//
//internal fun assertEntities() {
// val deftRoot = File("").absoluteFile
//
// val dir = deftRoot.resolve("plugins/workspaceModel/model")
// CodeAsserter().generate(dir, "testing", "testing/impl", "org.jetbrains.deft.IntellijWsTest")
//}
//class CodeAsserter : CodeWriter() {
// override fun File.writeCode(code: String) {
// assertEquals(this.readText(), code, this.path)
// }
//}
@@ -2,7 +2,7 @@
package com.intellij.workspaceModel.storage
import com.intellij.workspaceModel.storage.entities.test.api.MySource
import com.intellij.workspaceModel.storage.entities.unknowntypes.test.api.UnknownFieldEntity
import com.intellij.workspaceModel.storage.entities.test.api.UnknownFieldEntity
import org.junit.Test
import java.util.*
import kotlin.test.assertEquals