From 3275bb108781cc0532846f62853614738da3d7bc Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Wed, 8 Feb 2023 16:13:30 +0700 Subject: [PATCH] =?UTF-8?q?=D0=BD=D1=83=20=D0=B2=D0=BE=D1=82=20=D1=82?= =?UTF-8?q?=D0=B0=D0=BA=20=D0=BD=D0=B0=D0=B4=D0=BE=20=D0=B1=D1=8B=D0=BB?= =?UTF-8?q?=D0=BE=20=D0=B8=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=D1=82=D1=8C?= =?UTF-8?q?=20=D1=8D=D1=82=D1=83=20=D1=88=D1=82=D1=83=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{DefinitionBuilder.kt => FreezableDefintionBuilder.kt} | 5 +++-- .../ru/dbotthepony/kstarbound/defs/item/ItemPrototype.kt | 7 ++----- .../kstarbound/io/json/builder/BuilderAdapter.kt | 5 ++--- 3 files changed, 7 insertions(+), 10 deletions(-) rename src/main/kotlin/ru/dbotthepony/kstarbound/defs/{DefinitionBuilder.kt => FreezableDefintionBuilder.kt} (93%) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/DefinitionBuilder.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/FreezableDefintionBuilder.kt similarity index 93% rename from src/main/kotlin/ru/dbotthepony/kstarbound/defs/DefinitionBuilder.kt rename to src/main/kotlin/ru/dbotthepony/kstarbound/defs/FreezableDefintionBuilder.kt index 43052108..8f11addd 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/DefinitionBuilder.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/FreezableDefintionBuilder.kt @@ -5,7 +5,7 @@ import ru.dbotthepony.kstarbound.util.INotNullDelegate import kotlin.properties.ReadWriteProperty import kotlin.reflect.KProperty -abstract class DefinitionBuilder { +abstract class FreezableDefintionBuilder { interface IProperty { fun checkAndThrow() } @@ -81,7 +81,7 @@ abstract class DefinitionBuilder { private val properties = ArrayList() override fun equals(other: Any?): Boolean { - if (other is DefinitionBuilder && other.javaClass === this.javaClass) + if (other is FreezableDefintionBuilder && other.javaClass === this.javaClass) return other.properties == properties return false @@ -102,6 +102,7 @@ abstract class DefinitionBuilder { fun freeze() { if (isFrozen) return onFreeze() + properties.forEach { it.checkAndThrow() } isFrozen = true } } diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/ItemPrototype.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/ItemPrototype.kt index 3facb0ae..58b46102 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/ItemPrototype.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/ItemPrototype.kt @@ -1,19 +1,16 @@ package ru.dbotthepony.kstarbound.defs.item import com.google.common.collect.ImmutableList -import ru.dbotthepony.kstarbound.defs.DefinitionBuilder +import ru.dbotthepony.kstarbound.defs.FreezableDefintionBuilder import ru.dbotthepony.kstarbound.defs.RegistryReference import ru.dbotthepony.kstarbound.defs.ThingDescription -import ru.dbotthepony.kstarbound.defs.util.enrollMap -import ru.dbotthepony.kstarbound.io.json.builder.BuilderAdapter -import ru.dbotthepony.kstarbound.io.json.builder.INativeJsonHolder import ru.dbotthepony.kstarbound.io.json.builder.JsonBuilder import ru.dbotthepony.kstarbound.io.json.builder.JsonPropertyConfig import ru.dbotthepony.kstarbound.io.json.builder.JsonIgnoreProperty import ru.dbotthepony.kstarbound.util.NotNullVar @JsonBuilder -open class ItemPrototype : DefinitionBuilder(), IItemDefinition { +open class ItemPrototype : FreezableDefintionBuilder(), IItemDefinition { @JsonIgnoreProperty final override val shortdescription: String get() = descriptionData.shortdescription diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/builder/BuilderAdapter.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/builder/BuilderAdapter.kt index 4ef5cf86..0009368a 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/builder/BuilderAdapter.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/builder/BuilderAdapter.kt @@ -19,11 +19,10 @@ import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap import org.apache.logging.log4j.LogManager -import ru.dbotthepony.kstarbound.defs.DefinitionBuilder +import ru.dbotthepony.kstarbound.defs.FreezableDefintionBuilder import ru.dbotthepony.kstarbound.defs.util.flattenJsonElement import ru.dbotthepony.kstarbound.io.json.builder.BuilderAdapter.Builder import ru.dbotthepony.kstarbound.util.INotNullDelegate -import ru.dbotthepony.kstarbound.util.NotNullVar import kotlin.properties.Delegates import kotlin.reflect.KClass import kotlin.reflect.KMutableProperty1 @@ -187,7 +186,7 @@ class BuilderAdapter private constructor( } } - if (instance is DefinitionBuilder) { + if (instance is FreezableDefintionBuilder) { instance.freeze() }