From 5dd6c5182de60550e0eddb1bd680c97407a52e05 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Sun, 24 Nov 2024 20:14:01 +0100 Subject: [PATCH] Changes dependency on VintageValueProvider to ValueProvider --- .../vintage/prefabvalues/factories/CopyFactory.java | 13 ++++++------- .../prefabvalues/factories/EnumMapFactory.java | 9 ++++++--- .../prefabvalues/factories/EnumSetFactory.java | 7 ++++--- .../prefabvalues/factories/FallbackFactory.java | 10 ++++++---- .../vintage/prefabvalues/factories/MapFactory.java | 13 ++++++------- .../factories/SimpleGenericFactory.java | 9 ++++----- 6 files changed, 32 insertions(+), 29 deletions(-) diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/CopyFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/CopyFactory.java index 4eeee91b7..5379ec991 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/CopyFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/CopyFactory.java @@ -8,11 +8,11 @@ public class CopyFactory extends AbstractGenericFactory { - private final Class source; + private final Class type; private final Function copy; public CopyFactory(Class source, Function copy) { - this.source = source; + this.type = source; this.copy = copy; } @@ -23,12 +23,11 @@ public Tuple createValues( Attributes attributes ) { Attributes clone = attributes.cloneAndAdd(tag); - TypeTag sourceTag = copyGenericTypesInto(source, tag); + TypeTag sourceTag = copyGenericTypesInto(type, tag); - S redSource = valueProvider.giveRed(sourceTag, clone); - S blueSource = valueProvider.giveBlue(sourceTag, clone); - S redCopySource = valueProvider.giveRedCopy(sourceTag, clone); + Tuple source = valueProvider.provideOrThrow(sourceTag, clone); + Tuple copied = source.map(copy::apply); - return Tuple.of(copy.apply(redSource), copy.apply(blueSource), copy.apply(redCopySource)); + return Tuple.of(copied.getRed(), copied.getBlue(), copied.getRedCopy()); } } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/EnumMapFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/EnumMapFactory.java index accdfa191..5e6ecc8bb 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/EnumMapFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/EnumMapFactory.java @@ -27,12 +27,15 @@ public Tuple createValues( TypeTag keyTag = determineAndCacheActualTypeTag(0, tag, valueProvider, clone, Enum.class); TypeTag valueTag = determineAndCacheActualTypeTag(1, tag, valueProvider, clone, Enum.class); + Tuple key = valueProvider.provideOrThrow(keyTag, clone); + Tuple value = valueProvider.provideOrThrow(valueTag, clone); + Map red = new HashMap<>(); Map blue = new HashMap<>(); Map redCopy = new HashMap<>(); - red.put(valueProvider.giveRed(keyTag, clone), valueProvider.giveBlue(valueTag, clone)); - blue.put(valueProvider.giveBlue(keyTag, clone), valueProvider.giveBlue(valueTag, clone)); - redCopy.put(valueProvider.giveRed(keyTag, clone), valueProvider.giveBlue(valueTag, clone)); + red.put(key.getRed(), value.getBlue()); + blue.put(key.getBlue(), value.getBlue()); + redCopy.put(key.getRedCopy(), value.getBlue()); return Tuple.of(factory.apply(red), factory.apply(blue), factory.apply(redCopy)); } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/EnumSetFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/EnumSetFactory.java index 4aeb75791..c01426fc4 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/EnumSetFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/EnumSetFactory.java @@ -30,12 +30,13 @@ public Tuple createValues( Attributes clone = attributes.cloneAndAdd(tag); TypeTag entryTag = determineAndCacheActualTypeTag(0, tag, valueProvider, clone, Enum.class); + Tuple tuple = valueProvider.provideOrThrow(entryTag, clone); Collection red = new HashSet<>(); Collection blue = new HashSet<>(); Collection redCopy = new HashSet<>(); - red.add(valueProvider.giveRed(entryTag, clone)); - blue.add(valueProvider.giveBlue(entryTag, clone)); - redCopy.add(valueProvider.giveRed(entryTag, clone)); + red.add(tuple.getRed()); + blue.add(tuple.getBlue()); + redCopy.add(tuple.getRedCopy()); return new Tuple<>(factory.apply(red), factory.apply(blue), factory.apply(redCopy)); } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactory.java index a206d1ae2..9a351133d 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactory.java @@ -5,6 +5,7 @@ import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.InstanceCreator; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.ClassAccessor; @@ -60,19 +61,20 @@ private Tuple giveEnumInstances(TypeTag tag) { @SuppressWarnings("unchecked") private Tuple giveArrayInstances( TypeTag tag, - VintageValueProvider valueProvider, + ValueProvider valueProvider, Attributes attributes ) { Class type = tag.getType(); Class componentType = type.getComponentType(); TypeTag componentTag = new TypeTag(componentType); + Tuple component = valueProvider.provideOrThrow(componentTag, attributes); T red = (T) Array.newInstance(componentType, 1); - Array.set(red, 0, valueProvider.giveRed(componentTag, attributes)); + Array.set(red, 0, component.getRed()); T blue = (T) Array.newInstance(componentType, 1); - Array.set(blue, 0, valueProvider.giveBlue(componentTag, attributes)); + Array.set(blue, 0, component.getBlue()); T redCopy = (T) Array.newInstance(componentType, 1); - Array.set(redCopy, 0, valueProvider.giveRed(componentTag, attributes)); + Array.set(redCopy, 0, component.getRed()); return new Tuple<>(red, blue, redCopy); } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactory.java index 38eca6fa6..121460949 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactory.java @@ -34,20 +34,19 @@ public Tuple createValues( // values. // But don't do it in the Blue map, or they may cancel each other out again. - Object redKey = valueProvider.giveRed(keyTag, clone); - Object blueKey = valueProvider.giveBlue(keyTag, clone); - Object blueValue = valueProvider.giveBlue(valueTag, clone); + Tuple key = valueProvider.provideOrThrow(keyTag, clone); + Tuple value = valueProvider.provideOrThrow(valueTag, clone); T red = createEmpty.get(); - red.put(redKey, blueValue); + red.put(key.getRed(), value.getBlue()); T blue = createEmpty.get(); - if (!redKey.equals(blueKey)) { // This happens with single-element enums - blue.put(valueProvider.giveBlue(keyTag, clone), blueValue); + if (!key.getRed().equals(key.getBlue())) { // This happens with single-element enums + blue.put(key.getBlue(), value.getBlue()); } T redCopy = createEmpty.get(); - redCopy.put(redKey, blueValue); + redCopy.put(key.getRed(), value.getBlue()); return new Tuple<>(red, blue, redCopy); } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactory.java index f3ec0ee34..9ed4b1f02 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactory.java @@ -35,13 +35,12 @@ public Tuple createValues( for (int i = 0; i < n; i++) { TypeTag paramTag = determineAndCacheActualTypeTag(i, tag, valueProvider, clone); - Object redValue = valueProvider.giveRed(paramTag, clone); - Object blueValue = valueProvider.giveBlue(paramTag, clone); - if (redValue.equals(blueValue)) { // This happens with single-element enums + Tuple value = valueProvider.provideOrThrow(paramTag, clone); + if (value.getRed().equals(value.getBlue())) { // This happens with single-element enums useEmpty = true; } - redValues.add(redValue); - blueValues.add(blueValue); + redValues.add(value.getRed()); + blueValues.add(value.getBlue()); } Object red = factory.apply(redValues);