[core, serde-extension, weaver-pojo] Remove the coherent from collection stuff

This commit is contained in:
2025-04-20 21:19:00 +02:00
parent a50ce563e6
commit de92d6843f
16 changed files with 86 additions and 87 deletions

View File

@@ -1,6 +1,6 @@
package de.siphalor.tweed5.weaver.pojo.api.annotation;
import de.siphalor.tweed5.weaver.pojo.api.entry.WeavableCoherentCollectionConfigEntry;
import de.siphalor.tweed5.weaver.pojo.api.entry.WeavableCollectionConfigEntry;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -9,6 +9,6 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.TYPE_USE})
public @interface CoherentCollectionWeaving {
Class<? extends WeavableCoherentCollectionConfigEntry> entryClass() default WeavableCoherentCollectionConfigEntry.class;
public @interface CollectionWeaving {
Class<? extends WeavableCollectionConfigEntry> entryClass() default WeavableCollectionConfigEntry.class;
}

View File

@@ -1,6 +1,6 @@
package de.siphalor.tweed5.weaver.pojo.api.entry;
import de.siphalor.tweed5.core.api.entry.CoherentCollectionConfigEntry;
import de.siphalor.tweed5.core.api.entry.CollectionConfigEntry;
import de.siphalor.tweed5.core.api.entry.ConfigEntry;
import de.siphalor.tweed5.weaver.pojo.impl.weaving.PojoWeavingException;
@@ -15,9 +15,9 @@ import java.util.function.IntFunction;
* A constructor taking the value {@link Class}
* and a {@link java.util.function.IntFunction} that allows to instantiate the value class with a single capacity argument.
*/
public interface WeavableCoherentCollectionConfigEntry<E, T extends Collection<E>>
extends CoherentCollectionConfigEntry<E, T> {
static <E, T extends Collection<E>, C extends WeavableCoherentCollectionConfigEntry<E, T>> C instantiate(
public interface WeavableCollectionConfigEntry<E, T extends Collection<E>>
extends CollectionConfigEntry<E, T> {
static <E, T extends Collection<E>, C extends WeavableCollectionConfigEntry<E, T>> C instantiate(
Class<C> weavableClass, Class<T> valueClass, IntFunction<T> constructor
) throws PojoWeavingException {
try {

View File

@@ -3,11 +3,12 @@ package de.siphalor.tweed5.weaver.pojo.api.weaving;
import de.siphalor.tweed5.core.api.entry.ConfigEntry;
import de.siphalor.tweed5.core.api.extension.RegisteredExtensionData;
import de.siphalor.tweed5.typeutils.api.type.ActualType;
import de.siphalor.tweed5.weaver.pojo.api.annotation.CoherentCollectionWeaving;
import de.siphalor.tweed5.weaver.pojo.api.entry.WeavableCoherentCollectionConfigEntry;
import de.siphalor.tweed5.weaver.pojo.api.annotation.CollectionWeaving;
import de.siphalor.tweed5.weaver.pojo.api.entry.WeavableCollectionConfigEntry;
import de.siphalor.tweed5.weaver.pojo.impl.entry.CollectionConfigEntryImpl;
import de.siphalor.tweed5.weaver.pojo.impl.weaving.PojoWeavingException;
import de.siphalor.tweed5.weaver.pojo.impl.weaving.coherentcollection.CoherentCollectionWeavingConfig;
import de.siphalor.tweed5.weaver.pojo.impl.weaving.coherentcollection.CoherentCollectionWeavingConfigImpl;
import de.siphalor.tweed5.weaver.pojo.impl.weaving.collection.CollectionWeavingConfig;
import de.siphalor.tweed5.weaver.pojo.impl.weaving.collection.CollectionWeavingConfigImpl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -18,16 +19,16 @@ import java.lang.reflect.AnnotatedElement;
import java.util.*;
import java.util.function.IntFunction;
public class CoherentCollectionPojoWeaver implements TweedPojoWeaver {
private static final CoherentCollectionWeavingConfig DEFAULT_WEAVING_CONFIG = CoherentCollectionWeavingConfigImpl.builder()
.coherentCollectionEntryClass(de.siphalor.tweed5.weaver.pojo.impl.entry.CoherentCollectionConfigEntryImpl.class)
public class CollectionPojoWeaver implements TweedPojoWeaver {
private static final CollectionWeavingConfig DEFAULT_WEAVING_CONFIG = CollectionWeavingConfigImpl.builder()
.collectionEntryClass(CollectionConfigEntryImpl.class)
.build();
private RegisteredExtensionData<WeavingContext.ExtensionsData, CoherentCollectionWeavingConfig> weavingConfigAccess;
private RegisteredExtensionData<WeavingContext.ExtensionsData, CollectionWeavingConfig> weavingConfigAccess;
@Override
public void setup(SetupContext context) {
this.weavingConfigAccess = context.registerWeavingContextExtensionData(CoherentCollectionWeavingConfig.class);
this.weavingConfigAccess = context.registerWeavingContextExtensionData(CollectionWeavingConfig.class);
}
@Override
@@ -37,15 +38,15 @@ public class CoherentCollectionPojoWeaver implements TweedPojoWeaver {
return null;
}
try {
CoherentCollectionWeavingConfig weavingConfig = getOrCreateWeavingConfig(context);
CollectionWeavingConfig weavingConfig = getOrCreateWeavingConfig(context);
WeavingContext.ExtensionsData newExtensionsData = context.extensionsData().copy();
weavingConfigAccess.set(newExtensionsData, weavingConfig);
IntFunction<Collection<Object>> constructor = getCollectionConstructor(valueType);
//noinspection unchecked,rawtypes
WeavableCoherentCollectionConfigEntry configEntry = WeavableCoherentCollectionConfigEntry.instantiate(
(Class) weavingConfig.coherentCollectionEntryClass(),
WeavableCollectionConfigEntry configEntry = WeavableCollectionConfigEntry.instantiate(
(Class) weavingConfig.collectionEntryClass(),
(Class) valueType.declaredType(),
constructor
);
@@ -65,31 +66,31 @@ public class CoherentCollectionPojoWeaver implements TweedPojoWeaver {
}
}
private CoherentCollectionWeavingConfig getOrCreateWeavingConfig(WeavingContext context) {
CoherentCollectionWeavingConfig parent;
if (context.extensionsData().isPatchworkPartSet(CoherentCollectionWeavingConfig.class)) {
parent = (CoherentCollectionWeavingConfig) context.extensionsData();
private CollectionWeavingConfig getOrCreateWeavingConfig(WeavingContext context) {
CollectionWeavingConfig parent;
if (context.extensionsData().isPatchworkPartSet(CollectionWeavingConfig.class)) {
parent = (CollectionWeavingConfig) context.extensionsData();
} else {
parent = DEFAULT_WEAVING_CONFIG;
}
CoherentCollectionWeavingConfig local = createWeavingConfigFromAnnotations(context.annotations());
CollectionWeavingConfig local = createWeavingConfigFromAnnotations(context.annotations());
if (local == null) {
return parent;
}
return CoherentCollectionWeavingConfigImpl.withOverrides(parent, local);
return CollectionWeavingConfigImpl.withOverrides(parent, local);
}
private CoherentCollectionWeavingConfig createWeavingConfigFromAnnotations(@NotNull AnnotatedElement annotations) {
CoherentCollectionWeaving annotation = annotations.getAnnotation(CoherentCollectionWeaving.class);
private CollectionWeavingConfig createWeavingConfigFromAnnotations(@NotNull AnnotatedElement annotations) {
CollectionWeaving annotation = annotations.getAnnotation(CollectionWeaving.class);
if (annotation == null) {
return null;
}
CoherentCollectionWeavingConfigImpl.CoherentCollectionWeavingConfigImplBuilder builder = CoherentCollectionWeavingConfigImpl.builder();
CollectionWeavingConfigImpl.CollectionWeavingConfigImplBuilder builder = CollectionWeavingConfigImpl.builder();
if (annotation.entryClass() != null) {
builder.coherentCollectionEntryClass(annotation.entryClass());
builder.collectionEntryClass(annotation.entryClass());
}
return builder.build();

View File

@@ -4,7 +4,7 @@ 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.core.api.entry.ConfigEntryVisitor;
import de.siphalor.tweed5.weaver.pojo.api.entry.WeavableCoherentCollectionConfigEntry;
import de.siphalor.tweed5.weaver.pojo.api.entry.WeavableCollectionConfigEntry;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
@@ -16,11 +16,11 @@ import java.util.function.IntFunction;
@Getter
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CoherentCollectionConfigEntryImpl<E, T extends Collection<E>> extends BaseConfigEntry<T> implements WeavableCoherentCollectionConfigEntry<E, T> {
public class CollectionConfigEntryImpl<E, T extends Collection<E>> extends BaseConfigEntry<T> implements WeavableCollectionConfigEntry<E, T> {
private final IntFunction<T> constructor;
private ConfigEntry<E> elementEntry;
public CoherentCollectionConfigEntryImpl(@NotNull Class<T> valueClass, IntFunction<T> constructor) {
public CollectionConfigEntryImpl(@NotNull Class<T> valueClass, IntFunction<T> constructor) {
super(valueClass);
this.constructor = constructor;
}

View File

@@ -1,10 +0,0 @@
package de.siphalor.tweed5.weaver.pojo.impl.weaving.coherentcollection;
import de.siphalor.tweed5.weaver.pojo.api.entry.WeavableCoherentCollectionConfigEntry;
import org.jetbrains.annotations.Nullable;
public interface CoherentCollectionWeavingConfig {
@SuppressWarnings("rawtypes")
@Nullable
Class<? extends WeavableCoherentCollectionConfigEntry> coherentCollectionEntryClass();
}

View File

@@ -1,21 +0,0 @@
package de.siphalor.tweed5.weaver.pojo.impl.weaving.coherentcollection;
import de.siphalor.tweed5.weaver.pojo.api.entry.WeavableCoherentCollectionConfigEntry;
import lombok.Builder;
import lombok.Value;
import org.jetbrains.annotations.Nullable;
@Builder
@Value
public class CoherentCollectionWeavingConfigImpl implements CoherentCollectionWeavingConfig {
@SuppressWarnings("rawtypes")
@Nullable
Class<? extends WeavableCoherentCollectionConfigEntry> coherentCollectionEntryClass;
public static CoherentCollectionWeavingConfigImpl withOverrides(CoherentCollectionWeavingConfig self, CoherentCollectionWeavingConfig overrides) {
return CoherentCollectionWeavingConfigImpl.builder()
.coherentCollectionEntryClass(overrides.coherentCollectionEntryClass() != null ? overrides.coherentCollectionEntryClass() : self.coherentCollectionEntryClass())
.build();
}
}

View File

@@ -0,0 +1,10 @@
package de.siphalor.tweed5.weaver.pojo.impl.weaving.collection;
import de.siphalor.tweed5.weaver.pojo.api.entry.WeavableCollectionConfigEntry;
import org.jetbrains.annotations.Nullable;
public interface CollectionWeavingConfig {
@SuppressWarnings("rawtypes")
@Nullable
Class<? extends WeavableCollectionConfigEntry> collectionEntryClass();
}

View File

@@ -0,0 +1,21 @@
package de.siphalor.tweed5.weaver.pojo.impl.weaving.collection;
import de.siphalor.tweed5.weaver.pojo.api.entry.WeavableCollectionConfigEntry;
import lombok.Builder;
import lombok.Value;
import org.jetbrains.annotations.Nullable;
@Builder
@Value
public class CollectionWeavingConfigImpl implements CollectionWeavingConfig {
@SuppressWarnings("rawtypes")
@Nullable
Class<? extends WeavableCollectionConfigEntry> collectionEntryClass;
public static CollectionWeavingConfigImpl withOverrides(CollectionWeavingConfig self, CollectionWeavingConfig overrides) {
return CollectionWeavingConfigImpl.builder()
.collectionEntryClass(overrides.collectionEntryClass() != null ? overrides.collectionEntryClass() : self.collectionEntryClass())
.build();
}
}

View File

@@ -5,7 +5,7 @@ import de.siphalor.tweed5.core.api.container.ConfigContainer;
import de.siphalor.tweed5.core.api.extension.TweedExtension;
import de.siphalor.tweed5.weaver.pojo.api.annotation.CompoundWeaving;
import de.siphalor.tweed5.weaver.pojo.api.annotation.PojoWeaving;
import de.siphalor.tweed5.weaver.pojo.api.weaving.CoherentCollectionPojoWeaver;
import de.siphalor.tweed5.weaver.pojo.api.weaving.CollectionPojoWeaver;
import de.siphalor.tweed5.weaver.pojo.api.weaving.CompoundPojoWeaver;
import de.siphalor.tweed5.weaver.pojo.api.weaving.TrivialPojoWeaver;
import lombok.Data;
@@ -90,7 +90,7 @@ class TweedPojoWeaverBootstrapperTest {
boolean somethingElse;
}
@PojoWeaving(weavers = {CompoundPojoWeaver.class, CoherentCollectionPojoWeaver.class, TrivialPojoWeaver.class})
@PojoWeaving(weavers = {CompoundPojoWeaver.class, CollectionPojoWeaver.class, TrivialPojoWeaver.class})
@CompoundWeaving(namingFormat = "camel_case")
@Data
public static class CompoundWithList {

View File

@@ -1,12 +1,10 @@
package de.siphalor.tweed5.weaver.pojo.test;
import de.siphalor.tweed5.core.api.entry.CoherentCollectionConfigEntry;
import de.siphalor.tweed5.core.api.entry.CollectionConfigEntry;
import de.siphalor.tweed5.core.api.entry.CompoundConfigEntry;
import de.siphalor.tweed5.core.api.entry.ConfigEntry;
import de.siphalor.tweed5.core.api.entry.SimpleConfigEntry;
import de.siphalor.tweed5.weaver.pojo.api.weaving.CoherentCollectionPojoWeaver;
import java.util.Collection;
import java.util.function.Consumer;
import static org.assertj.core.api.Assertions.assertThat;
@@ -39,11 +37,11 @@ public class ConfigEntryAssertions {
public static Consumer<Object> isCollectionEntryForClass(
Class<?> collectionClass,
Consumer<CoherentCollectionConfigEntry<?, ?>> condition
Consumer<CollectionConfigEntry<?, ?>> condition
) {
return object -> assertThat(object)
.as("Should be a collection config entry for class " + collectionClass.getName())
.asInstanceOf(type(CoherentCollectionConfigEntry.class))
.asInstanceOf(type(CollectionConfigEntry.class))
.as("Collection entry for class " + collectionClass.getSimpleName())
.satisfies(
listEntry -> assertThat(listEntry.valueClass())