[core, serde-extension, weaver-pojo] Remove the coherent from collection stuff
This commit is contained in:
@@ -2,7 +2,7 @@ package de.siphalor.tweed5.core.api.entry;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
public interface CoherentCollectionConfigEntry<E, T extends Collection<E>> extends ConfigEntry<T> {
|
public interface CollectionConfigEntry<E, T extends Collection<E>> extends ConfigEntry<T> {
|
||||||
ConfigEntry<E> elementEntry();
|
ConfigEntry<E> elementEntry();
|
||||||
|
|
||||||
T instantiateCollection(int size);
|
T instantiateCollection(int size);
|
||||||
@@ -6,11 +6,11 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.function.IntFunction;
|
import java.util.function.IntFunction;
|
||||||
|
|
||||||
public class CoherentCollectionConfigEntryImpl<E, T extends Collection<E>> extends BaseConfigEntry<T> implements CoherentCollectionConfigEntry<E, T> {
|
public class CollectionConfigEntryImpl<E, T extends Collection<E>> extends BaseConfigEntry<T> implements CollectionConfigEntry<E, T> {
|
||||||
private final IntFunction<T> collectionConstructor;
|
private final IntFunction<T> collectionConstructor;
|
||||||
private ConfigEntry<E> elementEntry;
|
private ConfigEntry<E> elementEntry;
|
||||||
|
|
||||||
public CoherentCollectionConfigEntryImpl(Class<T> valueClass, IntFunction<T> collectionConstructor) {
|
public CollectionConfigEntryImpl(Class<T> valueClass, IntFunction<T> collectionConstructor) {
|
||||||
super(valueClass);
|
super(valueClass);
|
||||||
this.collectionConstructor = collectionConstructor;
|
this.collectionConstructor = collectionConstructor;
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package de.siphalor.tweed5.data.extension.api.readwrite;
|
package de.siphalor.tweed5.data.extension.api.readwrite;
|
||||||
|
|
||||||
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.CompoundConfigEntry;
|
||||||
import de.siphalor.tweed5.core.api.entry.ConfigEntry;
|
import de.siphalor.tweed5.core.api.entry.ConfigEntry;
|
||||||
import de.siphalor.tweed5.data.extension.api.TweedEntryReader;
|
import de.siphalor.tweed5.data.extension.api.TweedEntryReader;
|
||||||
@@ -53,9 +53,9 @@ public class TweedEntryReaderWriters {
|
|||||||
return new TweedEntryReaderWriterImpls.NullableWriter<>(delegate);
|
return new TweedEntryReaderWriterImpls.NullableWriter<>(delegate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T, C extends Collection<T>> TweedEntryReaderWriter<C, CoherentCollectionConfigEntry<T, C>> coherentCollectionReaderWriter() {
|
public static <T, C extends Collection<T>> TweedEntryReaderWriter<C, CollectionConfigEntry<T, C>> collectionReaderWriter() {
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
return (TweedEntryReaderWriter<C, CoherentCollectionConfigEntry<T,C>>)(TweedEntryReaderWriter<?, ?>) TweedEntryReaderWriterImpls.COHERENT_COLLECTION_READER_WRITER;
|
return (TweedEntryReaderWriter<C, CollectionConfigEntry<T,C>>)(TweedEntryReaderWriter<?, ?>) TweedEntryReaderWriterImpls.COLLECTION_READER_WRITER;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> TweedEntryReaderWriter<T, CompoundConfigEntry<T>> compoundReaderWriter() {
|
public static <T> TweedEntryReaderWriter<T, CompoundConfigEntry<T>> compoundReaderWriter() {
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ public class DefaultTweedEntryReaderWriterImplsProvider implements TweedReaderWr
|
|||||||
context.registerWriterFactory("tweed5.double", new StaticReaderWriterFactory<>(doubleReaderWriter()));
|
context.registerWriterFactory("tweed5.double", new StaticReaderWriterFactory<>(doubleReaderWriter()));
|
||||||
context.registerReaderFactory("tweed5.string", new StaticReaderWriterFactory<>(stringReaderWriter()));
|
context.registerReaderFactory("tweed5.string", new StaticReaderWriterFactory<>(stringReaderWriter()));
|
||||||
context.registerWriterFactory("tweed5.string", new StaticReaderWriterFactory<>(stringReaderWriter()));
|
context.registerWriterFactory("tweed5.string", new StaticReaderWriterFactory<>(stringReaderWriter()));
|
||||||
context.registerReaderFactory("tweed5.collection.coherent", new StaticReaderWriterFactory<>(coherentCollectionReaderWriter()));
|
context.registerReaderFactory("tweed5.collection", new StaticReaderWriterFactory<>(collectionReaderWriter()));
|
||||||
context.registerWriterFactory("tweed5.collection.coherent", new StaticReaderWriterFactory<>(coherentCollectionReaderWriter()));
|
context.registerWriterFactory("tweed5.collection", new StaticReaderWriterFactory<>(collectionReaderWriter()));
|
||||||
context.registerReaderFactory("tweed5.compound", new StaticReaderWriterFactory<>(compoundReaderWriter()));
|
context.registerReaderFactory("tweed5.compound", new StaticReaderWriterFactory<>(compoundReaderWriter()));
|
||||||
context.registerWriterFactory("tweed5.compound", new StaticReaderWriterFactory<>(compoundReaderWriter()));
|
context.registerWriterFactory("tweed5.compound", new StaticReaderWriterFactory<>(compoundReaderWriter()));
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package de.siphalor.tweed5.data.extension.impl;
|
package de.siphalor.tweed5.data.extension.impl;
|
||||||
|
|
||||||
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.CompoundConfigEntry;
|
||||||
import de.siphalor.tweed5.core.api.entry.ConfigEntry;
|
import de.siphalor.tweed5.core.api.entry.ConfigEntry;
|
||||||
import de.siphalor.tweed5.data.extension.api.*;
|
import de.siphalor.tweed5.data.extension.api.*;
|
||||||
@@ -26,7 +26,7 @@ public class TweedEntryReaderWriterImpls {
|
|||||||
public static final TweedEntryReaderWriter<Double, ConfigEntry<Double>> DOUBLE_READER_WRITER = new PrimitiveReaderWriter<>(TweedDataToken::readAsDouble, TweedDataVisitor::visitDouble);
|
public static final TweedEntryReaderWriter<Double, ConfigEntry<Double>> DOUBLE_READER_WRITER = new PrimitiveReaderWriter<>(TweedDataToken::readAsDouble, TweedDataVisitor::visitDouble);
|
||||||
public static final TweedEntryReaderWriter<String, ConfigEntry<String>> STRING_READER_WRITER = new PrimitiveReaderWriter<>(TweedDataToken::readAsString, TweedDataVisitor::visitString);
|
public static final TweedEntryReaderWriter<String, ConfigEntry<String>> STRING_READER_WRITER = new PrimitiveReaderWriter<>(TweedDataToken::readAsString, TweedDataVisitor::visitString);
|
||||||
|
|
||||||
public static final TweedEntryReaderWriter<Collection<Object>, CoherentCollectionConfigEntry<Object, Collection<Object>>> COHERENT_COLLECTION_READER_WRITER = new CoherentCollectionReaderWriter<>();
|
public static final TweedEntryReaderWriter<Collection<Object>, CollectionConfigEntry<Object, Collection<Object>>> COLLECTION_READER_WRITER = new CollectionReaderWriter<>();
|
||||||
public static final TweedEntryReaderWriter<Object, CompoundConfigEntry<Object>> COMPOUND_READER_WRITER = new CompoundReaderWriter<>();
|
public static final TweedEntryReaderWriter<Object, CompoundConfigEntry<Object>> COMPOUND_READER_WRITER = new CompoundReaderWriter<>();
|
||||||
|
|
||||||
public static final TweedEntryReaderWriter<Object, ConfigEntry<Object>> NOOP_READER_WRITER = new NoopReaderWriter();
|
public static final TweedEntryReaderWriter<Object, ConfigEntry<Object>> NOOP_READER_WRITER = new NoopReaderWriter();
|
||||||
@@ -76,9 +76,9 @@ public class TweedEntryReaderWriterImpls {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CoherentCollectionReaderWriter<T, C extends Collection<T>> implements TweedEntryReaderWriter<C, CoherentCollectionConfigEntry<T, C>> {
|
public static class CollectionReaderWriter<T, C extends Collection<T>> implements TweedEntryReaderWriter<C, CollectionConfigEntry<T, C>> {
|
||||||
@Override
|
@Override
|
||||||
public C read(TweedDataReader reader, CoherentCollectionConfigEntry<T, C> entry, TweedReadContext context) throws TweedEntryReadException, TweedDataReadException {
|
public C read(TweedDataReader reader, CollectionConfigEntry<T, C> entry, TweedReadContext context) throws TweedEntryReadException, TweedDataReadException {
|
||||||
assertIsToken(reader.readToken(), TweedDataToken::isListStart, "Expected list start");
|
assertIsToken(reader.readToken(), TweedDataToken::isListStart, "Expected list start");
|
||||||
TweedDataToken token = reader.peekToken();
|
TweedDataToken token = reader.peekToken();
|
||||||
if (token.isListEnd()) {
|
if (token.isListEnd()) {
|
||||||
@@ -107,7 +107,7 @@ public class TweedEntryReaderWriterImpls {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(TweedDataVisitor writer, C value, CoherentCollectionConfigEntry<T, C> entry, TweedWriteContext context) throws TweedEntryWriteException, TweedDataWriteException {
|
public void write(TweedDataVisitor writer, C value, CollectionConfigEntry<T, C> entry, TweedWriteContext context) throws TweedEntryWriteException, TweedDataWriteException {
|
||||||
requireNonNullWriteValue(value);
|
requireNonNullWriteValue(value);
|
||||||
|
|
||||||
if (value.isEmpty()) {
|
if (value.isEmpty()) {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import de.siphalor.tweed5.core.api.container.ConfigContainer;
|
|||||||
import de.siphalor.tweed5.core.api.extension.EntryExtensionsData;
|
import de.siphalor.tweed5.core.api.extension.EntryExtensionsData;
|
||||||
import de.siphalor.tweed5.core.api.extension.RegisteredExtensionData;
|
import de.siphalor.tweed5.core.api.extension.RegisteredExtensionData;
|
||||||
import de.siphalor.tweed5.core.impl.DefaultConfigContainer;
|
import de.siphalor.tweed5.core.impl.DefaultConfigContainer;
|
||||||
import de.siphalor.tweed5.core.impl.entry.CoherentCollectionConfigEntryImpl;
|
import de.siphalor.tweed5.core.impl.entry.CollectionConfigEntryImpl;
|
||||||
import de.siphalor.tweed5.core.impl.entry.SimpleConfigEntryImpl;
|
import de.siphalor.tweed5.core.impl.entry.SimpleConfigEntryImpl;
|
||||||
import de.siphalor.tweed5.core.impl.entry.StaticMapCompoundConfigEntryImpl;
|
import de.siphalor.tweed5.core.impl.entry.StaticMapCompoundConfigEntryImpl;
|
||||||
import de.siphalor.tweed5.data.extension.api.EntryReaderWriterDefinition;
|
import de.siphalor.tweed5.data.extension.api.EntryReaderWriterDefinition;
|
||||||
@@ -49,7 +49,7 @@ class ReadWriteExtensionImplTest {
|
|||||||
SimpleConfigEntryImpl<Integer> intEntry = new SimpleConfigEntryImpl<>(Integer.class);
|
SimpleConfigEntryImpl<Integer> intEntry = new SimpleConfigEntryImpl<>(Integer.class);
|
||||||
rootEntry.addSubEntry("int", intEntry);
|
rootEntry.addSubEntry("int", intEntry);
|
||||||
|
|
||||||
CoherentCollectionConfigEntryImpl<Boolean, List<Boolean>> listEntry = new CoherentCollectionConfigEntryImpl<>((Class<List<Boolean>>) (Class<?>) List.class, ArrayList::new);
|
CollectionConfigEntryImpl<Boolean, List<Boolean>> listEntry = new CollectionConfigEntryImpl<>((Class<List<Boolean>>) (Class<?>) List.class, ArrayList::new);
|
||||||
rootEntry.addSubEntry("list", listEntry);
|
rootEntry.addSubEntry("list", listEntry);
|
||||||
|
|
||||||
SimpleConfigEntryImpl<Boolean> booleanEntry = new SimpleConfigEntryImpl<>(Boolean.class);
|
SimpleConfigEntryImpl<Boolean> booleanEntry = new SimpleConfigEntryImpl<>(Boolean.class);
|
||||||
@@ -60,7 +60,7 @@ class ReadWriteExtensionImplTest {
|
|||||||
RegisteredExtensionData<EntryExtensionsData, EntryReaderWriterDefinition> readerWriterData = (RegisteredExtensionData<EntryExtensionsData, EntryReaderWriterDefinition>) configContainer.entryDataExtensions().get(EntryReaderWriterDefinition.class);
|
RegisteredExtensionData<EntryExtensionsData, EntryReaderWriterDefinition> readerWriterData = (RegisteredExtensionData<EntryExtensionsData, EntryReaderWriterDefinition>) configContainer.entryDataExtensions().get(EntryReaderWriterDefinition.class);
|
||||||
readerWriterData.set(rootEntry.extensionsData(), new TrivialEntryReaderWriterDefinition(TweedEntryReaderWriters.compoundReaderWriter()));
|
readerWriterData.set(rootEntry.extensionsData(), new TrivialEntryReaderWriterDefinition(TweedEntryReaderWriters.compoundReaderWriter()));
|
||||||
readerWriterData.set(intEntry.extensionsData(), new TrivialEntryReaderWriterDefinition(TweedEntryReaderWriters.intReaderWriter()));
|
readerWriterData.set(intEntry.extensionsData(), new TrivialEntryReaderWriterDefinition(TweedEntryReaderWriters.intReaderWriter()));
|
||||||
readerWriterData.set(listEntry.extensionsData(), new TrivialEntryReaderWriterDefinition(TweedEntryReaderWriters.coherentCollectionReaderWriter()));
|
readerWriterData.set(listEntry.extensionsData(), new TrivialEntryReaderWriterDefinition(TweedEntryReaderWriters.collectionReaderWriter()));
|
||||||
readerWriterData.set(booleanEntry.extensionsData(), new TrivialEntryReaderWriterDefinition(TweedEntryReaderWriters.booleanReaderWriter()));
|
readerWriterData.set(booleanEntry.extensionsData(), new TrivialEntryReaderWriterDefinition(TweedEntryReaderWriters.booleanReaderWriter()));
|
||||||
|
|
||||||
configContainer.initialize();
|
configContainer.initialize();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package de.siphalor.tweed5.weaver.pojo.api.annotation;
|
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.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
@@ -9,6 +9,6 @@ import java.lang.annotation.Target;
|
|||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target({ElementType.TYPE, ElementType.TYPE_USE})
|
@Target({ElementType.TYPE, ElementType.TYPE_USE})
|
||||||
public @interface CoherentCollectionWeaving {
|
public @interface CollectionWeaving {
|
||||||
Class<? extends WeavableCoherentCollectionConfigEntry> entryClass() default WeavableCoherentCollectionConfigEntry.class;
|
Class<? extends WeavableCollectionConfigEntry> entryClass() default WeavableCollectionConfigEntry.class;
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package de.siphalor.tweed5.weaver.pojo.api.entry;
|
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.core.api.entry.ConfigEntry;
|
||||||
import de.siphalor.tweed5.weaver.pojo.impl.weaving.PojoWeavingException;
|
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}
|
* 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.
|
* 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>>
|
public interface WeavableCollectionConfigEntry<E, T extends Collection<E>>
|
||||||
extends CoherentCollectionConfigEntry<E, T> {
|
extends CollectionConfigEntry<E, T> {
|
||||||
static <E, T extends Collection<E>, C extends WeavableCoherentCollectionConfigEntry<E, T>> C instantiate(
|
static <E, T extends Collection<E>, C extends WeavableCollectionConfigEntry<E, T>> C instantiate(
|
||||||
Class<C> weavableClass, Class<T> valueClass, IntFunction<T> constructor
|
Class<C> weavableClass, Class<T> valueClass, IntFunction<T> constructor
|
||||||
) throws PojoWeavingException {
|
) throws PojoWeavingException {
|
||||||
try {
|
try {
|
||||||
@@ -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.entry.ConfigEntry;
|
||||||
import de.siphalor.tweed5.core.api.extension.RegisteredExtensionData;
|
import de.siphalor.tweed5.core.api.extension.RegisteredExtensionData;
|
||||||
import de.siphalor.tweed5.typeutils.api.type.ActualType;
|
import de.siphalor.tweed5.typeutils.api.type.ActualType;
|
||||||
import de.siphalor.tweed5.weaver.pojo.api.annotation.CoherentCollectionWeaving;
|
import de.siphalor.tweed5.weaver.pojo.api.annotation.CollectionWeaving;
|
||||||
import de.siphalor.tweed5.weaver.pojo.api.entry.WeavableCoherentCollectionConfigEntry;
|
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.PojoWeavingException;
|
||||||
import de.siphalor.tweed5.weaver.pojo.impl.weaving.coherentcollection.CoherentCollectionWeavingConfig;
|
import de.siphalor.tweed5.weaver.pojo.impl.weaving.collection.CollectionWeavingConfig;
|
||||||
import de.siphalor.tweed5.weaver.pojo.impl.weaving.coherentcollection.CoherentCollectionWeavingConfigImpl;
|
import de.siphalor.tweed5.weaver.pojo.impl.weaving.collection.CollectionWeavingConfigImpl;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -18,16 +19,16 @@ import java.lang.reflect.AnnotatedElement;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.IntFunction;
|
import java.util.function.IntFunction;
|
||||||
|
|
||||||
public class CoherentCollectionPojoWeaver implements TweedPojoWeaver {
|
public class CollectionPojoWeaver implements TweedPojoWeaver {
|
||||||
private static final CoherentCollectionWeavingConfig DEFAULT_WEAVING_CONFIG = CoherentCollectionWeavingConfigImpl.builder()
|
private static final CollectionWeavingConfig DEFAULT_WEAVING_CONFIG = CollectionWeavingConfigImpl.builder()
|
||||||
.coherentCollectionEntryClass(de.siphalor.tweed5.weaver.pojo.impl.entry.CoherentCollectionConfigEntryImpl.class)
|
.collectionEntryClass(CollectionConfigEntryImpl.class)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
private RegisteredExtensionData<WeavingContext.ExtensionsData, CoherentCollectionWeavingConfig> weavingConfigAccess;
|
private RegisteredExtensionData<WeavingContext.ExtensionsData, CollectionWeavingConfig> weavingConfigAccess;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup(SetupContext context) {
|
public void setup(SetupContext context) {
|
||||||
this.weavingConfigAccess = context.registerWeavingContextExtensionData(CoherentCollectionWeavingConfig.class);
|
this.weavingConfigAccess = context.registerWeavingContextExtensionData(CollectionWeavingConfig.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -37,15 +38,15 @@ public class CoherentCollectionPojoWeaver implements TweedPojoWeaver {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
CoherentCollectionWeavingConfig weavingConfig = getOrCreateWeavingConfig(context);
|
CollectionWeavingConfig weavingConfig = getOrCreateWeavingConfig(context);
|
||||||
WeavingContext.ExtensionsData newExtensionsData = context.extensionsData().copy();
|
WeavingContext.ExtensionsData newExtensionsData = context.extensionsData().copy();
|
||||||
weavingConfigAccess.set(newExtensionsData, weavingConfig);
|
weavingConfigAccess.set(newExtensionsData, weavingConfig);
|
||||||
|
|
||||||
IntFunction<Collection<Object>> constructor = getCollectionConstructor(valueType);
|
IntFunction<Collection<Object>> constructor = getCollectionConstructor(valueType);
|
||||||
|
|
||||||
//noinspection unchecked,rawtypes
|
//noinspection unchecked,rawtypes
|
||||||
WeavableCoherentCollectionConfigEntry configEntry = WeavableCoherentCollectionConfigEntry.instantiate(
|
WeavableCollectionConfigEntry configEntry = WeavableCollectionConfigEntry.instantiate(
|
||||||
(Class) weavingConfig.coherentCollectionEntryClass(),
|
(Class) weavingConfig.collectionEntryClass(),
|
||||||
(Class) valueType.declaredType(),
|
(Class) valueType.declaredType(),
|
||||||
constructor
|
constructor
|
||||||
);
|
);
|
||||||
@@ -65,31 +66,31 @@ public class CoherentCollectionPojoWeaver implements TweedPojoWeaver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private CoherentCollectionWeavingConfig getOrCreateWeavingConfig(WeavingContext context) {
|
private CollectionWeavingConfig getOrCreateWeavingConfig(WeavingContext context) {
|
||||||
CoherentCollectionWeavingConfig parent;
|
CollectionWeavingConfig parent;
|
||||||
if (context.extensionsData().isPatchworkPartSet(CoherentCollectionWeavingConfig.class)) {
|
if (context.extensionsData().isPatchworkPartSet(CollectionWeavingConfig.class)) {
|
||||||
parent = (CoherentCollectionWeavingConfig) context.extensionsData();
|
parent = (CollectionWeavingConfig) context.extensionsData();
|
||||||
} else {
|
} else {
|
||||||
parent = DEFAULT_WEAVING_CONFIG;
|
parent = DEFAULT_WEAVING_CONFIG;
|
||||||
}
|
}
|
||||||
|
|
||||||
CoherentCollectionWeavingConfig local = createWeavingConfigFromAnnotations(context.annotations());
|
CollectionWeavingConfig local = createWeavingConfigFromAnnotations(context.annotations());
|
||||||
if (local == null) {
|
if (local == null) {
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
return CoherentCollectionWeavingConfigImpl.withOverrides(parent, local);
|
return CollectionWeavingConfigImpl.withOverrides(parent, local);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CoherentCollectionWeavingConfig createWeavingConfigFromAnnotations(@NotNull AnnotatedElement annotations) {
|
private CollectionWeavingConfig createWeavingConfigFromAnnotations(@NotNull AnnotatedElement annotations) {
|
||||||
CoherentCollectionWeaving annotation = annotations.getAnnotation(CoherentCollectionWeaving.class);
|
CollectionWeaving annotation = annotations.getAnnotation(CollectionWeaving.class);
|
||||||
if (annotation == null) {
|
if (annotation == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
CoherentCollectionWeavingConfigImpl.CoherentCollectionWeavingConfigImplBuilder builder = CoherentCollectionWeavingConfigImpl.builder();
|
CollectionWeavingConfigImpl.CollectionWeavingConfigImplBuilder builder = CollectionWeavingConfigImpl.builder();
|
||||||
if (annotation.entryClass() != null) {
|
if (annotation.entryClass() != null) {
|
||||||
builder.coherentCollectionEntryClass(annotation.entryClass());
|
builder.collectionEntryClass(annotation.entryClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.build();
|
return builder.build();
|
||||||
@@ -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.ConfigEntry;
|
||||||
import de.siphalor.tweed5.core.api.entry.ConfigEntryValueVisitor;
|
import de.siphalor.tweed5.core.api.entry.ConfigEntryValueVisitor;
|
||||||
import de.siphalor.tweed5.core.api.entry.ConfigEntryVisitor;
|
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.EqualsAndHashCode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
@@ -16,11 +16,11 @@ import java.util.function.IntFunction;
|
|||||||
@Getter
|
@Getter
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@ToString(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 final IntFunction<T> constructor;
|
||||||
private ConfigEntry<E> elementEntry;
|
private ConfigEntry<E> elementEntry;
|
||||||
|
|
||||||
public CoherentCollectionConfigEntryImpl(@NotNull Class<T> valueClass, IntFunction<T> constructor) {
|
public CollectionConfigEntryImpl(@NotNull Class<T> valueClass, IntFunction<T> constructor) {
|
||||||
super(valueClass);
|
super(valueClass);
|
||||||
this.constructor = constructor;
|
this.constructor = constructor;
|
||||||
}
|
}
|
||||||
@@ -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();
|
|
||||||
}
|
|
||||||
@@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ import de.siphalor.tweed5.core.api.container.ConfigContainer;
|
|||||||
import de.siphalor.tweed5.core.api.extension.TweedExtension;
|
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.CompoundWeaving;
|
||||||
import de.siphalor.tweed5.weaver.pojo.api.annotation.PojoWeaving;
|
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.CompoundPojoWeaver;
|
||||||
import de.siphalor.tweed5.weaver.pojo.api.weaving.TrivialPojoWeaver;
|
import de.siphalor.tweed5.weaver.pojo.api.weaving.TrivialPojoWeaver;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -90,7 +90,7 @@ class TweedPojoWeaverBootstrapperTest {
|
|||||||
boolean somethingElse;
|
boolean somethingElse;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PojoWeaving(weavers = {CompoundPojoWeaver.class, CoherentCollectionPojoWeaver.class, TrivialPojoWeaver.class})
|
@PojoWeaving(weavers = {CompoundPojoWeaver.class, CollectionPojoWeaver.class, TrivialPojoWeaver.class})
|
||||||
@CompoundWeaving(namingFormat = "camel_case")
|
@CompoundWeaving(namingFormat = "camel_case")
|
||||||
@Data
|
@Data
|
||||||
public static class CompoundWithList {
|
public static class CompoundWithList {
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
package de.siphalor.tweed5.weaver.pojo.test;
|
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.CompoundConfigEntry;
|
||||||
import de.siphalor.tweed5.core.api.entry.ConfigEntry;
|
import de.siphalor.tweed5.core.api.entry.ConfigEntry;
|
||||||
import de.siphalor.tweed5.core.api.entry.SimpleConfigEntry;
|
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 java.util.function.Consumer;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
@@ -39,11 +37,11 @@ public class ConfigEntryAssertions {
|
|||||||
|
|
||||||
public static Consumer<Object> isCollectionEntryForClass(
|
public static Consumer<Object> isCollectionEntryForClass(
|
||||||
Class<?> collectionClass,
|
Class<?> collectionClass,
|
||||||
Consumer<CoherentCollectionConfigEntry<?, ?>> condition
|
Consumer<CollectionConfigEntry<?, ?>> condition
|
||||||
) {
|
) {
|
||||||
return object -> assertThat(object)
|
return object -> assertThat(object)
|
||||||
.as("Should be a collection config entry for class " + collectionClass.getName())
|
.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())
|
.as("Collection entry for class " + collectionClass.getSimpleName())
|
||||||
.satisfies(
|
.satisfies(
|
||||||
listEntry -> assertThat(listEntry.valueClass())
|
listEntry -> assertThat(listEntry.valueClass())
|
||||||
|
|||||||
Reference in New Issue
Block a user