From affc1de0f5b57487055fab3fdda1472e7f70b0db Mon Sep 17 00:00:00 2001 From: Siphalor Date: Mon, 16 Mar 2026 21:42:47 +0100 Subject: [PATCH] refactor!: Refactored type hierarchy and methods of StructuredConfigEntry --- CHANGELOG.md | 1 + tweed5/attributes-extension/build.gradle.kts | 1 + .../AttributesFilteredCompoundEntry.java | 9 +++--- .../AddressableStructuredConfigEntry.java | 13 ++++++++ .../core/api/entry/CollectionConfigEntry.java | 4 +-- .../core/api/entry/CompoundConfigEntry.java | 9 ++---- .../api/entry/ConfigEntryValueVisitor.java | 11 +++++-- .../entry/MutableStructuredConfigEntry.java | 16 ++++++++++ .../core/api/entry/NullableConfigEntry.java | 4 +-- .../impl/entry/CollectionConfigEntryImpl.java | 3 +- .../impl/entry/NullableConfigEntryImpl.java | 9 ++++-- .../StaticMapCompoundConfigEntryImpl.java | 30 +++++++++---------- .../patch/impl/PatchExtensionImpl.java | 4 +-- .../PathTrackingConfigEntryValueVisitor.java | 20 +++++++++++-- .../impl/ValidationExtensionImpl.java | 5 ++-- .../impl/TweedEntryReaderWriterImpls.java | 2 +- .../api/DefaultPresetWeavingProcessor.java | 2 +- .../entry/StaticPojoCompoundConfigEntry.java | 16 +++++----- 18 files changed, 107 insertions(+), 52 deletions(-) create mode 100644 tweed5/core/src/main/java/de/siphalor/tweed5/core/api/entry/AddressableStructuredConfigEntry.java create mode 100644 tweed5/core/src/main/java/de/siphalor/tweed5/core/api/entry/MutableStructuredConfigEntry.java diff --git a/CHANGELOG.md b/CHANGELOG.md index ee96c0c..d03ccdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `coat-bridge`: Added experimental text mapper based on Tweed Serde. ### Changed +- **Breaking**@`core`: Refactored type hierarchy and methods of `StructuredConfigEntry`. - `weaver-pojo-serde-extension`: Slightly changed the `SerdePojoReaderWriterSpec` to be more closely aligned with Java's identifier rules. - `attributes-extension`: The `AttributesReadWriteFilterExtension` now correctly skips non-matching compound entries diff --git a/tweed5/attributes-extension/build.gradle.kts b/tweed5/attributes-extension/build.gradle.kts index 3e52514..5a08390 100644 --- a/tweed5/attributes-extension/build.gradle.kts +++ b/tweed5/attributes-extension/build.gradle.kts @@ -6,6 +6,7 @@ plugins { dependencies { implementation(project(":tweed5-core")) compileOnly(project(":tweed5-serde-extension")) + testImplementation(project(":tweed5-default-extensions")) testImplementation(project(":tweed5-serde-extension")) testImplementation(project(":tweed5-serde-hjson")) } diff --git a/tweed5/attributes-extension/src/main/java/de/siphalor/tweed5/attributesextension/impl/serde/filter/AttributesFilteredCompoundEntry.java b/tweed5/attributes-extension/src/main/java/de/siphalor/tweed5/attributesextension/impl/serde/filter/AttributesFilteredCompoundEntry.java index 148a87a..6d2ccbd 100644 --- a/tweed5/attributes-extension/src/main/java/de/siphalor/tweed5/attributesextension/impl/serde/filter/AttributesFilteredCompoundEntry.java +++ b/tweed5/attributes-extension/src/main/java/de/siphalor/tweed5/attributesextension/impl/serde/filter/AttributesFilteredCompoundEntry.java @@ -7,6 +7,7 @@ import de.siphalor.tweed5.core.api.entry.ConfigEntryValueVisitor; import de.siphalor.tweed5.core.api.entry.ConfigEntryVisitor; import de.siphalor.tweed5.patchwork.api.Patchwork; import lombok.RequiredArgsConstructor; +import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; import java.util.Map; @@ -16,7 +17,7 @@ public class AttributesFilteredCompoundEntry impleme private final CompoundConfigEntry delegate; @Override - public void set(T compoundValue, String key, V value) { + public void set(T compoundValue, String key, Object value) { if (value == AttributesReadWriteFilterExtensionImpl.NOOP_MARKER) { return; } @@ -24,13 +25,13 @@ public class AttributesFilteredCompoundEntry impleme } @Override - public V get(T compoundValue, String key) { + public Object get(T compoundValue, String key) { return delegate.get(compoundValue, key); } @Override - public T instantiateCompoundValue() { - return delegate.instantiateCompoundValue(); + public @NonNull T instantiateValue() { + return delegate.instantiateValue(); } @Override diff --git a/tweed5/core/src/main/java/de/siphalor/tweed5/core/api/entry/AddressableStructuredConfigEntry.java b/tweed5/core/src/main/java/de/siphalor/tweed5/core/api/entry/AddressableStructuredConfigEntry.java new file mode 100644 index 0000000..7cc5c8f --- /dev/null +++ b/tweed5/core/src/main/java/de/siphalor/tweed5/core/api/entry/AddressableStructuredConfigEntry.java @@ -0,0 +1,13 @@ +package de.siphalor.tweed5.core.api.entry; + +import java.util.function.Consumer; + +public interface AddressableStructuredConfigEntry extends StructuredConfigEntry { + @Override + default AddressableStructuredConfigEntry apply(Consumer> function) { + StructuredConfigEntry.super.apply(function); + return this; + } + + Object get(T value, String key); +} diff --git a/tweed5/core/src/main/java/de/siphalor/tweed5/core/api/entry/CollectionConfigEntry.java b/tweed5/core/src/main/java/de/siphalor/tweed5/core/api/entry/CollectionConfigEntry.java index b68f2fc..0adf2f6 100644 --- a/tweed5/core/src/main/java/de/siphalor/tweed5/core/api/entry/CollectionConfigEntry.java +++ b/tweed5/core/src/main/java/de/siphalor/tweed5/core/api/entry/CollectionConfigEntry.java @@ -38,9 +38,9 @@ public interface CollectionConfigEntry> extends Struc int index = 0; for (E item : value) { String indexString = Integer.toString(index); - if (visitor.enterStructuredSubEntry("element", indexString)) { + if (visitor.enterAddressableStructuredSubEntry("element", indexString, null)) { elementEntry().visitInOrder(visitor, item); - visitor.leaveStructuredSubEntry("element", indexString); + visitor.leaveAddressableStructuredSubEntry("element", indexString, null); } index++; } diff --git a/tweed5/core/src/main/java/de/siphalor/tweed5/core/api/entry/CompoundConfigEntry.java b/tweed5/core/src/main/java/de/siphalor/tweed5/core/api/entry/CompoundConfigEntry.java index f7e7bdd..df14bdd 100644 --- a/tweed5/core/src/main/java/de/siphalor/tweed5/core/api/entry/CompoundConfigEntry.java +++ b/tweed5/core/src/main/java/de/siphalor/tweed5/core/api/entry/CompoundConfigEntry.java @@ -4,18 +4,13 @@ import de.siphalor.tweed5.core.api.Arity; import java.util.function.Consumer; -public interface CompoundConfigEntry extends StructuredConfigEntry { +public interface CompoundConfigEntry extends MutableStructuredConfigEntry { @Override default CompoundConfigEntry apply(Consumer> function) { - StructuredConfigEntry.super.apply(function); + MutableStructuredConfigEntry.super.apply(function); return this; } - void set(T compoundValue, String key, V value); - V get(T compoundValue, String key); - - T instantiateCompoundValue(); - @Override default void visitInOrder(ConfigEntryVisitor visitor) { if (visitor.enterStructuredEntry(this)) { diff --git a/tweed5/core/src/main/java/de/siphalor/tweed5/core/api/entry/ConfigEntryValueVisitor.java b/tweed5/core/src/main/java/de/siphalor/tweed5/core/api/entry/ConfigEntryValueVisitor.java index ac9b63b..d92e75a 100644 --- a/tweed5/core/src/main/java/de/siphalor/tweed5/core/api/entry/ConfigEntryValueVisitor.java +++ b/tweed5/core/src/main/java/de/siphalor/tweed5/core/api/entry/ConfigEntryValueVisitor.java @@ -3,18 +3,25 @@ package de.siphalor.tweed5.core.api.entry; public interface ConfigEntryValueVisitor { void visitEntry(ConfigEntry entry, T value); - default boolean enterStructuredEntry(ConfigEntry entry, T value) { + default boolean enterStructuredEntry(StructuredConfigEntry entry, T value) { visitEntry(entry, value); return true; } + default boolean enterAddressableStructuredSubEntry(String entryKey, String valueKey, String dataKey) { + return true; + } + default boolean enterStructuredSubEntry(String entryKey, String valueKey) { return true; } + default void leaveAddressableStructuredSubEntry(String entryKey, String valueKey, String dataKey) { + } + default void leaveStructuredSubEntry(String entryKey, String valueKey) { } - default void leaveStructuredEntry(ConfigEntry entry, T value) { + default void leaveStructuredEntry(StructuredConfigEntry entry, T value) { } } diff --git a/tweed5/core/src/main/java/de/siphalor/tweed5/core/api/entry/MutableStructuredConfigEntry.java b/tweed5/core/src/main/java/de/siphalor/tweed5/core/api/entry/MutableStructuredConfigEntry.java new file mode 100644 index 0000000..fd45936 --- /dev/null +++ b/tweed5/core/src/main/java/de/siphalor/tweed5/core/api/entry/MutableStructuredConfigEntry.java @@ -0,0 +1,16 @@ +package de.siphalor.tweed5.core.api.entry; + +import org.jspecify.annotations.NonNull; + +import java.util.function.Consumer; + +public interface MutableStructuredConfigEntry extends AddressableStructuredConfigEntry { + @Override + default AddressableStructuredConfigEntry apply(Consumer> function) { + AddressableStructuredConfigEntry.super.apply(function); + return this; + } + + @NonNull T instantiateValue(); + void set(T value, String key, Object subValue); +} diff --git a/tweed5/core/src/main/java/de/siphalor/tweed5/core/api/entry/NullableConfigEntry.java b/tweed5/core/src/main/java/de/siphalor/tweed5/core/api/entry/NullableConfigEntry.java index aaf6708..e62e31b 100644 --- a/tweed5/core/src/main/java/de/siphalor/tweed5/core/api/entry/NullableConfigEntry.java +++ b/tweed5/core/src/main/java/de/siphalor/tweed5/core/api/entry/NullableConfigEntry.java @@ -5,12 +5,12 @@ import org.jetbrains.annotations.Nullable; import java.util.function.Consumer; -public interface NullableConfigEntry extends StructuredConfigEntry { +public interface NullableConfigEntry extends AddressableStructuredConfigEntry { String NON_NULL_KEY = ":nonNull"; @Override default NullableConfigEntry apply(Consumer> function) { - StructuredConfigEntry.super.apply(function); + AddressableStructuredConfigEntry.super.apply(function); return this; } diff --git a/tweed5/core/src/main/java/de/siphalor/tweed5/core/impl/entry/CollectionConfigEntryImpl.java b/tweed5/core/src/main/java/de/siphalor/tweed5/core/impl/entry/CollectionConfigEntryImpl.java index c15d858..4ef7abf 100644 --- a/tweed5/core/src/main/java/de/siphalor/tweed5/core/impl/entry/CollectionConfigEntryImpl.java +++ b/tweed5/core/src/main/java/de/siphalor/tweed5/core/impl/entry/CollectionConfigEntryImpl.java @@ -2,11 +2,12 @@ package de.siphalor.tweed5.core.impl.entry; import de.siphalor.tweed5.core.api.container.ConfigContainer; import de.siphalor.tweed5.core.api.entry.*; +import org.jspecify.annotations.NonNull; import java.util.Collection; import java.util.function.IntFunction; -public class CollectionConfigEntryImpl> extends BaseConfigEntry implements CollectionConfigEntry { +public class CollectionConfigEntryImpl> extends BaseConfigEntry implements CollectionConfigEntry { private final IntFunction collectionConstructor; private final ConfigEntry elementEntry; diff --git a/tweed5/core/src/main/java/de/siphalor/tweed5/core/impl/entry/NullableConfigEntryImpl.java b/tweed5/core/src/main/java/de/siphalor/tweed5/core/impl/entry/NullableConfigEntryImpl.java index 75076e0..2ffe214 100644 --- a/tweed5/core/src/main/java/de/siphalor/tweed5/core/impl/entry/NullableConfigEntryImpl.java +++ b/tweed5/core/src/main/java/de/siphalor/tweed5/core/impl/entry/NullableConfigEntryImpl.java @@ -24,6 +24,11 @@ public class NullableConfigEntryImpl extends BaseCon this.nonNullEntry = nonNullEntry; } + @Override + public T get(T value, String key) { + return value; + } + @Override public Map> subEntries() { return Collections.singletonMap(NON_NULL_KEY, nonNullEntry); @@ -33,9 +38,9 @@ public class NullableConfigEntryImpl extends BaseCon public void visitInOrder(ConfigEntryValueVisitor visitor, T value) { if (value != null) { if (visitor.enterStructuredEntry(this, value)) { - if (visitor.enterStructuredSubEntry(NON_NULL_KEY, NON_NULL_KEY)) { + if (visitor.enterAddressableStructuredSubEntry(NON_NULL_KEY, NON_NULL_KEY, NON_NULL_KEY)) { nonNullEntry.visitInOrder(visitor, value); - visitor.leaveStructuredSubEntry(NON_NULL_KEY, NON_NULL_KEY); + visitor.leaveAddressableStructuredSubEntry(NON_NULL_KEY, NON_NULL_KEY, NON_NULL_KEY); } visitor.leaveStructuredEntry(this, value); } diff --git a/tweed5/core/src/main/java/de/siphalor/tweed5/core/impl/entry/StaticMapCompoundConfigEntryImpl.java b/tweed5/core/src/main/java/de/siphalor/tweed5/core/impl/entry/StaticMapCompoundConfigEntryImpl.java index 519003c..89646fc 100644 --- a/tweed5/core/src/main/java/de/siphalor/tweed5/core/impl/entry/StaticMapCompoundConfigEntryImpl.java +++ b/tweed5/core/src/main/java/de/siphalor/tweed5/core/impl/entry/StaticMapCompoundConfigEntryImpl.java @@ -2,12 +2,13 @@ package de.siphalor.tweed5.core.impl.entry; import de.siphalor.tweed5.core.api.container.ConfigContainer; import de.siphalor.tweed5.core.api.entry.*; +import org.jspecify.annotations.NonNull; import java.util.LinkedHashMap; import java.util.Map; import java.util.function.IntFunction; -public class StaticMapCompoundConfigEntryImpl> extends BaseConfigEntry implements CompoundConfigEntry { +public class StaticMapCompoundConfigEntryImpl> extends BaseConfigEntry implements CompoundConfigEntry { private final IntFunction mapConstructor; private final Map> compoundEntries; @@ -28,16 +29,15 @@ public class StaticMapCompoundConfigEntryImpl> ext } @Override - public void set(T compoundValue, String key, V value) { + public void set(T compoundValue, String key, Object value) { requireKey(key); compoundValue.put(key, value); } @Override - public V get(T compoundValue, String key) { + public Object get(T compoundValue, String key) { requireKey(key); - //noinspection unchecked - return (V) compoundValue.get(key); + return compoundValue.get(key); } private void requireKey(String key) { @@ -47,29 +47,27 @@ public class StaticMapCompoundConfigEntryImpl> ext } @Override - public T instantiateCompoundValue() { + public T instantiateValue() { return mapConstructor.apply(compoundEntries.size()); } @Override public void visitInOrder(ConfigEntryValueVisitor visitor, T value) { if (visitor.enterStructuredEntry(this, value)) { - if (value != null) { - compoundEntries.forEach((key, entry) -> { - if (visitor.enterStructuredSubEntry(key, key)) { - //noinspection unchecked - ((ConfigEntry) entry).visitInOrder(visitor, value.get(key)); - visitor.leaveStructuredSubEntry(key, key); - } - }); - } + compoundEntries.forEach((key, entry) -> { + if (visitor.enterAddressableStructuredSubEntry(key, key, key)) { + //noinspection unchecked + ((ConfigEntry) entry).visitInOrder(visitor, value.get(key)); + visitor.leaveAddressableStructuredSubEntry(key, key, key); + } + }); visitor.leaveStructuredEntry(this, value); } } @Override public T deepCopy(T value) { - T copy = instantiateCompoundValue(); + T copy = instantiateValue(); value.forEach((String key, Object element) -> { //noinspection unchecked ConfigEntry elementEntry = (ConfigEntry) compoundEntries.get(key); diff --git a/tweed5/default-extensions/src/main/java/de/siphalor/tweed5/defaultextensions/patch/impl/PatchExtensionImpl.java b/tweed5/default-extensions/src/main/java/de/siphalor/tweed5/defaultextensions/patch/impl/PatchExtensionImpl.java index 99338d3..341d27e 100644 --- a/tweed5/default-extensions/src/main/java/de/siphalor/tweed5/defaultextensions/patch/impl/PatchExtensionImpl.java +++ b/tweed5/default-extensions/src/main/java/de/siphalor/tweed5/defaultextensions/patch/impl/PatchExtensionImpl.java @@ -62,7 +62,7 @@ public class PatchExtensionImpl implements PatchExtension, ReadWriteRelatedExten if (targetValue != null) { targetCompoundValue = targetValue; } else { - targetCompoundValue = compoundEntry.instantiateCompoundValue(); + targetCompoundValue = compoundEntry.instantiateValue(); } compoundEntry.subEntries().forEach((key, subEntry) -> { if (!patchInfo.containsEntry(subEntry)) { @@ -70,7 +70,7 @@ public class PatchExtensionImpl implements PatchExtension, ReadWriteRelatedExten } compoundEntry.set( targetCompoundValue, key, patch( - subEntry, + (ConfigEntry) subEntry, compoundEntry.get(targetCompoundValue, key), compoundEntry.get(patchValue, key), patchInfo diff --git a/tweed5/default-extensions/src/main/java/de/siphalor/tweed5/defaultextensions/pather/api/PathTrackingConfigEntryValueVisitor.java b/tweed5/default-extensions/src/main/java/de/siphalor/tweed5/defaultextensions/pather/api/PathTrackingConfigEntryValueVisitor.java index e154b68..e54f3f6 100644 --- a/tweed5/default-extensions/src/main/java/de/siphalor/tweed5/defaultextensions/pather/api/PathTrackingConfigEntryValueVisitor.java +++ b/tweed5/default-extensions/src/main/java/de/siphalor/tweed5/defaultextensions/pather/api/PathTrackingConfigEntryValueVisitor.java @@ -2,6 +2,7 @@ package de.siphalor.tweed5.defaultextensions.pather.api; import de.siphalor.tweed5.core.api.entry.ConfigEntry; import de.siphalor.tweed5.core.api.entry.ConfigEntryValueVisitor; +import de.siphalor.tweed5.core.api.entry.StructuredConfigEntry; import lombok.RequiredArgsConstructor; import org.jspecify.annotations.Nullable; @@ -16,10 +17,19 @@ public class PathTrackingConfigEntryValueVisitor implements ConfigEntryValueVisi } @Override - public boolean enterStructuredEntry(ConfigEntry entry, T value) { + public boolean enterStructuredEntry(StructuredConfigEntry entry, T value) { return delegate.enterStructuredEntry(entry, value); } + @Override + public boolean enterAddressableStructuredSubEntry(String entryKey, String valueKey, String dataKey) { + boolean enter = delegate.enterAddressableStructuredSubEntry(entryKey, valueKey, dataKey); + if (enter) { + pathTracking.pushPathPart(entryKey, valueKey); + } + return enter; + } + @Override public boolean enterStructuredSubEntry(String entryKey, String valueKey) { boolean enter = delegate.enterStructuredSubEntry(entryKey, valueKey); @@ -29,6 +39,12 @@ public class PathTrackingConfigEntryValueVisitor implements ConfigEntryValueVisi return enter; } + @Override + public void leaveAddressableStructuredSubEntry(String entryKey, String valueKey, String dataKey) { + delegate.leaveAddressableStructuredSubEntry(entryKey, valueKey, dataKey); + pathTracking.popPathPart(); + } + @Override public void leaveStructuredSubEntry(String entryKey, String valueKey) { delegate.leaveStructuredSubEntry(entryKey, valueKey); @@ -36,7 +52,7 @@ public class PathTrackingConfigEntryValueVisitor implements ConfigEntryValueVisi } @Override - public void leaveStructuredEntry(ConfigEntry entry, T value) { + public void leaveStructuredEntry(StructuredConfigEntry entry, T value) { delegate.leaveStructuredEntry(entry, value); } } diff --git a/tweed5/default-extensions/src/main/java/de/siphalor/tweed5/defaultextensions/validation/impl/ValidationExtensionImpl.java b/tweed5/default-extensions/src/main/java/de/siphalor/tweed5/defaultextensions/validation/impl/ValidationExtensionImpl.java index 0055823..66443a5 100644 --- a/tweed5/default-extensions/src/main/java/de/siphalor/tweed5/defaultextensions/validation/impl/ValidationExtensionImpl.java +++ b/tweed5/default-extensions/src/main/java/de/siphalor/tweed5/defaultextensions/validation/impl/ValidationExtensionImpl.java @@ -3,6 +3,7 @@ package de.siphalor.tweed5.defaultextensions.validation.impl; import de.siphalor.tweed5.core.api.container.ConfigContainer; import de.siphalor.tweed5.core.api.entry.ConfigEntry; import de.siphalor.tweed5.core.api.entry.ConfigEntryValueVisitor; +import de.siphalor.tweed5.core.api.entry.StructuredConfigEntry; import de.siphalor.tweed5.core.api.extension.TweedExtension; import de.siphalor.tweed5.core.api.extension.TweedExtensionSetupContext; import de.siphalor.tweed5.core.api.middleware.DefaultMiddlewareContainer; @@ -290,12 +291,12 @@ public class ValidationExtensionImpl implements ReadWriteRelatedExtension, Valid } @Override - public boolean enterStructuredEntry(ConfigEntry entry, T value) { + public boolean enterStructuredEntry(StructuredConfigEntry entry, T value) { return true; } @Override - public void leaveStructuredEntry(ConfigEntry entry, T value) { + public void leaveStructuredEntry(StructuredConfigEntry entry, T value) { visitEntry(entry, value); } } diff --git a/tweed5/serde-extension/src/main/java/de/siphalor/tweed5/data/extension/impl/TweedEntryReaderWriterImpls.java b/tweed5/serde-extension/src/main/java/de/siphalor/tweed5/data/extension/impl/TweedEntryReaderWriterImpls.java index cc3bade..e0959a4 100644 --- a/tweed5/serde-extension/src/main/java/de/siphalor/tweed5/data/extension/impl/TweedEntryReaderWriterImpls.java +++ b/tweed5/serde-extension/src/main/java/de/siphalor/tweed5/data/extension/impl/TweedEntryReaderWriterImpls.java @@ -234,7 +234,7 @@ public class TweedEntryReaderWriterImpls { } Map> compoundEntries = entry.subEntries(); - T compoundValue = entry.instantiateCompoundValue(); + T compoundValue = entry.instantiateValue(); while (true) { try { TweedDataToken token = reader.readToken(); diff --git a/tweed5/weaver-pojo-presets-extension/src/main/java/de/siphalor/tweed5/weaver/pojoext/presets/api/DefaultPresetWeavingProcessor.java b/tweed5/weaver-pojo-presets-extension/src/main/java/de/siphalor/tweed5/weaver/pojoext/presets/api/DefaultPresetWeavingProcessor.java index 67b591c..d13f3ce 100644 --- a/tweed5/weaver-pojo-presets-extension/src/main/java/de/siphalor/tweed5/weaver/pojoext/presets/api/DefaultPresetWeavingProcessor.java +++ b/tweed5/weaver-pojo-presets-extension/src/main/java/de/siphalor/tweed5/weaver/pojoext/presets/api/DefaultPresetWeavingProcessor.java @@ -37,7 +37,7 @@ public class DefaultPresetWeavingProcessor implements TweedPojoWeavingExtensi private T instantiateEntry(ConfigEntry entry) { if (entry instanceof CompoundConfigEntry) { - return ((CompoundConfigEntry) entry).instantiateCompoundValue(); + return ((CompoundConfigEntry) entry).instantiateValue(); } else { throw new IllegalArgumentException( "Can only determine default preset from instantiation for POJOs. " diff --git a/tweed5/weaver-pojo/src/main/java/de/siphalor/tweed5/weaver/pojo/impl/entry/StaticPojoCompoundConfigEntry.java b/tweed5/weaver-pojo/src/main/java/de/siphalor/tweed5/weaver/pojo/impl/entry/StaticPojoCompoundConfigEntry.java index db0a425..b3ef8cb 100644 --- a/tweed5/weaver-pojo/src/main/java/de/siphalor/tweed5/weaver/pojo/impl/entry/StaticPojoCompoundConfigEntry.java +++ b/tweed5/weaver-pojo/src/main/java/de/siphalor/tweed5/weaver/pojo/impl/entry/StaticPojoCompoundConfigEntry.java @@ -6,7 +6,6 @@ import de.siphalor.tweed5.core.api.entry.BaseConfigEntry; import de.siphalor.tweed5.core.api.entry.ConfigEntry; import de.siphalor.tweed5.core.api.entry.ConfigEntryValueVisitor; import de.siphalor.tweed5.weaver.pojo.api.entry.WeavableCompoundConfigEntry; -import org.jspecify.annotations.Nullable; import java.util.Collections; import java.util.LinkedHashMap; @@ -41,7 +40,7 @@ public class StaticPojoCompoundConfigEntry extends BaseConfigEntry impleme } @Override - public void set(T compoundValue, String key, V value) { + public void set(T compoundValue, String key, Object value) { SubEntry subEntry = subEntries.get(key); if (subEntry == null) { throw new IllegalArgumentException("Unknown config entry: " + key); @@ -55,22 +54,21 @@ public class StaticPojoCompoundConfigEntry extends BaseConfigEntry impleme } @Override - public V get(T compoundValue, String key) { + public Object get(T compoundValue, String key) { SubEntry subEntry = subEntries.get(key); if (subEntry == null) { throw new IllegalArgumentException("Unknown config entry: " + key); } try { - //noinspection unchecked - return (V) subEntry.getter().invoke(compoundValue); + return subEntry.getter().invoke(compoundValue); } catch (Throwable e) { throw new IllegalStateException("Failed to get value for config entry \"" + key + "\"", e); } } @Override - public T instantiateCompoundValue() { + public T instantiateValue() { try { return noArgsConstructor.get(); } catch (Throwable e) { @@ -82,22 +80,24 @@ public class StaticPojoCompoundConfigEntry extends BaseConfigEntry impleme public void visitInOrder(ConfigEntryValueVisitor visitor, T value) { if (visitor.enterStructuredEntry(this, value)) { subEntries.forEach((key, entry) -> { - if (visitor.enterStructuredSubEntry(key, key)) { + if (visitor.enterAddressableStructuredSubEntry(key, key, key)) { try { Object subValue = entry.getter().invoke(value); //noinspection unchecked ((ConfigEntry) entry.configEntry()).visitInOrder(visitor, subValue); + visitor.leaveAddressableStructuredSubEntry(key, key, key); } catch (Throwable e) { throw new RuntimeException("Failed to get compound sub entry value \"" + key + "\""); } } }); + visitor.leaveStructuredEntry(this, value); } } @Override public T deepCopy(T value) { - T copy = instantiateCompoundValue(); + T copy = instantiateValue(); for (SubEntry subEntry : subEntries.values()) { try { Object subValue = subEntry.getter().invoke(value);