From 0b4d6f49373b7abe337a66e1183f7a66d95da7cb Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Wed, 20 Nov 2024 19:34:03 +0100 Subject: [PATCH 01/18] Introduces CachedValueProvider --- .../RecordObjectAccessorScramblingTest.java | 10 ++- .../vintage/RecordObjectAccessorTest.java | 2 + .../instantiation/CachedValueProvider.java | 83 +++++++++++++++++++ .../instantiation/ChainedValueProvider.java | 2 +- .../instantiation/VintageValueProvider.java | 47 ++--------- .../internal/util/DefaultValueProviders.java | 15 ++-- .../VintageValueProviderCreatorTest.java | 12 +-- .../VintageValueProviderTest.java | 11 +-- .../reflection/vintage/ClassAccessorTest.java | 7 +- .../InPlaceObjectAccessorScramblingTest.java | 8 +- .../factories/FallbackFactoryTest.java | 4 +- .../factories/MapFactoryTest.java | 2 + .../factories/SimpleGenericFactoryTest.java | 2 + .../JavaFxFactoryProviderTest.java | 2 + 14 files changed, 146 insertions(+), 61 deletions(-) create mode 100644 equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProvider.java diff --git a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorScramblingTest.java b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorScramblingTest.java index 5f689a58c..898826026 100644 --- a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorScramblingTest.java +++ b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorScramblingTest.java @@ -8,6 +8,7 @@ import java.util.LinkedHashSet; import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; import org.junit.jupiter.api.BeforeEach; @@ -17,14 +18,21 @@ public class RecordObjectAccessorScramblingTest { private static final LinkedHashSet EMPTY_TYPE_STACK = new LinkedHashSet<>(); + private CachedValueProvider cache; private FactoryCache factoryCache; private VintageValueProvider valueProvider; @BeforeEach public void setup() throws Exception { + cache = new CachedValueProvider(); factoryCache = JavaApiPrefabValues.build(); valueProvider = - new VintageValueProvider(TestValueProviders.empty(), factoryCache, new ObjenesisStd()); + new VintageValueProvider( + TestValueProviders.empty(), + cache, + factoryCache, + new ObjenesisStd() + ); } @Test diff --git a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorTest.java b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorTest.java index cc19512d5..b083634f7 100644 --- a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorTest.java +++ b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorTest.java @@ -10,6 +10,7 @@ import nl.jqno.equalsverifier.internal.reflection.Instantiator; import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; @@ -77,6 +78,7 @@ public void fail_whenConstructorThrowsOnSomethingElse() { VintageValueProvider vp = new VintageValueProvider( TestValueProviders.empty(), + new CachedValueProvider(), JavaApiPrefabValues.build(), objenesis ); diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProvider.java new file mode 100644 index 000000000..a7a84a60a --- /dev/null +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProvider.java @@ -0,0 +1,83 @@ +package nl.jqno.equalsverifier.internal.reflection.instantiation; + +import java.util.*; +import nl.jqno.equalsverifier.internal.reflection.Tuple; +import nl.jqno.equalsverifier.internal.reflection.TypeTag; + +/** + * Provider of instances that have been created before, e.g. by other ValueProviders. + */ +public class CachedValueProvider implements ValueProvider { + + private final Map> cache = new HashMap<>(); + + /** + * Adds a value to the cache. + * + * @param tag The type to assign the value to. + * @param label The label that the value should be linked to. + * @param tuple The value to add to the cache. + */ + public void put(TypeTag tag, String label, Tuple tuple) { + cache.put(Key.of(tag, label), tuple); + } + + /** + * Checks if a value is already present in the cache. + * + * @param tag The type for which we want to see if a value is present. + * @param label The label that the value should be linked to. + * @return Whether a value for the given tag and label is present in the cache. + */ + public boolean contains(TypeTag tag, String label) { + Key key = Key.of(tag, label); + return cache.containsKey(key); + } + + /** + * {@inheritDoc}} + */ + @SuppressWarnings("unchecked") + @Override + public Optional> provide(TypeTag tag, String label) { + Key key = Key.of(tag, label); + if (cache.containsKey(key)) { + return Optional.of((Tuple) cache.get(key)); + } + return Optional.empty(); + } + + private static final class Key { + + final TypeTag tag; + final String label; + + private Key(TypeTag tag, String label) { + this.tag = tag; + this.label = label; + } + + public static Key of(TypeTag tag, String label) { + return new Key(tag, label); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Key)) { + return false; + } + Key other = (Key) obj; + return Objects.equals(tag, other.tag) && Objects.equals(label, other.label); + } + + @Override + public int hashCode() { + return Objects.hash(tag, label); + } + + @Override + public String toString() { + return "Key: [" + tag + "/" + label + "]"; + } + } +} diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProvider.java index f2c32e770..919ed12ee 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProvider.java @@ -8,7 +8,7 @@ import nl.jqno.equalsverifier.internal.reflection.TypeTag; /** - * Provider of prefabricated instances of classes, delegating to other ValueProviders in sequence. + * Provider of instances of classes, delegating to other ValueProviders in sequence. */ public class ChainedValueProvider implements ValueProvider { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java index aab525544..0c2b73783 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java @@ -22,9 +22,8 @@ */ public class VintageValueProvider implements ValueProvider { - private final Map> valueCache = new HashMap<>(); - private final ValueProvider valueProvider; + private final CachedValueProvider cache; private final FactoryCache factoryCache; private final PrefabValueFactory fallbackFactory; @@ -32,16 +31,19 @@ public class VintageValueProvider implements ValueProvider { * Constructor. * * @param valueProvider Will be used to look up values before they are created. + * @param cache The values that have already been constructed. * @param factoryCache The factories that can be used to create values. * @param objenesis To instantiate non-record classes. */ @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "A cache is inherently mutable.") public VintageValueProvider( ValueProvider valueProvider, + CachedValueProvider cache, FactoryCache factoryCache, Objenesis objenesis ) { this.valueProvider = valueProvider; + this.cache = cache; this.factoryCache = factoryCache; this.fallbackFactory = new FallbackFactory<>(objenesis); } @@ -165,10 +167,9 @@ public void realizeCacheFor(TypeTag tag, LinkedHashSet typeStack) { * @param typeStack Keeps track of recursion in the type. */ public void realizeCacheFor(TypeTag tag, String label, LinkedHashSet typeStack) { - Key key = Key.of(tag, label); - if (!valueCache.containsKey(key)) { + if (!cache.contains(tag, label)) { Tuple tuple = createTuple(tag, label, typeStack); - valueCache.put(key, tuple); + cache.put(tag, label, tuple); } } @@ -179,7 +180,7 @@ private Tuple giveTuple(TypeTag tag, String label) { @SuppressWarnings("unchecked") private Tuple giveTuple(TypeTag tag, String label, LinkedHashSet typeStack) { realizeCacheFor(tag, label, typeStack); - return (Tuple) valueCache.get(Key.of(tag, label)); + return (Tuple) cache.provide(tag, label).get(); } private Tuple createTuple(TypeTag tag, String label, LinkedHashSet typeStack) { @@ -206,38 +207,4 @@ private Tuple createTuple(TypeTag tag, String label, LinkedHashSet result = (Tuple) fallbackFactory.createValues(tag, this, typeStack); return result; } - - private static final class Key { - - final TypeTag tag; - final String label; - - private Key(TypeTag tag, String label) { - this.tag = tag; - this.label = label; - } - - public static Key of(TypeTag tag, String label) { - return new Key(tag, label); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Key)) { - return false; - } - Key other = (Key) obj; - return Objects.equals(tag, other.tag) && Objects.equals(label, other.label); - } - - @Override - public int hashCode() { - return Objects.hash(tag, label); - } - - @Override - public String toString() { - return "Key: [" + tag + "/" + label + "]"; - } - } } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/DefaultValueProviders.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/DefaultValueProviders.java index 867ccf5ee..f8ff0f0bd 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/DefaultValueProviders.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/DefaultValueProviders.java @@ -1,8 +1,6 @@ package nl.jqno.equalsverifier.internal.util; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ChainedValueProvider; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.*; import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; import org.objenesis.Objenesis; @@ -14,9 +12,16 @@ public static ValueProvider create(FactoryCache factoryCache, Objenesis objenesi ChainedValueProvider mainChain = new ChainedValueProvider(); ChainedValueProvider vintageChain = new ChainedValueProvider(); - ValueProvider vintage = new VintageValueProvider(vintageChain, factoryCache, objenesis); + CachedValueProvider cache = new CachedValueProvider(); + ValueProvider vintage = new VintageValueProvider( + vintageChain, + cache, + factoryCache, + objenesis + ); - mainChain.register(vintage); + mainChain.register(cache, vintage); + vintageChain.register(cache); return mainChain; } diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderCreatorTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderCreatorTest.java index ffcf6a4ef..af92d7e71 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderCreatorTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderCreatorTest.java @@ -31,15 +31,17 @@ public class VintageValueProviderCreatorTest { private static final TypeTag TWOSTEP_NODE_ARRAY_A_TAG = new TypeTag(TwoStepNodeArrayA.class); private Objenesis objenesis; + private CachedValueProvider cache; private FactoryCache factoryCache; private VintageValueProvider valueProvider; @BeforeEach public void setup() { objenesis = new ObjenesisStd(); + cache = new CachedValueProvider(); factoryCache = FactoryCacheFactory.withPrimitiveFactories(); valueProvider = - new VintageValueProvider(TestValueProviders.empty(), factoryCache, objenesis); + new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); } @Test @@ -80,7 +82,7 @@ public void createEmptyEnum() { public void oneStepRecursiveType() { factoryCache.put(Node.class, values(new Node(), new Node(), new Node())); valueProvider = - new VintageValueProvider(TestValueProviders.empty(), factoryCache, objenesis); + new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); valueProvider.giveRed(NODE_TAG); } @@ -98,7 +100,7 @@ public void oneStepRecursiveArrayType() { values(new NodeArray(), new NodeArray(), new NodeArray()) ); valueProvider = - new VintageValueProvider(TestValueProviders.empty(), factoryCache, objenesis); + new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); valueProvider.giveRed(NODE_ARRAY_TAG); } @@ -116,7 +118,7 @@ public void addTwoStepRecursiveType() { values(new TwoStepNodeB(), new TwoStepNodeB(), new TwoStepNodeB()) ); valueProvider = - new VintageValueProvider(TestValueProviders.empty(), factoryCache, objenesis); + new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); valueProvider.giveRed(TWOSTEP_NODE_A_TAG); } @@ -134,7 +136,7 @@ public void twoStepRecursiveArrayType() { values(new TwoStepNodeArrayB(), new TwoStepNodeArrayB(), new TwoStepNodeArrayB()) ); valueProvider = - new VintageValueProvider(TestValueProviders.empty(), factoryCache, objenesis); + new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); valueProvider.giveRed(TWOSTEP_NODE_ARRAY_A_TAG); } diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderTest.java index 54db33c3d..092b1beee 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderTest.java @@ -29,6 +29,7 @@ public class VintageValueProviderTest { private static final TypeTag INT_TAG = new TypeTag(int.class); private Objenesis objenesis = new ObjenesisStd(); + private CachedValueProvider cache = new CachedValueProvider(); private FactoryCache factoryCache = new FactoryCache(); private VintageValueProvider vp; @@ -36,7 +37,7 @@ public class VintageValueProviderTest { public void setUp() { factoryCache.put(String.class, new AppendingStringTestFactory()); factoryCache.put(int.class, values(42, 1337, 42)); - vp = new VintageValueProvider(TestValueProviders.empty(), factoryCache, objenesis); + vp = new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); } @Test @@ -117,7 +118,7 @@ public void fallbackDoesNotAffectStaticFields() { @Test public void stringListIsSeparateFromIntegerList() { factoryCache.put(List.class, new ListTestFactory()); - vp = new VintageValueProvider(TestValueProviders.empty(), factoryCache, objenesis); + vp = new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); List strings = vp.giveRed(new TypeTag(List.class, STRING_TAG)); List ints = vp.giveRed(new TypeTag(List.class, INT_TAG)); @@ -134,7 +135,7 @@ public void addingNullDoesntBreakAnything() { @Test public void addingATypeTwiceOverrulesTheExistingOne() { factoryCache.put(int.class, values(-1, -2, -1)); - vp = new VintageValueProvider(TestValueProviders.empty(), factoryCache, objenesis); + vp = new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); assertEquals(-1, (int) vp.giveRed(INT_TAG)); assertEquals(-2, (int) vp.giveBlue(INT_TAG)); } @@ -143,7 +144,7 @@ public void addingATypeTwiceOverrulesTheExistingOne() { public void addLazyFactoryWorks() { TypeTag lazyTag = new TypeTag(Lazy.class); factoryCache.put(Lazy.class.getName(), values(Lazy.X, Lazy.Y, Lazy.X)); - vp = new VintageValueProvider(TestValueProviders.empty(), factoryCache, objenesis); + vp = new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); assertEquals(Lazy.X, vp.giveRed(lazyTag)); assertEquals(Lazy.Y, vp.giveBlue(lazyTag)); assertEquals(Lazy.X, vp.giveRedCopy(lazyTag)); @@ -159,7 +160,7 @@ public void addLazyFactoryIsLazy() { (t, p, ts) -> Tuple.of(ThrowingInitializer.X, ThrowingInitializer.Y, ThrowingInitializer.X) ); - vp = new VintageValueProvider(TestValueProviders.empty(), factoryCache, objenesis); + vp = new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); // Should throw, because `giveRed` does instantiate objects: try { diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessorTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessorTest.java index ed6f1155f..13e56d293 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessorTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessorTest.java @@ -8,6 +8,7 @@ import java.util.LinkedHashSet; import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; import nl.jqno.equalsverifier.testhelpers.types.PointContainer; @@ -23,6 +24,7 @@ public class ClassAccessorTest { private LinkedHashSet empty; private Objenesis objenesis; + private CachedValueProvider cache; private FactoryCache factoryCache; private VintageValueProvider valueProvider; private ClassAccessor pointContainerAccessor; @@ -31,9 +33,10 @@ public class ClassAccessorTest { public void setup() { empty = new LinkedHashSet<>(); objenesis = new ObjenesisStd(); + cache = new CachedValueProvider(); factoryCache = JavaApiPrefabValues.build(); valueProvider = - new VintageValueProvider(TestValueProviders.empty(), factoryCache, objenesis); + new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); pointContainerAccessor = ClassAccessor.of(PointContainer.class, valueProvider, objenesis); } @@ -125,7 +128,7 @@ public void instantiateRecursiveTypeUsingPrefabValue() { values(new TwoStepNodeB(), new TwoStepNodeB(), new TwoStepNodeB()) ); valueProvider = - new VintageValueProvider(TestValueProviders.empty(), factoryCache, objenesis); + new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); ClassAccessor .of(TwoStepNodeA.class, valueProvider, objenesis) .getRedObject(TypeTag.NULL, empty); diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorScramblingTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorScramblingTest.java index 638c4d55c..e59ab0728 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorScramblingTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorScramblingTest.java @@ -10,6 +10,7 @@ import nl.jqno.equalsverifier.internal.exceptions.ModuleException; import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; @@ -35,7 +36,12 @@ public void setup() { factoryCache.put(Point.class, values(new Point(1, 2), new Point(2, 3), new Point(1, 2))); objenesis = new ObjenesisStd(); valueProviderTest = - new VintageValueProvider(TestValueProviders.empty(), factoryCache, objenesis); + new VintageValueProvider( + TestValueProviders.empty(), + new CachedValueProvider(), + factoryCache, + objenesis + ); } @Test diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java index 3725424f8..606e7fbbd 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java @@ -10,6 +10,7 @@ import nl.jqno.equalsverifier.internal.exceptions.RecursionException; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; @@ -35,10 +36,11 @@ public class FallbackFactoryTest { public void setUp() { Objenesis objenesis = new ObjenesisStd(); factory = new FallbackFactory<>(objenesis); + CachedValueProvider cache = new CachedValueProvider(); FactoryCache factoryCache = new FactoryCache(); factoryCache.put(int.class, values(42, 1337, 42)); valueProvider = - new VintageValueProvider(TestValueProviders.empty(), factoryCache, objenesis); + new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); typeStack = new LinkedHashSet<>(); } diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactoryTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactoryTest.java index e08d755fc..eea125d5e 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactoryTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactoryTest.java @@ -8,6 +8,7 @@ import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; import nl.jqno.equalsverifier.testhelpers.types.TypeHelper.OneElementEnum; @@ -53,6 +54,7 @@ public void setUp() { valueProvider = new VintageValueProvider( TestValueProviders.empty(), + new CachedValueProvider(), JavaApiPrefabValues.build(), new ObjenesisStd() ); diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactoryTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactoryTest.java index c54b0b816..cfa9a3137 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactoryTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactoryTest.java @@ -7,6 +7,7 @@ import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; import nl.jqno.equalsverifier.testhelpers.types.Pair; @@ -55,6 +56,7 @@ public void setUp() { valueProvider = new VintageValueProvider( TestValueProviders.empty(), + new CachedValueProvider(), JavaApiPrefabValues.build(), new ObjenesisStd() ); diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProviderTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProviderTest.java index adf0e4948..fe4f51d00 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProviderTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProviderTest.java @@ -8,6 +8,7 @@ import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factoryproviders.JavaFxFactoryProvider.PropertyFactory; @@ -27,6 +28,7 @@ public void setUp() { valueProvider = new VintageValueProvider( TestValueProviders.empty(), + new CachedValueProvider(), JavaApiPrefabValues.build(), new ObjenesisStd() ); From 64cdebee87f062c3ee7e5a80ed528e8c43007bec Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Thu, 21 Nov 2024 15:58:47 +0100 Subject: [PATCH 02/18] Allows ChainedValueProvider to update the cache --- .../instantiation/ChainedValueProvider.java | 13 ++++++++++++- .../internal/util/DefaultValueProviders.java | 7 ++++--- .../instantiation/ChainedValueProviderTest.java | 11 ++++++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProvider.java index 919ed12ee..0cb14a26d 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProvider.java @@ -1,5 +1,6 @@ package nl.jqno.equalsverifier.internal.reflection.instantiation; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -14,6 +15,13 @@ public class ChainedValueProvider implements ValueProvider { private boolean locked = false; private final List providers = new ArrayList<>(); + private final CachedValueProvider cache; + + @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "A cache is inherently mutable") + public ChainedValueProvider(CachedValueProvider cache) { + this.cache = cache; + providers.add(cache); + } /** * Adds providers to the chain, so they can be delegated to when providing a value. @@ -35,11 +43,14 @@ public void register(ValueProvider... valueProviders) { /** {@inheritDoc} */ @Override public Optional> provide(TypeTag tag, String label) { - return providers + Optional> result = providers .stream() .map(vp -> vp.provide(tag, label)) .filter(Optional::isPresent) .findFirst() .orElse(Optional.empty()); + + result.ifPresent(r -> cache.put(tag, label, r)); + return result; } } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/DefaultValueProviders.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/DefaultValueProviders.java index f8ff0f0bd..7c85be7fe 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/DefaultValueProviders.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/DefaultValueProviders.java @@ -9,10 +9,11 @@ public final class DefaultValueProviders { private DefaultValueProviders() {} public static ValueProvider create(FactoryCache factoryCache, Objenesis objenesis) { - ChainedValueProvider mainChain = new ChainedValueProvider(); - ChainedValueProvider vintageChain = new ChainedValueProvider(); - CachedValueProvider cache = new CachedValueProvider(); + + ChainedValueProvider mainChain = new ChainedValueProvider(cache); + ChainedValueProvider vintageChain = new ChainedValueProvider(cache); + ValueProvider vintage = new VintageValueProvider( vintageChain, cache, diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProviderTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProviderTest.java index f416cea54..c4c092904 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProviderTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProviderTest.java @@ -27,7 +27,8 @@ public class ChainedValueProviderTest { "a" ); - private final ChainedValueProvider sut = new ChainedValueProvider(); + private final CachedValueProvider cache = new CachedValueProvider(); + private final ChainedValueProvider sut = new ChainedValueProvider(cache); @Test public void returnsValueIfMatch() { @@ -72,6 +73,14 @@ public void returnsValueFromFirstMatch() { assertEquals(0, anotherIntProvider.called); } + @Test + public void updatesTheCache() { + sut.register(intProvider); + sut.provideOrThrow(INT, null); + + assertEquals(1, cache.provideOrThrow(INT, null).getRed()); + } + @Test public void makesDefensiveCopy() { ValueProvider[] providers = { stringProvider }; From b362d72c95a88fc1b297c76d4740cca91a4704d8 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Fri, 22 Nov 2024 10:29:07 +0100 Subject: [PATCH 03/18] Introduces Attributes for ValueProviders --- .../RecordObjectAccessorScramblingTest.java | 6 +- .../vintage/RecordObjectAccessorTest.java | 6 +- .../checkers/AbstractDelegationChecker.java | 3 +- .../MapEntryHashCodeRequirementChecker.java | 3 +- .../fieldchecks/JpaLazyGetterFieldCheck.java | 3 +- .../fieldchecks/ReflexivityFieldCheck.java | 3 +- .../fieldchecks/StringFieldCheck.java | 3 +- .../instantiation/CachedValueProvider.java | 4 +- .../instantiation/ChainedValueProvider.java | 6 +- .../instantiation/SubjectCreator.java | 6 +- .../instantiation/ValueProvider.java | 67 +++++++++++++++++-- .../instantiation/VintageValueProvider.java | 67 ++++++++----------- .../reflection/vintage/ClassAccessor.java | 44 ++++++------ .../reflection/vintage/FieldModifier.java | 8 +-- .../vintage/InPlaceObjectAccessor.java | 6 +- .../reflection/vintage/ObjectAccessor.java | 6 +- .../vintage/RecordObjectAccessor.java | 6 +- .../factories/AbstractGenericFactory.java | 17 ++--- .../prefabvalues/factories/CopyFactory.java | 6 +- .../factories/EnumMapFactory.java | 6 +- .../factories/EnumSetFactory.java | 6 +- .../factories/ExternalFactory.java | 6 +- .../factories/FallbackFactory.java | 29 ++++---- .../prefabvalues/factories/MapFactory.java | 6 +- .../factories/PrefabValueFactory.java | 11 +-- .../prefabvalues/factories/SimpleFactory.java | 4 +- .../factories/SimpleGenericFactory.java | 6 +- .../GuavaFactoryProvider.java | 9 +-- .../JavaFxFactoryProvider.java | 3 +- .../testhelpers/TestValueProviders.java | 4 +- .../ChainedValueProviderTest.java | 22 +++--- .../instantiation/SubjectCreatorTest.java | 4 +- .../VintageValueProviderTest.java | 8 +-- .../reflection/vintage/ClassAccessorTest.java | 6 +- .../InPlaceObjectAccessorScramblingTest.java | 6 +- .../factories/AbstractGenericFactoryTest.java | 4 +- .../factories/FallbackFactoryTest.java | 17 ++--- .../factories/MapFactoryTest.java | 12 ++-- .../factories/SimpleGenericFactoryTest.java | 12 ++-- 39 files changed, 241 insertions(+), 210 deletions(-) diff --git a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorScramblingTest.java b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorScramblingTest.java index 898826026..a39f867db 100644 --- a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorScramblingTest.java +++ b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorScramblingTest.java @@ -5,10 +5,10 @@ import static org.junit.jupiter.api.Assertions.assertNotSame; import java.lang.reflect.Constructor; -import java.util.LinkedHashSet; import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; import org.junit.jupiter.api.BeforeEach; @@ -17,7 +17,7 @@ public class RecordObjectAccessorScramblingTest { - private static final LinkedHashSet EMPTY_TYPE_STACK = new LinkedHashSet<>(); + private static final Attributes EMPTY_ATTRIBUTES = Attributes.unlabeled(); private CachedValueProvider cache; private FactoryCache factoryCache; private VintageValueProvider valueProvider; @@ -66,7 +66,7 @@ private RecordObjectAccessor create(T object) { } private ObjectAccessor doScramble(Object object) { - return create(object).scramble(valueProvider, TypeTag.NULL, EMPTY_TYPE_STACK); + return create(object).scramble(valueProvider, TypeTag.NULL, EMPTY_ATTRIBUTES); } record Point(int x, int y) {} diff --git a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorTest.java b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorTest.java index b083634f7..8975d574f 100644 --- a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorTest.java +++ b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorTest.java @@ -4,13 +4,13 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.lang.reflect.Constructor; -import java.util.LinkedHashSet; import java.util.Objects; import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; import nl.jqno.equalsverifier.internal.reflection.Instantiator; import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; @@ -21,7 +21,7 @@ public class RecordObjectAccessorTest { - private static final LinkedHashSet EMPTY_TYPE_STACK = new LinkedHashSet<>(); + private static final Attributes EMPTY_ATTRIBUTES = Attributes.unlabeled(); private Objenesis objenesis; private Object recordInstance; @@ -83,7 +83,7 @@ public void fail_whenConstructorThrowsOnSomethingElse() { objenesis ); ExpectedException - .when(() -> accessorFor(instance).scramble(vp, TypeTag.NULL, EMPTY_TYPE_STACK)) + .when(() -> accessorFor(instance).scramble(vp, TypeTag.NULL, EMPTY_ATTRIBUTES)) .assertThrows(ReflectionException.class) .assertMessageContains("Record:", "failed to run constructor", "prefab values"); } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java index 9cd851599..4ae690cc6 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java @@ -10,6 +10,7 @@ import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.util.*; public class AbstractDelegationChecker implements Checker { @@ -74,7 +75,7 @@ private void checkAbstractDelegationInFields() { private Tuple safelyGetTuple(TypeTag tag, String fieldName) { try { - return valueProvider.provideOrThrow(tag, fieldName); + return valueProvider.provideOrThrow(tag, Attributes.labeled(fieldName)); } catch (Exception ignored) { // If it fails for some reason, any reason, just return null so we can skip the test. return null; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/MapEntryHashCodeRequirementChecker.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/MapEntryHashCodeRequirementChecker.java index 7438783b4..f9abe6f8c 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/MapEntryHashCodeRequirementChecker.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/MapEntryHashCodeRequirementChecker.java @@ -5,6 +5,7 @@ import java.util.Map; import java.util.Objects; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.util.Configuration; import nl.jqno.equalsverifier.internal.util.Context; import nl.jqno.equalsverifier.internal.util.Formatter; @@ -23,7 +24,7 @@ public MapEntryHashCodeRequirementChecker(Context context) { public void check() { if (Map.Entry.class.isAssignableFrom(config.getType())) { Map.Entry e = valueProvider - .>provideOrThrow(config.getTypeTag(), null) + .>provideOrThrow(config.getTypeTag(), Attributes.unlabeled()) .getRed(); int expectedHashCode = Objects.hashCode(e.getKey()) ^ Objects.hashCode(e.getValue()); diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/JpaLazyGetterFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/JpaLazyGetterFieldCheck.java index c2119280c..0ef963e88 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/JpaLazyGetterFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/JpaLazyGetterFieldCheck.java @@ -14,6 +14,7 @@ import nl.jqno.equalsverifier.internal.reflection.annotations.SupportedAnnotations; import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.util.Configuration; import nl.jqno.equalsverifier.internal.util.Context; import nl.jqno.equalsverifier.internal.util.Formatter; @@ -64,7 +65,7 @@ public void execute(FieldProbe fieldProbe) { ); TypeTag sub = new TypeTag(throwingGetterCreator(getterName)); - Tuple tuple = valueProvider.provideOrThrow(sub, fieldName); + Tuple tuple = valueProvider.provideOrThrow(sub, Attributes.labeled(fieldName)); T red1 = tuple.getRed(); T red2 = tuple.getRedCopy(); diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ReflexivityFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ReflexivityFieldCheck.java index fd2d98f06..e3d3b25b1 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ReflexivityFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ReflexivityFieldCheck.java @@ -13,6 +13,7 @@ import nl.jqno.equalsverifier.internal.reflection.annotations.SupportedAnnotations; import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.util.Configuration; import nl.jqno.equalsverifier.internal.util.Context; import nl.jqno.equalsverifier.internal.util.Formatter; @@ -80,7 +81,7 @@ private void checkValueReflexivity(FieldProbe probe) { String fieldName = field.getName(); TypeTag tag = TypeTag.of(field, typeTag); Tuple tuple = valueProvider - .provide(tag, fieldName) + .provide(tag, Attributes.labeled(fieldName)) .orElseThrow(() -> new NoValueException(tag, fieldName)); Object left = subjectCreator.withFieldSetTo(field, tuple.getRed()); diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/StringFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/StringFieldCheck.java index 6c67acc42..a90be9261 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/StringFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/StringFieldCheck.java @@ -8,6 +8,7 @@ import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.util.CachedHashCodeInitializer; import nl.jqno.equalsverifier.internal.util.Formatter; @@ -42,7 +43,7 @@ public void execute(FieldProbe fieldProbe) { if (String.class.equals(fieldProbe.getType()) && !fieldProbe.isStatic()) { TypeTag string = new TypeTag(String.class); String red = valueProvider - .provideOrThrow(string, fieldProbe.getName()) + .provideOrThrow(string, Attributes.labeled(fieldProbe.getName())) .getRed(); final T reference; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProvider.java index a7a84a60a..6aba203fb 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProvider.java @@ -39,8 +39,8 @@ public boolean contains(TypeTag tag, String label) { */ @SuppressWarnings("unchecked") @Override - public Optional> provide(TypeTag tag, String label) { - Key key = Key.of(tag, label); + public Optional> provide(TypeTag tag, Attributes attributes) { + Key key = Key.of(tag, attributes.label); if (cache.containsKey(key)) { return Optional.of((Tuple) cache.get(key)); } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProvider.java index 0cb14a26d..599444795 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProvider.java @@ -42,15 +42,15 @@ public void register(ValueProvider... valueProviders) { /** {@inheritDoc} */ @Override - public Optional> provide(TypeTag tag, String label) { + public Optional> provide(TypeTag tag, Attributes attributes) { Optional> result = providers .stream() - .map(vp -> vp.provide(tag, label)) + .map(vp -> vp.provide(tag, attributes)) .filter(Optional::isPresent) .findFirst() .orElse(Optional.empty()); - result.ifPresent(r -> cache.put(tag, label, r)); + result.ifPresent(r -> cache.put(tag, attributes.label, r)); return result; } } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreator.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreator.java index 0e4a8f70a..56fd956fb 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreator.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreator.java @@ -6,6 +6,7 @@ import java.util.Map; import nl.jqno.equalsverifier.internal.exceptions.ModuleException; import nl.jqno.equalsverifier.internal.reflection.*; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.util.Configuration; import nl.jqno.equalsverifier.internal.util.Rethrow; import org.objenesis.Objenesis; @@ -237,7 +238,10 @@ private FieldIterable nonSuperFields() { private Tuple valuesFor(Field f) { try { TypeTag fieldTag = TypeTag.of(f, typeTag); - Tuple tuple = valueProvider.provideOrThrow(fieldTag, f.getName()); + Tuple tuple = valueProvider.provideOrThrow( + fieldTag, + Attributes.labeled(f.getName()) + ); return tuple; } catch (ModuleException e) { throw new ModuleException( diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ValueProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ValueProvider.java index cc37b9873..366f6963a 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ValueProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ValueProvider.java @@ -1,5 +1,6 @@ package nl.jqno.equalsverifier.internal.reflection.instantiation; +import java.util.LinkedHashSet; import java.util.Optional; import nl.jqno.equalsverifier.internal.exceptions.NoValueException; import nl.jqno.equalsverifier.internal.reflection.Tuple; @@ -21,12 +22,11 @@ public interface ValueProvider { * * @param The returned tuple will have this generic type. * @param tag A description of the desired type, including generic parameters. - * @param label Returns only the value assigned to the given label, or if label is null, - * returns the value that's not assigned to any label. + * @param attributes Provides metadata needed to provide a value. * @return A tuple of two different values of the given type, or an empty Optional if none * could be found. */ - Optional> provide(TypeTag tag, String label); + Optional> provide(TypeTag tag, Attributes attributes); /** * Returns a tuple of prefabricated values of the specified type, or, if none exists, throws a @@ -34,13 +34,66 @@ public interface ValueProvider { * * @param The returned tuple will have this generic type. * @param tag A description of the desired type, including generic parameters. - * @param label Returns only the value assigned to the given label, or if label is null, - * returns the value that's not assigned to any label. + * @param attributes Provides metadata needed to provide a value. * @return A tuple of two different values of the given type, or an empty Optional if none * could be found. * @throws NoValueException if no value could be found for the given tag. */ - default Tuple provideOrThrow(TypeTag tag, String label) { - return this.provide(tag, label).orElseThrow(() -> new NoValueException(tag)); + default Tuple provideOrThrow(TypeTag tag, Attributes attributes) { + return this.provide(tag, attributes).orElseThrow(() -> new NoValueException(tag)); + } + + /** + * Container for metadata needed to provide values. + */ + public static final class Attributes { + + /** + * Values can be assigned to a label; if one is specified, ValueProvider returns the value + * assigned to it (or falls back to the value assigned to a null label). If label is null, + * it immediately returns the value assigned to the null label. + */ + public final String label; + /** + * Keeps track of recursion. + */ + public final LinkedHashSet typeStack; + + /** Private constructor. Use the factories instead. */ + private Attributes(String label, LinkedHashSet typeStack) { + this.label = label; + this.typeStack = typeStack; + } + + /** + * Don't use a label when providing a value. + * + * @return An Attributes object with no label. + */ + public static Attributes unlabeled() { + return new Attributes(null, new LinkedHashSet<>()); + } + + /** + * Use a label when providing a value. + * + * @param label The label to use. + * @return An Attributes object with the given label. + */ + public static Attributes labeled(String label) { + return new Attributes(label, new LinkedHashSet<>()); + } + + /** + * Clones the internal typeStack and adds a type to it. + * + * @param tag A type to add to the recursion checker. + * @return A new Attributes object with a type added to its typeStack. + */ + public Attributes cloneAndAdd(TypeTag tag) { + LinkedHashSet clone = new LinkedHashSet<>(typeStack); + clone.add(tag); + return new Attributes(label, clone); + } } } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java index 0c2b73783..2c1294903 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java @@ -50,8 +50,8 @@ public VintageValueProvider( /** {@inheritDoc} */ @Override - public Optional> provide(TypeTag tag, String label) { - return Rethrow.rethrow(() -> Optional.of(giveTuple(tag, label))); + public Optional> provide(TypeTag tag, Attributes attributes) { + return Rethrow.rethrow(() -> Optional.of(giveTuple(tag, attributes))); } /** @@ -64,7 +64,7 @@ public Optional> provide(TypeTag tag, String label) { * @return The "red" prefabricated value. */ public T giveRed(TypeTag tag) { - return this.giveTuple(tag, null).getRed(); + return this.giveTuple(tag).getRed(); } /** @@ -77,7 +77,7 @@ public T giveRed(TypeTag tag) { * @return The "blue" prefabricated value. */ public T giveBlue(TypeTag tag) { - return this.giveTuple(tag, null).getBlue(); + return this.giveTuple(tag).getBlue(); } /** @@ -90,7 +90,7 @@ public T giveBlue(TypeTag tag) { * @return A shallow copy of the "red" prefabricated value. */ public T giveRedCopy(TypeTag tag) { - return this.giveTuple(tag, null).getRedCopy(); + return this.giveTuple(tag).getRedCopy(); } /** @@ -100,11 +100,11 @@ public T giveRedCopy(TypeTag tag) { * @param The type of the value. * @param tag A description of the desired type, including generic parameters. * @param value A value that is different from the value that will be returned. - * @param typeStack Keeps track of recursion in the type. + * @param attributes Provides metadata needed to provide a value and to keep track of recursion. * @return A value that is different from {@code value}. */ // CHECKSTYLE OFF: CyclomaticComplexity - public T giveOther(TypeTag tag, T value, LinkedHashSet typeStack) { + public T giveOther(TypeTag tag, T value, Attributes attributes) { Class type = tag.getType(); if ( value != null && @@ -114,7 +114,7 @@ public T giveOther(TypeTag tag, T value, LinkedHashSet typeStack) { throw new ReflectionException("TypeTag does not match value."); } - Tuple tuple = giveTuple(tag, null, typeStack); + Tuple tuple = giveTuple(tag, attributes); if (tuple.getRed() == null) { return null; } @@ -151,60 +151,47 @@ private boolean arraysAreDeeplyEqual(Object x, Object y) { * * @param The desired type. * @param tag A description of the desired type, including generic parameters. - * @param typeStack Keeps track of recursion in the type. + * @param attributes Keeps track of recursion in the type. */ - public void realizeCacheFor(TypeTag tag, LinkedHashSet typeStack) { - realizeCacheFor(tag, null, typeStack); - } - - /** - * Makes sure that values for the specified type are present in the cache, but doesn't return - * them. - * - * @param The desired type. - * @param tag A description of the desired type, including generic parameters. - * @param label Adds the value assigned to the given label, if a label is given. - * @param typeStack Keeps track of recursion in the type. - */ - public void realizeCacheFor(TypeTag tag, String label, LinkedHashSet typeStack) { - if (!cache.contains(tag, label)) { - Tuple tuple = createTuple(tag, label, typeStack); - cache.put(tag, label, tuple); + public void realizeCacheFor(TypeTag tag, Attributes attributes) { + if (!cache.contains(tag, attributes.label)) { + Tuple tuple = createTuple(tag, attributes); + cache.put(tag, attributes.label, tuple); } } - private Tuple giveTuple(TypeTag tag, String label) { - return giveTuple(tag, label, new LinkedHashSet<>()); + private Tuple giveTuple(TypeTag tag) { + return giveTuple(tag, Attributes.unlabeled()); } @SuppressWarnings("unchecked") - private Tuple giveTuple(TypeTag tag, String label, LinkedHashSet typeStack) { - realizeCacheFor(tag, label, typeStack); - return (Tuple) cache.provide(tag, label).get(); + private Tuple giveTuple(TypeTag tag, Attributes attributes) { + realizeCacheFor(tag, attributes); + return (Tuple) cache.provide(tag, attributes).get(); } - private Tuple createTuple(TypeTag tag, String label, LinkedHashSet typeStack) { - if (typeStack.contains(tag)) { - throw new RecursionException(typeStack); + private Tuple createTuple(TypeTag tag, Attributes attributes) { + if (attributes.typeStack.contains(tag)) { + throw new RecursionException(attributes.typeStack); } - Optional> provided = valueProvider.provide(tag, null); + Optional> provided = valueProvider.provide(tag, attributes); if (provided.isPresent()) { return provided.get(); } Class type = tag.getType(); - if (label != null && factoryCache.contains(type, label)) { - PrefabValueFactory factory = factoryCache.get(type, label); - return factory.createValues(tag, this, typeStack); + if (attributes.label != null && factoryCache.contains(type, attributes.label)) { + PrefabValueFactory factory = factoryCache.get(type, attributes.label); + return factory.createValues(tag, this, attributes); } if (factoryCache.contains(type)) { PrefabValueFactory factory = factoryCache.get(type); - return factory.createValues(tag, this, typeStack); + return factory.createValues(tag, this, attributes); } @SuppressWarnings("unchecked") - Tuple result = (Tuple) fallbackFactory.createValues(tag, this, typeStack); + Tuple result = (Tuple) fallbackFactory.createValues(tag, this, attributes); return result; } } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessor.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessor.java index e19fde95d..45a49d695 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessor.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessor.java @@ -1,8 +1,8 @@ package nl.jqno.equalsverifier.internal.reflection.vintage; -import java.util.LinkedHashSet; import nl.jqno.equalsverifier.internal.reflection.Instantiator; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import org.objenesis.Objenesis; @@ -45,60 +45,54 @@ public static ClassAccessor of( /** * Returns an instance of T that is not equal to the instance of T returned by {@link - * #getBlueObject(TypeTag, LinkedHashSet)}. + * #getBlueObject(TypeTag, Attributes)}. * * @param enclosingType Describes the type that contains this object as a field, to determine * any generic parameters it may contain. - * @param typeStack Keeps track of recursion in the type. + * @param attributes Provides metadata needed to provide a value and to keep track of recursion. * @return An instance of T. */ - public T getRedObject(TypeTag enclosingType, LinkedHashSet typeStack) { - return getRedAccessor(enclosingType, typeStack).get(); + public T getRedObject(TypeTag enclosingType, Attributes attributes) { + return getRedAccessor(enclosingType, attributes).get(); } /** - * Returns an {@link ObjectAccessor} for {@link #getRedObject(TypeTag, LinkedHashSet)}. + * Returns an {@link ObjectAccessor} for {@link #getRedObject(TypeTag, Attributes)}. * * @param enclosingType Describes the type that contains this object as a field, to determine * any generic parameters it may contain. - * @param typeStack Keeps track of recursion in the type. + * @param attributes Provides metadata needed to provide a value and to keep track of recursion. * @return An {@link ObjectAccessor} for {@link #getRedObject}. */ - public ObjectAccessor getRedAccessor( - TypeTag enclosingType, - LinkedHashSet typeStack - ) { - return buildObjectAccessor().scramble(valueProvider, enclosingType, typeStack); + public ObjectAccessor getRedAccessor(TypeTag enclosingType, Attributes attributes) { + return buildObjectAccessor().scramble(valueProvider, enclosingType, attributes); } /** * Returns an instance of T that is not equal to the instance of T returned by {@link - * #getRedObject(TypeTag, LinkedHashSet)}. + * #getRedObject(TypeTag, Attributes)}. * * @param enclosingType Describes the type that contains this object as a field, to determine * any generic parameters it may contain. - * @param typeStack Keeps track of recursion in the type. + * @param attributes Provides metadata needed to provide a value and to keep track of recursion. * @return An instance of T. */ - public T getBlueObject(TypeTag enclosingType, LinkedHashSet typeStack) { - return getBlueAccessor(enclosingType, typeStack).get(); + public T getBlueObject(TypeTag enclosingType, Attributes attributes) { + return getBlueAccessor(enclosingType, attributes).get(); } /** - * Returns an {@link ObjectAccessor} for {@link #getBlueObject(TypeTag, LinkedHashSet)}. + * Returns an {@link ObjectAccessor} for {@link #getBlueObject(TypeTag, Attributes)}. * * @param enclosingType Describes the type that contains this object as a field, to determine * any generic parameters it may contain. - * @param typeStack Keeps track of recursion in the type. - * @return An {@link ObjectAccessor} for {@link #getBlueObject(TypeTag, LinkedHashSet)}. + * @param attributes Provides metadata needed to provide a value and to keep track of recursion. + * @return An {@link ObjectAccessor} for {@link #getBlueObject(TypeTag, Attributes)}. */ - public ObjectAccessor getBlueAccessor( - TypeTag enclosingType, - LinkedHashSet typeStack - ) { + public ObjectAccessor getBlueAccessor(TypeTag enclosingType, Attributes attributes) { return buildObjectAccessor() - .scramble(valueProvider, enclosingType, typeStack) - .scramble(valueProvider, enclosingType, typeStack); + .scramble(valueProvider, enclosingType, attributes) + .scramble(valueProvider, enclosingType, attributes); } private ObjectAccessor buildObjectAccessor() { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/FieldModifier.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/FieldModifier.java index 0b91e5f87..995e9bbbf 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/FieldModifier.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/FieldModifier.java @@ -3,10 +3,10 @@ import static nl.jqno.equalsverifier.internal.util.Rethrow.rethrow; import java.lang.reflect.Field; -import java.util.LinkedHashSet; import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; public final class FieldModifier { @@ -53,17 +53,17 @@ public void copyTo(Object to) { * will be taken from it. * @param enclosingType A tag for the type that contains the field. Needed to determine a * generic type, if it has one.. - * @param typeStack Keeps track of recursion in the type. + * @param attributes Provides metadata needed to provide a value and to keep track of recursion. * @throws ReflectionException If the operation fails. */ public void changeField( VintageValueProvider valueProvider, TypeTag enclosingType, - LinkedHashSet typeStack + Attributes attributes ) { FieldChanger fm = () -> { TypeTag tag = TypeTag.of(field, enclosingType); - Object newValue = valueProvider.giveOther(tag, field.get(object), typeStack); + Object newValue = valueProvider.giveOther(tag, field.get(object), attributes); field.set(object, newValue); }; change(fm, false); diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessor.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessor.java index c9cf1c573..f48130627 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessor.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessor.java @@ -1,10 +1,10 @@ package nl.jqno.equalsverifier.internal.reflection.vintage; import java.lang.reflect.Field; -import java.util.LinkedHashSet; import nl.jqno.equalsverifier.internal.reflection.FieldIterable; import nl.jqno.equalsverifier.internal.reflection.Instantiator; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import org.objenesis.Objenesis; @@ -35,10 +35,10 @@ public T copy(Objenesis objenesis) { public ObjectAccessor scramble( VintageValueProvider valueProvider, TypeTag enclosingType, - LinkedHashSet typeStack + Attributes attributes ) { for (Field field : FieldIterable.of(type())) { - fieldModifierFor(field).changeField(valueProvider, enclosingType, typeStack); + fieldModifierFor(field).changeField(valueProvider, enclosingType, attributes); } return this; } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ObjectAccessor.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ObjectAccessor.java index 480e30224..329980e52 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ObjectAccessor.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ObjectAccessor.java @@ -1,8 +1,8 @@ package nl.jqno.equalsverifier.internal.reflection.vintage; -import java.util.LinkedHashSet; import nl.jqno.equalsverifier.internal.reflection.RecordsHelper; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import org.objenesis.Objenesis; @@ -95,12 +95,12 @@ public Class type() { * @param valueProvider Prefabricated values to take values from. * @param enclosingType Describes the type that contains this object as a field, to determine * any generic parameters it may contain. - * @param typeStack Keeps track of recursion in the type. + * @param attributes Provides metadata needed to provide a value and to keep track of recursion. * @return An accessor to the scrambled object. */ public abstract ObjectAccessor scramble( VintageValueProvider valueProvider, TypeTag enclosingType, - LinkedHashSet typeStack + Attributes attributes ); } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessor.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessor.java index c1f63ea44..8c45295aa 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessor.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessor.java @@ -1,13 +1,13 @@ package nl.jqno.equalsverifier.internal.reflection.vintage; import java.lang.reflect.Field; -import java.util.LinkedHashSet; import java.util.List; import java.util.function.Function; import java.util.stream.Collectors; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; import nl.jqno.equalsverifier.internal.reflection.RecordProbe; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import org.objenesis.Objenesis; @@ -40,12 +40,12 @@ public T copy(Objenesis objenesis) { public ObjectAccessor scramble( VintageValueProvider valueProvider, TypeTag enclosingType, - LinkedHashSet typeStack + Attributes attributes ) { return makeAccessor(f -> { Object value = getField(f); TypeTag tag = TypeTag.of(f, enclosingType); - return valueProvider.giveOther(tag, value, typeStack); + return valueProvider.giveOther(tag, value, attributes); }); } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactory.java index 0058867ad..06e4571e1 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactory.java @@ -4,10 +4,10 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.LinkedHashSet; import java.util.List; import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; /** @@ -18,13 +18,6 @@ public abstract class AbstractGenericFactory implements PrefabValueFactory public static final TypeTag OBJECT_TYPE_TAG = new TypeTag(Object.class); - protected LinkedHashSet cloneWith(LinkedHashSet typeStack, TypeTag tag) { - @SuppressWarnings("unchecked") - LinkedHashSet clone = (LinkedHashSet) typeStack.clone(); - clone.add(tag); - return clone; - } - protected TypeTag copyGenericTypesInto(Class type, TypeTag source) { List genericTypes = new ArrayList<>(); for (TypeTag tag : source.getGenericTypes()) { @@ -37,23 +30,23 @@ protected TypeTag determineAndCacheActualTypeTag( int n, TypeTag tag, VintageValueProvider valueProvider, - LinkedHashSet typeStack + Attributes attributes ) { - return determineAndCacheActualTypeTag(n, tag, valueProvider, typeStack, null); + return determineAndCacheActualTypeTag(n, tag, valueProvider, attributes, null); } protected TypeTag determineAndCacheActualTypeTag( int n, TypeTag tag, VintageValueProvider valueProvider, - LinkedHashSet typeStack, + Attributes attributes, Class bottomType ) { TypeTag result = determineActualTypeTagFor(n, tag); if (bottomType != null && result.getType().equals(Object.class)) { result = new TypeTag(bottomType); } - valueProvider.realizeCacheFor(result, typeStack); + valueProvider.realizeCacheFor(result, attributes); return result; } 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 1b1222861..9b1af52e3 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 @@ -1,9 +1,9 @@ package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; -import java.util.LinkedHashSet; import java.util.function.Function; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; public class CopyFactory extends AbstractGenericFactory { @@ -20,9 +20,9 @@ public CopyFactory(Class source, Function copy) { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - LinkedHashSet typeStack + Attributes attributes ) { - LinkedHashSet clone = cloneWith(typeStack, tag); + Attributes clone = attributes.cloneAndAdd(tag); TypeTag sourceTag = copyGenericTypesInto(source, tag); valueProvider.realizeCacheFor(sourceTag, clone); 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 5b1424694..836bc01e2 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 @@ -1,11 +1,11 @@ package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; import java.util.HashMap; -import java.util.LinkedHashSet; import java.util.Map; import java.util.function.Function; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; @SuppressWarnings({ "unchecked", "rawtypes" }) @@ -21,9 +21,9 @@ public EnumMapFactory(Function factory) { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - LinkedHashSet typeStack + Attributes attributes ) { - LinkedHashSet clone = cloneWith(typeStack, tag); + Attributes clone = attributes.cloneAndAdd(tag); TypeTag keyTag = determineAndCacheActualTypeTag(0, tag, valueProvider, clone, Enum.class); TypeTag valueTag = determineAndCacheActualTypeTag(1, tag, valueProvider, clone, Enum.class); 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 61a59e447..23d3bdfcc 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 @@ -2,10 +2,10 @@ import java.util.Collection; import java.util.HashSet; -import java.util.LinkedHashSet; import java.util.function.Function; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; /** @@ -25,9 +25,9 @@ public EnumSetFactory(Function factory) { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - LinkedHashSet typeStack + Attributes attributes ) { - LinkedHashSet clone = cloneWith(typeStack, tag); + Attributes clone = attributes.cloneAndAdd(tag); TypeTag entryTag = determineAndCacheActualTypeTag(0, tag, valueProvider, clone, Enum.class); Collection red = new HashSet<>(); diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/ExternalFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/ExternalFactory.java index d458ee0a7..da625da89 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/ExternalFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/ExternalFactory.java @@ -3,10 +3,10 @@ import static nl.jqno.equalsverifier.internal.reflection.Util.classes; import static nl.jqno.equalsverifier.internal.reflection.Util.objects; -import java.util.LinkedHashSet; import nl.jqno.equalsverifier.internal.reflection.ConditionalInstantiator; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factoryproviders.FactoryProvider; @@ -27,7 +27,7 @@ public ExternalFactory(String factoryName) { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - LinkedHashSet typeStack + Attributes attributes ) { if (factoryCache == null) { ConditionalInstantiator ci = new ConditionalInstantiator(factoryName); @@ -36,6 +36,6 @@ public Tuple createValues( } PrefabValueFactory factory = factoryCache.get(tag.getType()); - return factory.createValues(tag, valueProvider, typeStack); + return factory.createValues(tag, valueProvider, attributes); } } 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 eb69ea6b3..91b9aeac7 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 @@ -2,11 +2,8 @@ import java.lang.reflect.Array; import java.lang.reflect.Field; -import java.util.LinkedHashSet; -import nl.jqno.equalsverifier.internal.reflection.FieldIterable; -import nl.jqno.equalsverifier.internal.reflection.FieldProbe; -import nl.jqno.equalsverifier.internal.reflection.Tuple; -import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.*; +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; import org.objenesis.Objenesis; @@ -29,11 +26,9 @@ public FallbackFactory(Objenesis objenesis) { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - LinkedHashSet typeStack + Attributes attributes ) { - @SuppressWarnings("unchecked") - LinkedHashSet clone = (LinkedHashSet) typeStack.clone(); - clone.add(tag); + Attributes clone = attributes.cloneAndAdd(tag); Class type = tag.getType(); if (type.isEnum()) { @@ -65,12 +60,12 @@ private Tuple giveEnumInstances(TypeTag tag) { private Tuple giveArrayInstances( TypeTag tag, VintageValueProvider valueProvider, - LinkedHashSet typeStack + Attributes attributes ) { Class type = tag.getType(); Class componentType = type.getComponentType(); TypeTag componentTag = new TypeTag(componentType); - valueProvider.realizeCacheFor(componentTag, typeStack); + valueProvider.realizeCacheFor(componentTag, attributes); T red = (T) Array.newInstance(componentType, 1); Array.set(red, 0, valueProvider.giveRed(componentTag)); @@ -85,14 +80,14 @@ private Tuple giveArrayInstances( private void traverseFields( TypeTag tag, VintageValueProvider valueProvider, - LinkedHashSet typeStack + Attributes attributes ) { Class type = tag.getType(); for (Field field : FieldIterable.of(type)) { FieldProbe probe = FieldProbe.of(field); boolean isStaticAndFinal = probe.isStatic() && probe.isFinal(); if (!isStaticAndFinal) { - valueProvider.realizeCacheFor(TypeTag.of(field, tag), typeStack); + valueProvider.realizeCacheFor(TypeTag.of(field, tag), attributes); } } } @@ -100,12 +95,12 @@ private void traverseFields( private Tuple giveInstances( TypeTag tag, VintageValueProvider valueProvider, - LinkedHashSet typeStack + Attributes attributes ) { ClassAccessor accessor = ClassAccessor.of(tag.getType(), valueProvider, objenesis); - T red = accessor.getRedObject(tag, typeStack); - T blue = accessor.getBlueObject(tag, typeStack); - T redCopy = accessor.getRedObject(tag, typeStack); + T red = accessor.getRedObject(tag, attributes); + T blue = accessor.getBlueObject(tag, attributes); + T redCopy = accessor.getRedObject(tag, attributes); 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 f835cfe90..92752ac21 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 @@ -1,10 +1,10 @@ package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; -import java.util.LinkedHashSet; import java.util.Map; import java.util.function.Supplier; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; /** @@ -24,9 +24,9 @@ public MapFactory(Supplier createEmpty) { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - LinkedHashSet typeStack + Attributes attributes ) { - LinkedHashSet clone = cloneWith(typeStack, tag); + Attributes clone = attributes.cloneAndAdd(tag); TypeTag keyTag = determineAndCacheActualTypeTag(0, tag, valueProvider, clone); TypeTag valueTag = determineAndCacheActualTypeTag(1, tag, valueProvider, clone); diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/PrefabValueFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/PrefabValueFactory.java index 4616c2660..172bebbe9 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/PrefabValueFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/PrefabValueFactory.java @@ -1,8 +1,8 @@ package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; -import java.util.LinkedHashSet; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; /** @@ -17,13 +17,8 @@ public interface PrefabValueFactory { * * @param tag The typetag of the type for which to create values. * @param valueProvider Repository for querying instances of generic types of the type tag. - * @param typeStack A stack of {@link TypeTag}s that require tag in order to be created. Used - * for recursion detection. + * @param attributes Provides metadata needed to provide a value and to keep track of recursion. * @return A "red" instance of {@code T}. */ - Tuple createValues( - TypeTag tag, - VintageValueProvider valueProvider, - LinkedHashSet typeStack - ); + Tuple createValues(TypeTag tag, VintageValueProvider valueProvider, Attributes attributes); } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleFactory.java index 44a7ae041..8e54df590 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleFactory.java @@ -1,8 +1,8 @@ package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; -import java.util.LinkedHashSet; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; /** @@ -21,7 +21,7 @@ public SimpleFactory(T red, T blue, T redCopy) { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - LinkedHashSet typeStack + Attributes attributes ) { return tuple; } 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 748f64f7f..785e2e5cb 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 @@ -1,12 +1,12 @@ package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; import java.util.ArrayList; -import java.util.LinkedHashSet; import java.util.List; import java.util.function.Supplier; import nl.jqno.equalsverifier.Func; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; public class SimpleGenericFactory extends AbstractGenericFactory { @@ -23,9 +23,9 @@ public SimpleGenericFactory(Func factory, Supplier emptyFactory) { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - LinkedHashSet typeStack + Attributes attributes ) { - LinkedHashSet clone = cloneWith(typeStack, tag); + Attributes clone = attributes.cloneAndAdd(tag); List redValues = new ArrayList<>(); List blueValues = new ArrayList<>(); diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/GuavaFactoryProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/GuavaFactoryProvider.java index cf571ca2f..317e55259 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/GuavaFactoryProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/GuavaFactoryProvider.java @@ -8,6 +8,7 @@ import java.util.function.Supplier; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.AbstractGenericFactory; @@ -160,9 +161,9 @@ private MultimapFactory(Supplier factory) { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - LinkedHashSet typeStack + Attributes attributes ) { - LinkedHashSet clone = cloneWith(typeStack, tag); + Attributes clone = attributes.cloneAndAdd(tag); TypeTag keyTag = determineAndCacheActualTypeTag(0, tag, valueProvider, clone); TypeTag valueTag = determineAndCacheActualTypeTag(1, tag, valueProvider, clone); @@ -190,9 +191,9 @@ private TableFactory(Supplier factory) { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - LinkedHashSet typeStack + Attributes attributes ) { - LinkedHashSet clone = cloneWith(typeStack, tag); + Attributes clone = attributes.cloneAndAdd(tag); TypeTag columnTag = determineAndCacheActualTypeTag(0, tag, valueProvider, clone); TypeTag rowTag = determineAndCacheActualTypeTag(1, tag, valueProvider, clone); TypeTag valueTag = determineAndCacheActualTypeTag(2, tag, valueProvider, clone); diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProvider.java index 9d6496d4c..1693bc08b 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProvider.java @@ -8,6 +8,7 @@ import java.util.*; import java.util.function.Function; import nl.jqno.equalsverifier.internal.reflection.*; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.AbstractGenericFactory; @@ -109,7 +110,7 @@ static final class PropertyFactory extends AbstractGenericFactory { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - LinkedHashSet typeStack + Attributes attributes ) { ConditionalInstantiator ci = new ConditionalInstantiator(fullyQualifiedTypeName); TypeTag singleParameterTag = copyGenericTypesInto(parameterRawType, tag); diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/TestValueProviders.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/TestValueProviders.java index 7c0a56187..915790688 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/TestValueProviders.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/TestValueProviders.java @@ -20,7 +20,7 @@ private TestValueProviders() {} public static ValueProvider empty() { return new ValueProvider() { @Override - public Optional> provide(TypeTag tag, String label) { + public Optional> provide(TypeTag tag, Attributes attributes) { return Optional.empty(); } }; @@ -30,7 +30,7 @@ public static ValueProvider simple() { return new ValueProvider() { @SuppressWarnings("unchecked") @Override - public Optional> provide(TypeTag tag, String label) { + public Optional> provide(TypeTag tag, Attributes attributes) { if (tag.getType().equals(int.class)) { return Optional.of((Tuple) INTS); } diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProviderTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProviderTest.java index c4c092904..9f092f438 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProviderTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProviderTest.java @@ -2,16 +2,18 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.*; +import java.util.Optional; import nl.jqno.equalsverifier.internal.exceptions.EqualsVerifierInternalBugException; import nl.jqno.equalsverifier.internal.exceptions.NoValueException; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; import org.junit.jupiter.api.Test; public class ChainedValueProviderTest { + private static final Attributes EMPTY_ATTRIBUTES = Attributes.unlabeled(); private static final TypeTag INT = new TypeTag(int.class); private final SingleTypeValueProvider intProvider = new SingleTypeValueProvider<>( @@ -33,20 +35,20 @@ public class ChainedValueProviderTest { @Test public void returnsValueIfMatch() { sut.register(intProvider); - assertEquals(1, sut.provideOrThrow(INT, null).getRed()); + assertEquals(1, sut.provideOrThrow(INT, EMPTY_ATTRIBUTES).getRed()); } @Test public void returnsEmptyIfNoMatch() { sut.register(stringProvider); - assertEquals(Optional.empty(), sut.provide(INT, null)); + assertEquals(Optional.empty(), sut.provide(INT, EMPTY_ATTRIBUTES)); } @Test public void throwsExceptionIfNoMatch() { sut.register(stringProvider); ExpectedException - .when(() -> sut.provideOrThrow(INT, null)) + .when(() -> sut.provideOrThrow(INT, EMPTY_ATTRIBUTES)) .assertThrows(NoValueException.class) .assertDescriptionContains("Could not find a value for int"); } @@ -54,7 +56,7 @@ public void throwsExceptionIfNoMatch() { @Test public void skipsNonMatchingValue() { sut.register(stringProvider, intProvider); - assertEquals(1, sut.provideOrThrow(INT, null).getRed()); + assertEquals(1, sut.provideOrThrow(INT, EMPTY_ATTRIBUTES).getRed()); assertEquals(1, stringProvider.called); assertEquals(1, intProvider.called); } @@ -68,7 +70,7 @@ public void returnsValueFromFirstMatch() { 1 ); sut.register(intProvider, anotherIntProvider); - assertEquals(1, sut.provideOrThrow(INT, null).getRed()); + assertEquals(1, sut.provideOrThrow(INT, EMPTY_ATTRIBUTES).getRed()); assertEquals(1, intProvider.called); assertEquals(0, anotherIntProvider.called); } @@ -76,9 +78,9 @@ public void returnsValueFromFirstMatch() { @Test public void updatesTheCache() { sut.register(intProvider); - sut.provideOrThrow(INT, null); + sut.provideOrThrow(INT, EMPTY_ATTRIBUTES); - assertEquals(1, cache.provideOrThrow(INT, null).getRed()); + assertEquals(1, cache.provideOrThrow(INT, EMPTY_ATTRIBUTES).getRed()); } @Test @@ -86,7 +88,7 @@ public void makesDefensiveCopy() { ValueProvider[] providers = { stringProvider }; sut.register(providers); providers[0] = intProvider; - assertEquals(Optional.empty(), sut.provide(INT, null)); + assertEquals(Optional.empty(), sut.provide(INT, EMPTY_ATTRIBUTES)); } @Test @@ -111,7 +113,7 @@ public SingleTypeValueProvider(Class type, X red, X blue, X redCopy) { @Override @SuppressWarnings("unchecked") - public Optional> provide(TypeTag tag, String label) { + public Optional> provide(TypeTag tag, Attributes attributes) { called++; if (tag.getType().equals(type)) { return Optional.of((Tuple) values); diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreatorTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreatorTest.java index ee51ae639..e99595234 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreatorTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreatorTest.java @@ -201,7 +201,7 @@ public void noValueFound() { static class SubjectCreatorTestValueProvider implements ValueProvider { - public Optional> provide(TypeTag tag, String label) { + public Optional> provide(TypeTag tag, Attributes attributes) { if (int.class.equals(tag.getType())) { return Optional.of(Tuple.of(I_RED, I_BLUE, I_RED)); } @@ -215,7 +215,7 @@ public Optional> provide(TypeTag tag, String label) { static class NoValueProvider implements ValueProvider { @Override - public Optional> provide(TypeTag tag, String label) { + public Optional> provide(TypeTag tag, Attributes attributes) { return Optional.empty(); } } diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderTest.java index 092b1beee..57d4f42f6 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderTest.java @@ -8,10 +8,10 @@ import static org.junit.jupiter.api.Assertions.fail; import java.util.ArrayList; -import java.util.LinkedHashSet; import java.util.List; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; @@ -50,7 +50,7 @@ public void sanityTestFactoryIncreasesStringLength() { @Test public void provide() { - Tuple actual = vp.provideOrThrow(POINT_TAG, null); + Tuple actual = vp.provideOrThrow(POINT_TAG, Attributes.unlabeled()); assertEquals(Tuple.of(new Point(42, 42), new Point(1337, 1337), new Point(42, 42)), actual); } @@ -208,7 +208,7 @@ public AppendingStringTestFactory() { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - LinkedHashSet typeStack + Attributes attributes ) { red += "r"; blue += "b"; @@ -224,7 +224,7 @@ private static final class ListTestFactory implements PrefabValueFactory { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - LinkedHashSet typeStack + Attributes attributes ) { TypeTag subtag = tag.getGenericTypes().get(0); diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessorTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessorTest.java index 13e56d293..ab5c63656 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessorTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessorTest.java @@ -5,10 +5,10 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; -import java.util.LinkedHashSet; import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; import nl.jqno.equalsverifier.testhelpers.types.PointContainer; @@ -22,7 +22,7 @@ public class ClassAccessorTest { - private LinkedHashSet empty; + private Attributes empty; private Objenesis objenesis; private CachedValueProvider cache; private FactoryCache factoryCache; @@ -31,7 +31,7 @@ public class ClassAccessorTest { @BeforeEach public void setup() { - empty = new LinkedHashSet<>(); + empty = Attributes.unlabeled(); objenesis = new ObjenesisStd(); cache = new CachedValueProvider(); factoryCache = JavaApiPrefabValues.build(); diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorScramblingTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorScramblingTest.java index e59ab0728..0f997ed47 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorScramblingTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorScramblingTest.java @@ -5,12 +5,12 @@ import java.text.AttributedString; import java.util.ArrayList; -import java.util.LinkedHashSet; import java.util.List; import nl.jqno.equalsverifier.internal.exceptions.ModuleException; import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; @@ -26,7 +26,7 @@ public class InPlaceObjectAccessorScramblingTest { - private static final LinkedHashSet EMPTY_TYPE_STACK = new LinkedHashSet<>(); + private static final Attributes EMPTY_ATTRIBUTES = Attributes.unlabeled(); private Objenesis objenesis; private VintageValueProvider valueProviderTest; @@ -161,7 +161,7 @@ private T copy(T object) { } private ObjectAccessor doScramble(Object object) { - return create(object).scramble(valueProviderTest, TypeTag.NULL, EMPTY_TYPE_STACK); + return create(object).scramble(valueProviderTest, TypeTag.NULL, EMPTY_ATTRIBUTES); } static final class StringContainer { diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactoryTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactoryTest.java index e0a2263fd..f480f042a 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactoryTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactoryTest.java @@ -4,10 +4,10 @@ import static nl.jqno.equalsverifier.internal.reflection.Util.objects; import static org.junit.jupiter.api.Assertions.assertThrows; -import java.util.LinkedHashSet; import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -26,7 +26,7 @@ public void setUp() { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - LinkedHashSet typeStack + Attributes attributes ) { return Tuple.of("red", "blue", new String("red")); } diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java index 606e7fbbd..79b553380 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java @@ -6,11 +6,11 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.LinkedHashSet; import nl.jqno.equalsverifier.internal.exceptions.RecursionException; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; @@ -30,7 +30,7 @@ public class FallbackFactoryTest { private FallbackFactory factory; private VintageValueProvider valueProvider; - private LinkedHashSet typeStack; + private Attributes attributes; @BeforeEach public void setUp() { @@ -41,7 +41,7 @@ public void setUp() { factoryCache.put(int.class, values(42, 1337, 42)); valueProvider = new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); - typeStack = new LinkedHashSet<>(); + attributes = Attributes.unlabeled(); } @Test @@ -61,7 +61,7 @@ public void giveMultiElementEnum() { @Test public void giveArray() { - Tuple tuple = factory.createValues(new TypeTag(int[].class), valueProvider, typeStack); + Tuple tuple = factory.createValues(new TypeTag(int[].class), valueProvider, attributes); assertArrayEquals(new int[] { 42 }, (int[]) tuple.getRed()); assertArrayEquals(new int[] { 1337 }, (int[]) tuple.getBlue()); } @@ -81,7 +81,7 @@ public void giveClassWithFields() { @Test public void dontGiveRecursiveClass() { ExpectedException - .when(() -> factory.createValues(new TypeTag(Node.class), valueProvider, typeStack)) + .when(() -> factory.createValues(new TypeTag(Node.class), valueProvider, attributes)) .assertThrows(RecursionException.class); } @@ -89,7 +89,7 @@ public void dontGiveRecursiveClass() { public void dontGiveTwoStepRecursiveClass() { ExpectedException .when(() -> - factory.createValues(new TypeTag(TwoStepNodeA.class), valueProvider, typeStack) + factory.createValues(new TypeTag(TwoStepNodeA.class), valueProvider, attributes) ) .assertThrows(RecursionException.class) .assertDescriptionContains("TwoStepNodeA", "TwoStepNodeB"); @@ -98,13 +98,14 @@ public void dontGiveTwoStepRecursiveClass() { @Test public void dontGiveRecursiveArray() { ExpectedException - .when(() -> factory.createValues(new TypeTag(NodeArray.class), valueProvider, typeStack) + .when(() -> + factory.createValues(new TypeTag(NodeArray.class), valueProvider, attributes) ) .assertThrows(RecursionException.class); } private void assertCorrectTuple(Class type, T expectedRed, T expectedBlue) { - Tuple tuple = factory.createValues(new TypeTag(type), valueProvider, typeStack); + Tuple tuple = factory.createValues(new TypeTag(type), valueProvider, attributes); assertEquals(expectedRed, tuple.getRed()); assertEquals(expectedBlue, tuple.getBlue()); } diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactoryTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactoryTest.java index eea125d5e..677a949bb 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactoryTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactoryTest.java @@ -3,12 +3,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.HashMap; -import java.util.LinkedHashSet; import java.util.Map; import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; import nl.jqno.equalsverifier.testhelpers.types.TypeHelper.OneElementEnum; @@ -41,7 +41,7 @@ public class MapFactoryTest { private static final MapFactory MAP_FACTORY = new MapFactory<>(HashMap::new); - private final LinkedHashSet typeStack = new LinkedHashSet<>(); + private final Attributes attributes = Attributes.unlabeled(); private VintageValueProvider valueProvider; private String red; private String blue; @@ -70,7 +70,7 @@ public void createMapsOfStringToString() { Tuple tuple = MAP_FACTORY.createValues( STRINGSTRINGMAP_TYPETAG, valueProvider, - typeStack + attributes ); assertEquals(mapOf(red, blue), tuple.getRed()); assertEquals(mapOf(blue, blue), tuple.getBlue()); @@ -78,14 +78,14 @@ public void createMapsOfStringToString() { @Test public void createMapsOfWildcard() { - Tuple tuple = MAP_FACTORY.createValues(WILDCARDMAP_TYPETAG, valueProvider, typeStack); + Tuple tuple = MAP_FACTORY.createValues(WILDCARDMAP_TYPETAG, valueProvider, attributes); assertEquals(mapOf(redObject, blueObject), tuple.getRed()); assertEquals(mapOf(blueObject, blueObject), tuple.getBlue()); } @Test public void createRawMaps() { - Tuple tuple = MAP_FACTORY.createValues(RAWMAP_TYPETAG, valueProvider, typeStack); + Tuple tuple = MAP_FACTORY.createValues(RAWMAP_TYPETAG, valueProvider, attributes); assertEquals(mapOf(redObject, blueObject), tuple.getRed()); assertEquals(mapOf(blueObject, blueObject), tuple.getBlue()); } @@ -95,7 +95,7 @@ public void createMapOfOneElementEnumKey() { Tuple tuple = MAP_FACTORY.createValues( ONEELEMENTENUMKEYMAP_TYPETAG, valueProvider, - typeStack + attributes ); assertEquals(mapOf(redEnum, blueObject), tuple.getRed()); assertEquals(new HashMap<>(), tuple.getBlue()); diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactoryTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactoryTest.java index cfa9a3137..fe9af463e 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactoryTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactoryTest.java @@ -2,12 +2,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.LinkedHashSet; import java.util.Optional; import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; import nl.jqno.equalsverifier.testhelpers.types.Pair; @@ -42,7 +42,7 @@ public class SimpleGenericFactoryTest { ); private static final PrefabValueFactory PAIR_FACTORY = Factories.simple(Pair::new, null); - private final LinkedHashSet typeStack = new LinkedHashSet<>(); + private final Attributes attributes = Attributes.unlabeled(); private VintageValueProvider valueProvider; private String redString; private String blueString; @@ -73,7 +73,7 @@ public void createOptionalsOfMapOfString() { Tuple tuple = OPTIONAL_FACTORY.createValues( STRINGOPTIONAL_TYPETAG, valueProvider, - typeStack + attributes ); assertEquals(Optional.of(redString), tuple.getRed()); assertEquals(Optional.of(blueString), tuple.getBlue()); @@ -84,7 +84,7 @@ public void createOptionalsOfWildcard() { Tuple tuple = OPTIONAL_FACTORY.createValues( WILDCARDOPTIONAL_TYPETAG, valueProvider, - typeStack + attributes ); assertEquals(Optional.of(redObject), tuple.getRed()); assertEquals(Optional.of(blueObject), tuple.getBlue()); @@ -95,7 +95,7 @@ public void createRawOptionals() { Tuple tuple = OPTIONAL_FACTORY.createValues( RAWOPTIONAL_TYPETAG, valueProvider, - typeStack + attributes ); assertEquals(Optional.of(redObject), tuple.getRed()); assertEquals(Optional.of(blueObject), tuple.getBlue()); @@ -103,7 +103,7 @@ public void createRawOptionals() { @Test public void createSomethingWithMoreThanOneTypeParameter() { - Tuple tuple = PAIR_FACTORY.createValues(PAIR_TYPETAG, valueProvider, typeStack); + Tuple tuple = PAIR_FACTORY.createValues(PAIR_TYPETAG, valueProvider, attributes); assertEquals(new Pair<>(redString, redInt), tuple.getRed()); assertEquals(new Pair<>(blueString, blueInt), tuple.getBlue()); } From 3068d401b7dacad8abd4d6770ddef611763bfc10 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Fri, 22 Nov 2024 12:08:08 +0100 Subject: [PATCH 04/18] Removes unnecessary complication --- .../factories/FallbackFactory.java | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) 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 91b9aeac7..1e30ea0ec 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 @@ -1,8 +1,8 @@ package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; import java.lang.reflect.Array; -import java.lang.reflect.Field; -import nl.jqno.equalsverifier.internal.reflection.*; +import nl.jqno.equalsverifier.internal.reflection.Tuple; +import nl.jqno.equalsverifier.internal.reflection.TypeTag; 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; @@ -38,7 +38,6 @@ public Tuple createValues( return giveArrayInstances(tag, valueProvider, clone); } - traverseFields(tag, valueProvider, clone); return giveInstances(tag, valueProvider, clone); } @@ -77,21 +76,6 @@ private Tuple giveArrayInstances( return new Tuple<>(red, blue, redCopy); } - private void traverseFields( - TypeTag tag, - VintageValueProvider valueProvider, - Attributes attributes - ) { - Class type = tag.getType(); - for (Field field : FieldIterable.of(type)) { - FieldProbe probe = FieldProbe.of(field); - boolean isStaticAndFinal = probe.isStatic() && probe.isFinal(); - if (!isStaticAndFinal) { - valueProvider.realizeCacheFor(TypeTag.of(field, tag), attributes); - } - } - } - private Tuple giveInstances( TypeTag tag, VintageValueProvider valueProvider, From f03e2c8ffe6a3750695d6bc687716c9954f9f38a Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Fri, 22 Nov 2024 13:48:41 +0100 Subject: [PATCH 05/18] Fixes test name --- .../integration/extended_contract/RecordsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/RecordsTest.java b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/RecordsTest.java index 076a44c41..fd6aa50ae 100644 --- a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/RecordsTest.java +++ b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/RecordsTest.java @@ -134,7 +134,7 @@ public void succeed_whenRecordValidatesInput_givenValidPrefabValues() { } @Test - public void succeed_whenRecord() { + public void succeed_whenRecordHasBoundedWildcardGeneric() { EqualsVerifier.forClass(WildcardGenericRecordContainer.class).verify(); } From e9749ebaa939df87551c655f9c714b1d545ade2d Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Fri, 22 Nov 2024 13:49:58 +0100 Subject: [PATCH 06/18] Removes realizeCacheFor from VintageValueProvider --- .../instantiation/VintageValueProvider.java | 48 ++++++----------- .../factories/AbstractGenericFactory.java | 1 - .../prefabvalues/factories/CopyFactory.java | 7 ++- .../factories/EnumMapFactory.java | 6 +-- .../factories/EnumSetFactory.java | 6 +-- .../factories/FallbackFactory.java | 7 ++- .../prefabvalues/factories/MapFactory.java | 8 +-- .../factories/SimpleGenericFactory.java | 4 +- .../GuavaFactoryProvider.java | 30 ++++++----- .../JavaFxFactoryProvider.java | 6 +-- .../VintageValueProviderCreatorTest.java | 9 ---- .../VintageValueProviderTest.java | 51 +------------------ .../JavaFxFactoryProviderTest.java | 13 ++++- 13 files changed, 67 insertions(+), 129 deletions(-) diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java index 2c1294903..8a8edf9bd 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java @@ -23,7 +23,6 @@ public class VintageValueProvider implements ValueProvider { private final ValueProvider valueProvider; - private final CachedValueProvider cache; private final FactoryCache factoryCache; private final PrefabValueFactory fallbackFactory; @@ -43,7 +42,6 @@ public VintageValueProvider( Objenesis objenesis ) { this.valueProvider = valueProvider; - this.cache = cache; this.factoryCache = factoryCache; this.fallbackFactory = new FallbackFactory<>(objenesis); } @@ -64,7 +62,11 @@ public Optional> provide(TypeTag tag, Attributes attributes) { * @return The "red" prefabricated value. */ public T giveRed(TypeTag tag) { - return this.giveTuple(tag).getRed(); + return giveRed(tag, Attributes.unlabeled()); + } + + public T giveRed(TypeTag tag, Attributes attributes) { + return this.giveTuple(tag, attributes).getRed(); } /** @@ -77,7 +79,11 @@ public T giveRed(TypeTag tag) { * @return The "blue" prefabricated value. */ public T giveBlue(TypeTag tag) { - return this.giveTuple(tag).getBlue(); + return giveBlue(tag, Attributes.unlabeled()); + } + + public T giveBlue(TypeTag tag, Attributes attributes) { + return this.giveTuple(tag, attributes).getBlue(); } /** @@ -90,7 +96,11 @@ public T giveBlue(TypeTag tag) { * @return A shallow copy of the "red" prefabricated value. */ public T giveRedCopy(TypeTag tag) { - return this.giveTuple(tag).getRedCopy(); + return giveRedCopy(tag, Attributes.unlabeled()); + } + + public T giveRedCopy(TypeTag tag, Attributes attributes) { + return this.giveTuple(tag, attributes).getRedCopy(); } /** @@ -145,32 +155,8 @@ private boolean arraysAreDeeplyEqual(Object x, Object y) { return Arrays.deepEquals(new Object[] { x }, new Object[] { y }); } - /** - * Makes sure that values for the specified type are present in the cache, but doesn't return - * them. - * - * @param The desired type. - * @param tag A description of the desired type, including generic parameters. - * @param attributes Keeps track of recursion in the type. - */ - public void realizeCacheFor(TypeTag tag, Attributes attributes) { - if (!cache.contains(tag, attributes.label)) { - Tuple tuple = createTuple(tag, attributes); - cache.put(tag, attributes.label, tuple); - } - } - - private Tuple giveTuple(TypeTag tag) { - return giveTuple(tag, Attributes.unlabeled()); - } - @SuppressWarnings("unchecked") private Tuple giveTuple(TypeTag tag, Attributes attributes) { - realizeCacheFor(tag, attributes); - return (Tuple) cache.provide(tag, attributes).get(); - } - - private Tuple createTuple(TypeTag tag, Attributes attributes) { if (attributes.typeStack.contains(tag)) { throw new RecursionException(attributes.typeStack); } @@ -190,8 +176,6 @@ private Tuple createTuple(TypeTag tag, Attributes attributes) { return factory.createValues(tag, this, attributes); } - @SuppressWarnings("unchecked") - Tuple result = (Tuple) fallbackFactory.createValues(tag, this, attributes); - return result; + return (Tuple) fallbackFactory.createValues(tag, this, attributes); } } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactory.java index 06e4571e1..7cac47f5d 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactory.java @@ -46,7 +46,6 @@ protected TypeTag determineAndCacheActualTypeTag( if (bottomType != null && result.getType().equals(Object.class)) { result = new TypeTag(bottomType); } - valueProvider.realizeCacheFor(result, attributes); return result; } 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 9b1af52e3..4eeee91b7 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 @@ -24,11 +24,10 @@ public Tuple createValues( ) { Attributes clone = attributes.cloneAndAdd(tag); TypeTag sourceTag = copyGenericTypesInto(source, tag); - valueProvider.realizeCacheFor(sourceTag, clone); - S redSource = valueProvider.giveRed(sourceTag); - S blueSource = valueProvider.giveBlue(sourceTag); - S redCopySource = valueProvider.giveRedCopy(sourceTag); + S redSource = valueProvider.giveRed(sourceTag, clone); + S blueSource = valueProvider.giveBlue(sourceTag, clone); + S redCopySource = valueProvider.giveRedCopy(sourceTag, clone); return Tuple.of(copy.apply(redSource), copy.apply(blueSource), copy.apply(redCopySource)); } 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 836bc01e2..accdfa191 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 @@ -30,9 +30,9 @@ public Tuple createValues( Map red = new HashMap<>(); Map blue = new HashMap<>(); Map redCopy = new HashMap<>(); - red.put(valueProvider.giveRed(keyTag), valueProvider.giveBlue(valueTag)); - blue.put(valueProvider.giveBlue(keyTag), valueProvider.giveBlue(valueTag)); - redCopy.put(valueProvider.giveRed(keyTag), valueProvider.giveBlue(valueTag)); + 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)); 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 23d3bdfcc..4aeb75791 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 @@ -33,9 +33,9 @@ public Tuple createValues( Collection red = new HashSet<>(); Collection blue = new HashSet<>(); Collection redCopy = new HashSet<>(); - red.add(valueProvider.giveRed(entryTag)); - blue.add(valueProvider.giveBlue(entryTag)); - redCopy.add(valueProvider.giveRed(entryTag)); + red.add(valueProvider.giveRed(entryTag, clone)); + blue.add(valueProvider.giveBlue(entryTag, clone)); + redCopy.add(valueProvider.giveRed(entryTag, clone)); 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 1e30ea0ec..605d2dbe5 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 @@ -64,14 +64,13 @@ private Tuple giveArrayInstances( Class type = tag.getType(); Class componentType = type.getComponentType(); TypeTag componentTag = new TypeTag(componentType); - valueProvider.realizeCacheFor(componentTag, attributes); T red = (T) Array.newInstance(componentType, 1); - Array.set(red, 0, valueProvider.giveRed(componentTag)); + Array.set(red, 0, valueProvider.giveRed(componentTag, attributes)); T blue = (T) Array.newInstance(componentType, 1); - Array.set(blue, 0, valueProvider.giveBlue(componentTag)); + Array.set(blue, 0, valueProvider.giveBlue(componentTag, attributes)); T redCopy = (T) Array.newInstance(componentType, 1); - Array.set(redCopy, 0, valueProvider.giveRed(componentTag)); + Array.set(redCopy, 0, valueProvider.giveRed(componentTag, attributes)); 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 92752ac21..38eca6fa6 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,16 +34,16 @@ 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); - Object blueKey = valueProvider.giveBlue(keyTag); - Object blueValue = valueProvider.giveBlue(valueTag); + Object redKey = valueProvider.giveRed(keyTag, clone); + Object blueKey = valueProvider.giveBlue(keyTag, clone); + Object blueValue = valueProvider.giveBlue(valueTag, clone); T red = createEmpty.get(); red.put(redKey, blueValue); T blue = createEmpty.get(); if (!redKey.equals(blueKey)) { // This happens with single-element enums - blue.put(valueProvider.giveBlue(keyTag), blueValue); + blue.put(valueProvider.giveBlue(keyTag, clone), blueValue); } T redCopy = createEmpty.get(); 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 785e2e5cb..f3ec0ee34 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,8 +35,8 @@ public Tuple createValues( for (int i = 0; i < n; i++) { TypeTag paramTag = determineAndCacheActualTypeTag(i, tag, valueProvider, clone); - Object redValue = valueProvider.giveRed(paramTag); - Object blueValue = valueProvider.giveBlue(paramTag); + Object redValue = valueProvider.giveRed(paramTag, clone); + Object blueValue = valueProvider.giveBlue(paramTag, clone); if (redValue.equals(blueValue)) { // This happens with single-element enums useEmpty = true; } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/GuavaFactoryProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/GuavaFactoryProvider.java index 317e55259..e20df0d9b 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/GuavaFactoryProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/GuavaFactoryProvider.java @@ -170,9 +170,15 @@ public Tuple createValues( T red = factory.get(); T blue = factory.get(); T redCopy = factory.get(); - red.put(valueProvider.giveRed(keyTag), valueProvider.giveBlue(valueTag)); - blue.put(valueProvider.giveBlue(keyTag), valueProvider.giveBlue(valueTag)); - redCopy.put(valueProvider.giveRed(keyTag), valueProvider.giveBlue(valueTag)); + 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) + ); return Tuple.of(red, blue, redCopy); } @@ -202,19 +208,19 @@ public Tuple createValues( T blue = factory.get(); T redCopy = factory.get(); red.put( - valueProvider.giveRed(columnTag), - valueProvider.giveRed(rowTag), - valueProvider.giveBlue(valueTag) + valueProvider.giveRed(columnTag, clone), + valueProvider.giveRed(rowTag, clone), + valueProvider.giveBlue(valueTag, clone) ); blue.put( - valueProvider.giveBlue(columnTag), - valueProvider.giveBlue(rowTag), - valueProvider.giveBlue(valueTag) + valueProvider.giveBlue(columnTag, clone), + valueProvider.giveBlue(rowTag, clone), + valueProvider.giveBlue(valueTag, clone) ); redCopy.put( - valueProvider.giveRed(columnTag), - valueProvider.giveRed(rowTag), - valueProvider.giveBlue(valueTag) + valueProvider.giveRed(columnTag, clone), + valueProvider.giveRed(rowTag, clone), + valueProvider.giveBlue(valueTag, clone) ); return Tuple.of(red, blue, redCopy); diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProvider.java index 1693bc08b..0ab9862b2 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProvider.java @@ -117,15 +117,15 @@ public Tuple createValues( T red = ci.instantiate( classes(parameterRawType), - objects(valueProvider.giveRed(singleParameterTag)) + objects(valueProvider.giveRed(singleParameterTag, attributes)) ); T blue = ci.instantiate( classes(parameterRawType), - objects(valueProvider.giveBlue(singleParameterTag)) + objects(valueProvider.giveBlue(singleParameterTag, attributes)) ); T redCopy = ci.instantiate( classes(parameterRawType), - objects(valueProvider.giveRed(singleParameterTag)) + objects(valueProvider.giveRed(singleParameterTag, attributes)) ); return Tuple.of(red, blue, redCopy); diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderCreatorTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderCreatorTest.java index af92d7e71..fd76c8c7c 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderCreatorTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderCreatorTest.java @@ -51,15 +51,6 @@ public void simple() { assertFalse(red.equals(blue)); } - @Test - public void createSecondTimeIsNoOp() { - Point red = valueProvider.giveRed(POINT_TAG); - Point blue = valueProvider.giveBlue(POINT_TAG); - - assertSame(red, valueProvider.giveRed(POINT_TAG)); - assertSame(blue, valueProvider.giveBlue(POINT_TAG)); - } - @Test public void createEnum() { assertNotNull(valueProvider.giveRed(ENUM_TAG)); diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderTest.java index 57d4f42f6..1ba7896e3 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderTest.java @@ -35,19 +35,11 @@ public class VintageValueProviderTest { @BeforeEach public void setUp() { - factoryCache.put(String.class, new AppendingStringTestFactory()); + factoryCache.put(String.class, values("r", "b", new String("r"))); factoryCache.put(int.class, values(42, 1337, 42)); vp = new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); } - @Test - public void sanityTestFactoryIncreasesStringLength() { - AppendingStringTestFactory f = new AppendingStringTestFactory(); - assertEquals("r", f.createValues(null, null, null).getRed()); - assertEquals("rr", f.createValues(null, null, null).getRed()); - assertEquals("rrr", f.createValues(null, null, null).getRed()); - } - @Test public void provide() { Tuple actual = vp.provideOrThrow(POINT_TAG, Attributes.unlabeled()); @@ -59,36 +51,17 @@ public void giveRedFromFactory() { assertEquals("r", vp.giveRed(STRING_TAG)); } - @Test - public void giveRedFromCache() { - vp.giveRed(STRING_TAG); - assertEquals("r", vp.giveRed(STRING_TAG)); - } - @Test public void giveBlueFromFactory() { assertEquals("b", vp.giveBlue(STRING_TAG)); } - @Test - public void giveBlueFromCache() { - vp.giveBlue(STRING_TAG); - assertEquals("b", vp.giveBlue(STRING_TAG)); - } - @Test public void giveRedCopyFromFactory() { assertEquals("r", vp.giveRedCopy(STRING_TAG)); assertNotSame(vp.giveRed(STRING_TAG), vp.giveRedCopy(STRING_TAG)); } - @Test - public void giveRedCopyFromCache() { - vp.giveRedCopy(STRING_TAG); - assertEquals("r", vp.giveRedCopy(STRING_TAG)); - assertNotSame(vp.giveRed(STRING_TAG), vp.giveRedCopy(STRING_TAG)); - } - @Test public void giveRedFromFallbackFactory() { Point actual = vp.giveRed(POINT_TAG); @@ -194,28 +167,6 @@ public int hashCode() { } } - private static class AppendingStringTestFactory implements PrefabValueFactory { - - private String red; - private String blue; - - public AppendingStringTestFactory() { - red = ""; - blue = ""; - } - - @Override - public Tuple createValues( - TypeTag tag, - VintageValueProvider valueProvider, - Attributes attributes - ) { - red += "r"; - blue += "b"; - return new Tuple<>(red, blue, new String(red)); - } - } - @SuppressWarnings("rawtypes") private static final class ListTestFactory implements PrefabValueFactory { diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProviderTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProviderTest.java index fe4f51d00..b91a6265c 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProviderTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProviderTest.java @@ -9,6 +9,7 @@ import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factoryproviders.JavaFxFactoryProvider.PropertyFactory; @@ -48,7 +49,11 @@ public void createInstancesWithCorrectSingleGenericParameter() { GenericContainer.class.getName(), List.class ); - Tuple tuple = factory.createValues(tag, valueProvider, null); + Tuple tuple = factory.createValues( + tag, + valueProvider, + Attributes.unlabeled() + ); assertEquals(valueProvider.giveRed(listTag), tuple.getRed().t); assertEquals(valueProvider.giveBlue(listTag), tuple.getBlue().t); @@ -72,7 +77,11 @@ public void createInstancesWithCorrectMultipleGenericParameter() { GenericMultiContainer.class.getName(), Map.class ); - Tuple tuple = factory.createValues(tag, valueProvider, null); + Tuple tuple = factory.createValues( + tag, + valueProvider, + Attributes.unlabeled() + ); assertEquals(valueProvider.giveRed(mapTag), tuple.getRed().t); assertEquals(valueProvider.giveBlue(mapTag), tuple.getBlue().t); From 67aaaecf1da104b6ad6c95729aae02341683a3e3 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Sat, 23 Nov 2024 10:08:27 +0100 Subject: [PATCH 07/18] Fixes bugs that popped up after removing realizeCacheFor --- .../vintage/prefabvalues/factories/FallbackFactory.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 605d2dbe5..a206d1ae2 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 @@ -1,8 +1,10 @@ package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; import java.lang.reflect.Array; +import nl.jqno.equalsverifier.internal.reflection.ClassProbe; 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.Attributes; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.ClassAccessor; @@ -83,7 +85,11 @@ private Tuple giveInstances( ClassAccessor accessor = ClassAccessor.of(tag.getType(), valueProvider, objenesis); T red = accessor.getRedObject(tag, attributes); T blue = accessor.getBlueObject(tag, attributes); - T redCopy = accessor.getRedObject(tag, attributes); + + @SuppressWarnings("unchecked") + Class actualType = (Class) red.getClass(); + T redCopy = new InstanceCreator<>(new ClassProbe(actualType), objenesis).copy(red); + return new Tuple<>(red, blue, redCopy); } } From 0cb4a1cedf9082087170c6799708d5fdfd9a06ed Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Sat, 23 Nov 2024 20:02:14 +0100 Subject: [PATCH 08/18] Adds test case --- .../factories/FallbackFactoryTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java index 79b553380..60593ad52 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java @@ -5,6 +5,7 @@ import static nl.jqno.equalsverifier.internal.testhelpers.Util.defaultHashCode; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; import nl.jqno.equalsverifier.internal.exceptions.RecursionException; import nl.jqno.equalsverifier.internal.reflection.Tuple; @@ -78,6 +79,18 @@ public void giveClassWithFields() { assertEquals(-10, IntContainer.STATIC_FINAL_I); } + @Test + public void redCopyIsNotSameAsRed() { + Tuple tuple = factory.createValues( + new TypeTag(IntContainer.class), + valueProvider, + attributes + ); + + assertEquals(tuple.getRed(), tuple.getRedCopy()); + assertNotSame(tuple.getRed(), tuple.getRedCopy()); + } + @Test public void dontGiveRecursiveClass() { ExpectedException @@ -108,6 +121,7 @@ private void assertCorrectTuple(Class type, T expectedRed, T expectedBlue Tuple tuple = factory.createValues(new TypeTag(type), valueProvider, attributes); assertEquals(expectedRed, tuple.getRed()); assertEquals(expectedBlue, tuple.getBlue()); + assertEquals(expectedRed, tuple.getRedCopy()); } private static final class IntContainer { From 519aeff67e219429d62f52901f94b1202dd97d6d Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Sun, 24 Nov 2024 19:45:51 +0100 Subject: [PATCH 09/18] Adds two more test cases --- .../vintage/RecordFallbackFactoryTest.java | 52 +++++++++++ .../SealedTypesFallbackFactoryTest.java | 88 +++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordFallbackFactoryTest.java create mode 100644 equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/SealedTypesFallbackFactoryTest.java diff --git a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordFallbackFactoryTest.java b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordFallbackFactoryTest.java new file mode 100644 index 000000000..f9971891f --- /dev/null +++ b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordFallbackFactoryTest.java @@ -0,0 +1,52 @@ +package nl.jqno.equalsverifier.internal.reflection.vintage; + +import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; + +import nl.jqno.equalsverifier.internal.reflection.Tuple; +import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.FallbackFactory; +import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.objenesis.Objenesis; +import org.objenesis.ObjenesisStd; + +public class RecordFallbackFactoryTest { + + private FallbackFactory factory; + private VintageValueProvider valueProvider; + private Attributes attributes; + + @BeforeEach + public void setUp() { + Objenesis objenesis = new ObjenesisStd(); + factory = new FallbackFactory<>(objenesis); + CachedValueProvider cache = new CachedValueProvider(); + FactoryCache factoryCache = new FactoryCache(); + factoryCache.put(int.class, values(42, 1337, 42)); + valueProvider = + new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); + attributes = Attributes.unlabeled(); + } + + @Test + public void redCopyHasTheSameValuesAsRed_whenSutContainsGenericValueThatNeedsToBeIdenticalInRedAndRedCopy() { + Tuple tuple = factory.createValues( + new TypeTag(GenericRecordContainer.class), + valueProvider, + attributes + ); + + assertEquals(tuple.getRed(), tuple.getRedCopy()); + assertNotSame(tuple.getRed(), tuple.getRedCopy()); + } + + record GenericRecord(T t) {} + + record GenericRecordContainer(GenericRecord bgr) {} +} diff --git a/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/SealedTypesFallbackFactoryTest.java b/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/SealedTypesFallbackFactoryTest.java new file mode 100644 index 000000000..5d2237503 --- /dev/null +++ b/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/SealedTypesFallbackFactoryTest.java @@ -0,0 +1,88 @@ +package nl.jqno.equalsverifier.internal.reflection.vintage; + +import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; + +import java.util.Objects; +import nl.jqno.equalsverifier.internal.reflection.Tuple; +import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.FallbackFactory; +import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.objenesis.Objenesis; +import org.objenesis.ObjenesisStd; + +public class SealedTypesFallbackFactoryTest { + + private FallbackFactory factory; + private VintageValueProvider valueProvider; + private Attributes attributes; + + @BeforeEach + public void setUp() { + Objenesis objenesis = new ObjenesisStd(); + factory = new FallbackFactory<>(objenesis); + CachedValueProvider cache = new CachedValueProvider(); + FactoryCache factoryCache = new FactoryCache(); + factoryCache.put(int.class, values(42, 1337, 42)); + valueProvider = + new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); + attributes = Attributes.unlabeled(); + } + + @Test + public void redCopyHasTheSameValuesAsRed_whenSutIsAbstractSealedAndPermittedTypeAddsField() { + Tuple tuple = factory.createValues( + new TypeTag(SealedParentWithFinalChild.class), + valueProvider, + attributes + ); + + assertEquals(tuple.getRed(), tuple.getRedCopy()); + assertNotSame(tuple.getRed(), tuple.getRedCopy()); + } + + public abstract static sealed class SealedParentWithFinalChild permits FinalSealedChild { + + private final int i; + + public SealedParentWithFinalChild(int i) { + this.i = i; + } + + @Override + public boolean equals(Object obj) { + return obj instanceof SealedParentWithFinalChild other && i == other.i; + } + + @Override + public int hashCode() { + return Objects.hash(i); + } + } + + public static final class FinalSealedChild extends SealedParentWithFinalChild { + + private final int j; + + public FinalSealedChild(int i, int j) { + super(i); + this.j = j; + } + + @Override + public boolean equals(Object obj) { + return obj instanceof FinalSealedChild other && super.equals(obj) && j == other.j; + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), j); + } + } +} From f9f5b175325d50525585768783ea26ffeec162c0 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Tue, 26 Nov 2024 10:04:50 +0100 Subject: [PATCH 10/18] Adds additional generics test --- .../extended_contract/GenericTypesTest.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java index 822567528..554c4ab08 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java @@ -15,6 +15,11 @@ public class GenericTypesTest { + @Test + public void succeed_whenClassHasGenericFieldThatsSpecifiedToABuiltinGeneric() { + EqualsVerifier.forClass(GenericContainerWithBuiltin.class).verify(); + } + @Test public void succeed_whenEqualsLooksAtJava8TypesGenericContent() { EqualsVerifier.forClass(JavaGenericTypeContainer.class).verify(); @@ -121,6 +126,29 @@ public void succeed_whenClassHasASelfReferenceGenericParameter_givenPrefabValues .verify(); } + static final class GenericContainerWithBuiltin { + + private final Generic> b; + + public GenericContainerWithBuiltin(Generic> b) { + this.b = b; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof GenericContainerWithBuiltin)) { + return false; + } + GenericContainerWithBuiltin other = (GenericContainerWithBuiltin) obj; + return Objects.equals(b, other.b); + } + + @Override + public int hashCode() { + return Objects.hash(b); + } + } + static final class JavaGenericTypeContainer { private final Optional optional; @@ -172,6 +200,30 @@ public String toString() { } } + static final class Generic { + + private final T t; + + public Generic(T t) { + this.t = t; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Generic)) { + return false; + } + @SuppressWarnings("unchecked") + Generic other = (Generic) obj; + return Objects.equals(t, other.t); + } + + @Override + public int hashCode() { + return Objects.hash(t); + } + } + static final class ListContainer { private final List list; From 142d44c6c74a032a7c72f4e83e4c1bc7c2f5f843 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Tue, 26 Nov 2024 20:42:17 +0100 Subject: [PATCH 11/18] Makes cache attempt unlabeled if labeled was not found --- .../reflection/instantiation/CachedValueProvider.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProvider.java index 6aba203fb..40015c14a 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProvider.java @@ -40,9 +40,13 @@ public boolean contains(TypeTag tag, String label) { @SuppressWarnings("unchecked") @Override public Optional> provide(TypeTag tag, Attributes attributes) { - Key key = Key.of(tag, attributes.label); - if (cache.containsKey(key)) { - return Optional.of((Tuple) cache.get(key)); + Key first = Key.of(tag, attributes.label); + if (cache.containsKey(first)) { + return Optional.of((Tuple) cache.get(first)); + } + Key second = Key.of(tag, null); + if (cache.containsKey(second)) { + return Optional.of((Tuple) cache.get(second)); } return Optional.empty(); } From d6171be5106f3d43978ed304b350657f6090d0a1 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Tue, 26 Nov 2024 21:18:57 +0100 Subject: [PATCH 12/18] Adds tests for CachedValueProvider --- .../CachedValueProviderTest.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProviderTest.java diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProviderTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProviderTest.java new file mode 100644 index 000000000..c3b4f7a3c --- /dev/null +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProviderTest.java @@ -0,0 +1,52 @@ +package nl.jqno.equalsverifier.internal.reflection.instantiation; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Optional; +import nl.jqno.equalsverifier.internal.reflection.Tuple; +import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; +import org.junit.jupiter.api.Test; + +public class CachedValueProviderTest { + + private static final TypeTag INT = new TypeTag(int.class); + + private CachedValueProvider sut = new CachedValueProvider(); + + @Test + public void aRegisteredValueCanBeFound() { + sut.put(INT, null, Tuple.of(3, 2, 3)); + assertEquals(Tuple.of(3, 2, 3), sut.provide(INT, Attributes.unlabeled()).get()); + } + + @Test + public void aValueRegisteredWithALabelCanBeFoundUnderThatLabel() { + sut.put(INT, "label", Tuple.of(3, 2, 3)); + assertEquals(Tuple.of(3, 2, 3), sut.provide(INT, Attributes.labeled("label")).get()); + } + + @Test + public void aValueRegisteredWithALabelCanNotBeFoundWithoutThatLabel() { + sut.put(INT, "label", Tuple.of(3, 2, 3)); + assertEquals(Optional.empty(), sut.provide(INT, Attributes.unlabeled())); + } + + @Test + public void aQueryWithLabelFallsBackToRegisteredValueWithoutLabel() { + sut.put(INT, null, Tuple.of(3, 2, 3)); + assertEquals(Tuple.of(3, 2, 3), sut.provide(INT, Attributes.labeled("label")).get()); + } + + @Test + public void aQueryWithLabelPrefersRegisteredValueWithThatLabel() { + sut.put(INT, null, Tuple.of(3, 2, 3)); + sut.put(INT, "label", Tuple.of(4, 3, 4)); + assertEquals(Tuple.of(4, 3, 4), sut.provide(INT, Attributes.labeled("label")).get()); + } + + @Test + public void anUnregisteredValueCanNotBeFound() { + assertEquals(Optional.empty(), sut.provide(INT, Attributes.unlabeled())); + } +} From 6c836e6f76d54484d2cc355590348902bb43200b Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Tue, 26 Nov 2024 21:28:06 +0100 Subject: [PATCH 13/18] Simplifies ClassAccessor --- .../reflection/vintage/ClassAccessor.java | 50 +++---------------- .../factories/FallbackFactory.java | 2 +- .../reflection/vintage/ClassAccessorTest.java | 44 ++++------------ 3 files changed, 19 insertions(+), 77 deletions(-) diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessor.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessor.java index 45a49d695..c13a5c89f 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessor.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessor.java @@ -19,28 +19,17 @@ public class ClassAccessor { private final VintageValueProvider valueProvider; private final Objenesis objenesis; - /** Private constructor. Call {@link #of(Class, PrefabValues)} instead. */ - ClassAccessor(Class type, VintageValueProvider valueProvider, Objenesis objenesis) { - this.type = type; - this.valueProvider = valueProvider; - this.objenesis = objenesis; - } - /** - * Factory method. + * Constructor. * - * @param The class on which {@link ClassAccessor} operates. * @param type The class on which {@link ClassAccessor} operates. Should be the same as T. * @param valueProvider Prefabricated values with which to fill instantiated objects. * @param objenesis To instantiate non-record classes. - * @return A {@link ClassAccessor} for T. */ - public static ClassAccessor of( - Class type, - VintageValueProvider valueProvider, - Objenesis objenesis - ) { - return new ClassAccessor<>(type, valueProvider, objenesis); + public ClassAccessor(Class type, VintageValueProvider valueProvider, Objenesis objenesis) { + this.type = type; + this.valueProvider = valueProvider; + this.objenesis = objenesis; } /** @@ -53,19 +42,7 @@ public static ClassAccessor of( * @return An instance of T. */ public T getRedObject(TypeTag enclosingType, Attributes attributes) { - return getRedAccessor(enclosingType, attributes).get(); - } - - /** - * Returns an {@link ObjectAccessor} for {@link #getRedObject(TypeTag, Attributes)}. - * - * @param enclosingType Describes the type that contains this object as a field, to determine - * any generic parameters it may contain. - * @param attributes Provides metadata needed to provide a value and to keep track of recursion. - * @return An {@link ObjectAccessor} for {@link #getRedObject}. - */ - public ObjectAccessor getRedAccessor(TypeTag enclosingType, Attributes attributes) { - return buildObjectAccessor().scramble(valueProvider, enclosingType, attributes); + return buildObjectAccessor().scramble(valueProvider, enclosingType, attributes).get(); } /** @@ -78,21 +55,10 @@ public ObjectAccessor getRedAccessor(TypeTag enclosingType, Attributes attrib * @return An instance of T. */ public T getBlueObject(TypeTag enclosingType, Attributes attributes) { - return getBlueAccessor(enclosingType, attributes).get(); - } - - /** - * Returns an {@link ObjectAccessor} for {@link #getBlueObject(TypeTag, Attributes)}. - * - * @param enclosingType Describes the type that contains this object as a field, to determine - * any generic parameters it may contain. - * @param attributes Provides metadata needed to provide a value and to keep track of recursion. - * @return An {@link ObjectAccessor} for {@link #getBlueObject(TypeTag, Attributes)}. - */ - public ObjectAccessor getBlueAccessor(TypeTag enclosingType, Attributes attributes) { return buildObjectAccessor() .scramble(valueProvider, enclosingType, attributes) - .scramble(valueProvider, enclosingType, attributes); + .scramble(valueProvider, enclosingType, attributes) + .get(); } private ObjectAccessor buildObjectAccessor() { 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..1eb12b579 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 @@ -82,7 +82,7 @@ private Tuple giveInstances( VintageValueProvider valueProvider, Attributes attributes ) { - ClassAccessor accessor = ClassAccessor.of(tag.getType(), valueProvider, objenesis); + ClassAccessor accessor = new ClassAccessor<>(tag.getType(), valueProvider, objenesis); T red = accessor.getRedObject(tag, attributes); T blue = accessor.getBlueObject(tag, attributes); diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessorTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessorTest.java index ab5c63656..252bf69ca 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessorTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessorTest.java @@ -37,7 +37,8 @@ public void setup() { factoryCache = JavaApiPrefabValues.build(); valueProvider = new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); - pointContainerAccessor = ClassAccessor.of(PointContainer.class, valueProvider, objenesis); + pointContainerAccessor = + new ClassAccessor<>(PointContainer.class, valueProvider, objenesis); } @Test @@ -48,7 +49,7 @@ public void getRedObject() { @Test @SuppressWarnings("rawtypes") public void getRedObjectGeneric() { - ClassAccessor accessor = ClassAccessor.of( + ClassAccessor accessor = new ClassAccessor<>( GenericTypeVariableListContainer.class, valueProvider, objenesis @@ -60,16 +61,6 @@ public void getRedObjectGeneric() { assertEquals(String.class, foo.tList.get(0).getClass()); } - @Test - public void getRedAccessor() { - PointContainer foo = pointContainerAccessor.getRedObject(TypeTag.NULL, empty); - ObjectAccessor objectAccessor = pointContainerAccessor.getRedAccessor( - TypeTag.NULL, - empty - ); - assertEquals(foo, objectAccessor.get()); - } - @Test public void getBlueObject() { assertObjectHasNoNullFields(pointContainerAccessor.getBlueObject(TypeTag.NULL, empty)); @@ -78,7 +69,7 @@ public void getBlueObject() { @Test @SuppressWarnings("rawtypes") public void getBlueObjectGeneric() { - ClassAccessor accessor = ClassAccessor.of( + ClassAccessor accessor = new ClassAccessor<>( GenericTypeVariableListContainer.class, valueProvider, objenesis @@ -90,16 +81,6 @@ public void getBlueObjectGeneric() { assertEquals(String.class, foo.tList.get(0).getClass()); } - @Test - public void getBlueAccessor() { - PointContainer foo = pointContainerAccessor.getBlueObject(TypeTag.NULL, empty); - ObjectAccessor objectAccessor = pointContainerAccessor.getBlueAccessor( - TypeTag.NULL, - empty - ); - assertEquals(foo, objectAccessor.get()); - } - @Test public void redAndBlueNotEqual() { PointContainer red = pointContainerAccessor.getRedObject(TypeTag.NULL, empty); @@ -109,15 +90,13 @@ public void redAndBlueNotEqual() { @Test public void instantiateAllTypes() { - ClassAccessor - .of(AllTypesContainer.class, valueProvider, objenesis) + new ClassAccessor<>(AllTypesContainer.class, valueProvider, objenesis) .getRedObject(TypeTag.NULL, empty); } @Test public void instantiateArrayTypes() { - ClassAccessor - .of(AllArrayTypesContainer.class, valueProvider, objenesis) + new ClassAccessor<>(AllArrayTypesContainer.class, valueProvider, objenesis) .getRedObject(TypeTag.NULL, empty); } @@ -129,28 +108,25 @@ public void instantiateRecursiveTypeUsingPrefabValue() { ); valueProvider = new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); - ClassAccessor - .of(TwoStepNodeA.class, valueProvider, objenesis) + new ClassAccessor<>(TwoStepNodeA.class, valueProvider, objenesis) .getRedObject(TypeTag.NULL, empty); } @Test public void instantiateInterfaceField() { - ClassAccessor - .of(InterfaceContainer.class, valueProvider, objenesis) + new ClassAccessor<>(InterfaceContainer.class, valueProvider, objenesis) .getRedObject(TypeTag.NULL, empty); } @Test public void instantiateAbstractClassField() { - ClassAccessor - .of(AbstractClassContainer.class, valueProvider, objenesis) + new ClassAccessor<>(AbstractClassContainer.class, valueProvider, objenesis) .getRedObject(TypeTag.NULL, empty); } @Test public void anInvalidTypeShouldNotThrowAnExceptionUponCreation() { - ClassAccessor.of(null, valueProvider, objenesis); + new ClassAccessor<>(null, valueProvider, objenesis); } private void assertObjectHasNoNullFields(PointContainer foo) { From 9513ed225977ab37a932dd95ee7e8c978b767922 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Tue, 26 Nov 2024 21:48:52 +0100 Subject: [PATCH 14/18] Re-organizes vintage packages --- .../vintage/RecordFallbackFactoryTest.java | 1 - .../RecordObjectAccessorCopyingTest.java | 2 +- .../RecordObjectAccessorScramblingTest.java | 5 +-- .../RecordObjectAccessorTest.java | 4 +-- .../SealedTypesFallbackFactoryTest.java | 1 - .../ConfiguredEqualsVerifier.java | 2 +- .../api/SingleTypeEqualsVerifierApi.java | 1 + .../reflection/JavaApiPrefabValues.java | 20 ++++++------ .../reflection/vintage/FactoryCache.java | 1 - .../vintage}/PrefabValuesApi.java | 6 ++-- .../VintageValueProvider.java | 8 +++-- .../vintage/{ => mutation}/ClassAccessor.java | 4 +-- .../vintage/{ => mutation}/FieldModifier.java | 4 +-- .../{ => mutation}/InPlaceObjectAccessor.java | 4 +-- .../{ => mutation}/ObjectAccessor.java | 4 +-- .../{ => mutation}/RecordObjectAccessor.java | 4 +-- .../factories/AbstractGenericFactory.java | 2 +- .../prefabvalues/factories/CopyFactory.java | 2 +- .../factories/EnumMapFactory.java | 2 +- .../factories/EnumSetFactory.java | 2 +- .../factories/ExternalFactory.java | 2 +- .../factories/FallbackFactory.java | 4 +-- .../prefabvalues/factories/MapFactory.java | 2 +- .../factories/PrefabValueFactory.java | 2 +- .../prefabvalues/factories/SimpleFactory.java | 2 +- .../factories/SimpleGenericFactory.java | 2 +- .../GuavaFactoryProvider.java | 7 ++--- .../JavaFxFactoryProvider.java | 10 ++++-- .../internal/util/DefaultValueProviders.java | 5 ++- .../architecture/ArchitectureTest.java | 31 ++++++------------- .../vintage}/PrefabValuesApiTest.java | 2 +- .../VintageValueProviderCreatorTest.java | 6 ++-- .../VintageValueProviderTest.java | 4 +-- .../{ => mutation}/ClassAccessorTest.java | 5 +-- .../{ => mutation}/FactoryCacheFactory.java | 4 ++- .../{ => mutation}/FieldModifierTest.java | 2 +- .../InPlaceObjectAccessorCopyingTest.java | 2 +- .../InPlaceObjectAccessorScramblingTest.java | 5 +-- .../InPlaceObjectAccessorTest.java | 2 +- .../factories/AbstractGenericFactoryTest.java | 2 +- .../factories/FallbackFactoryTest.java | 2 +- .../factories/MapFactoryTest.java | 2 +- .../factories/SimpleGenericFactoryTest.java | 2 +- .../JavaFxFactoryProviderTest.java | 2 +- .../jar/helper/JarAsserter.java | 2 +- 45 files changed, 92 insertions(+), 98 deletions(-) rename equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/{ => mutation}/RecordObjectAccessorCopyingTest.java (96%) rename equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/{ => mutation}/RecordObjectAccessorScramblingTest.java (92%) rename equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/{ => mutation}/RecordObjectAccessorTest.java (96%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{util => reflection/vintage}/PrefabValuesApi.java (95%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/{instantiation => vintage}/VintageValueProvider.java (96%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/{ => mutation}/ClassAccessor.java (94%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/{ => mutation}/FieldModifier.java (96%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/{ => mutation}/InPlaceObjectAccessor.java (91%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/{ => mutation}/ObjectAccessor.java (95%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/{ => mutation}/RecordObjectAccessor.java (93%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/{util => reflection/vintage}/PrefabValuesApiTest.java (82%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/{instantiation => vintage}/VintageValueProviderCreatorTest.java (96%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/{instantiation => vintage}/VintageValueProviderTest.java (98%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/{ => mutation}/ClassAccessorTest.java (95%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/{ => mutation}/FactoryCacheFactory.java (85%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/{ => mutation}/FieldModifierTest.java (95%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/{ => mutation}/InPlaceObjectAccessorCopyingTest.java (97%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/{ => mutation}/InPlaceObjectAccessorScramblingTest.java (96%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/{ => mutation}/InPlaceObjectAccessorTest.java (92%) diff --git a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordFallbackFactoryTest.java b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordFallbackFactoryTest.java index f9971891f..5c2a62dea 100644 --- a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordFallbackFactoryTest.java +++ b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordFallbackFactoryTest.java @@ -8,7 +8,6 @@ import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.FallbackFactory; import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; import org.junit.jupiter.api.BeforeEach; diff --git a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorCopyingTest.java b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/RecordObjectAccessorCopyingTest.java similarity index 96% rename from equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorCopyingTest.java rename to equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/RecordObjectAccessorCopyingTest.java index 25c904414..cbcc3c17a 100644 --- a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorCopyingTest.java +++ b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/RecordObjectAccessorCopyingTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotSame; diff --git a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorScramblingTest.java b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/RecordObjectAccessorScramblingTest.java similarity index 92% rename from equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorScramblingTest.java rename to equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/RecordObjectAccessorScramblingTest.java index a39f867db..7c9a42732 100644 --- a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorScramblingTest.java +++ b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/RecordObjectAccessorScramblingTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -9,7 +9,8 @@ import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorTest.java b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/RecordObjectAccessorTest.java similarity index 96% rename from equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorTest.java rename to equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/RecordObjectAccessorTest.java index 8975d574f..83a5d6333 100644 --- a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorTest.java +++ b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/RecordObjectAccessorTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -11,7 +11,7 @@ import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; import org.junit.jupiter.api.BeforeEach; diff --git a/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/SealedTypesFallbackFactoryTest.java b/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/SealedTypesFallbackFactoryTest.java index 5d2237503..afc7eb192 100644 --- a/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/SealedTypesFallbackFactoryTest.java +++ b/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/SealedTypesFallbackFactoryTest.java @@ -9,7 +9,6 @@ import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.FallbackFactory; import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; import org.junit.jupiter.api.BeforeEach; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/ConfiguredEqualsVerifier.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/ConfiguredEqualsVerifier.java index 687f6c78a..8e9aa2e57 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/ConfiguredEqualsVerifier.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/ConfiguredEqualsVerifier.java @@ -11,8 +11,8 @@ import nl.jqno.equalsverifier.api.SingleTypeEqualsVerifierApi; import nl.jqno.equalsverifier.internal.reflection.PackageScanner; import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.reflection.vintage.PrefabValuesApi; import nl.jqno.equalsverifier.internal.util.ListBuilders; -import nl.jqno.equalsverifier.internal.util.PrefabValuesApi; import nl.jqno.equalsverifier.internal.util.Validations; import org.objenesis.Objenesis; import org.objenesis.ObjenesisStd; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/SingleTypeEqualsVerifierApi.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/SingleTypeEqualsVerifierApi.java index 9d99721be..a401fc832 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/SingleTypeEqualsVerifierApi.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/SingleTypeEqualsVerifierApi.java @@ -11,6 +11,7 @@ import nl.jqno.equalsverifier.internal.checkers.*; import nl.jqno.equalsverifier.internal.exceptions.MessagingException; import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.reflection.vintage.PrefabValuesApi; import nl.jqno.equalsverifier.internal.util.*; import nl.jqno.equalsverifier.internal.util.Formatter; import org.objenesis.Objenesis; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/JavaApiPrefabValues.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/JavaApiPrefabValues.java index cadf7fcd3..1fe54c94d 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/JavaApiPrefabValues.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/JavaApiPrefabValues.java @@ -9,17 +9,18 @@ import java.beans.PropertyChangeSupport; import java.io.File; import java.io.PrintStream; -import java.lang.reflect.*; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.math.BigDecimal; import java.math.BigInteger; -import java.net.*; +import java.net.InetSocketAddress; +import java.net.URI; +import java.net.URL; import java.nio.*; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.text.DateFormat; -import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.text.SimpleDateFormat; +import java.text.*; import java.time.*; import java.time.format.DateTimeFormatter; import java.util.*; @@ -28,12 +29,9 @@ import java.util.concurrent.locks.StampedLock; import java.util.function.Supplier; import java.util.regex.Pattern; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.EnumMapFactory; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.EnumSetFactory; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.ExternalFactory; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.*; /** * Creates instances of classes for use in a {@link VintageValueProvider} object. diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCache.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCache.java index 528867fef..9dc7a52ef 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCache.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCache.java @@ -3,7 +3,6 @@ import java.util.HashMap; import java.util.Map; import java.util.Objects; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; /** Contains a cache of factories, for {@link VintageValueProvider}. */ diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/PrefabValuesApi.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/PrefabValuesApi.java similarity index 95% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/PrefabValuesApi.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/PrefabValuesApi.java index 529ec513c..0b1a86954 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/PrefabValuesApi.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/PrefabValuesApi.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.util; +package nl.jqno.equalsverifier.internal.reflection.vintage; import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.simple; import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; @@ -7,9 +7,9 @@ import nl.jqno.equalsverifier.Func.Func1; import nl.jqno.equalsverifier.Func.Func2; import nl.jqno.equalsverifier.internal.reflection.SuperclassIterable; -import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; -import nl.jqno.equalsverifier.internal.reflection.vintage.ObjectAccessor; +import nl.jqno.equalsverifier.internal.reflection.vintage.mutation.ObjectAccessor; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; +import nl.jqno.equalsverifier.internal.util.Validations; import org.objenesis.Objenesis; public final class PrefabValuesApi { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/VintageValueProvider.java similarity index 96% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/VintageValueProvider.java index 8a8edf9bd..c3e6ef616 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/VintageValueProvider.java @@ -1,12 +1,14 @@ -package nl.jqno.equalsverifier.internal.reflection.instantiation; +package nl.jqno.equalsverifier.internal.reflection.vintage; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import java.util.*; +import java.util.Arrays; +import java.util.Optional; import nl.jqno.equalsverifier.internal.exceptions.RecursionException; import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.FallbackFactory; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; import nl.jqno.equalsverifier.internal.util.PrimitiveMappers; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessor.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/ClassAccessor.java similarity index 94% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessor.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/ClassAccessor.java index c13a5c89f..bc4757e96 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessor.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/ClassAccessor.java @@ -1,9 +1,9 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; import nl.jqno.equalsverifier.internal.reflection.Instantiator; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; import org.objenesis.Objenesis; /** diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/FieldModifier.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/FieldModifier.java similarity index 96% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/FieldModifier.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/FieldModifier.java index 995e9bbbf..fd5725b16 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/FieldModifier.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/FieldModifier.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; import static nl.jqno.equalsverifier.internal.util.Rethrow.rethrow; @@ -7,7 +7,7 @@ import nl.jqno.equalsverifier.internal.reflection.FieldProbe; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; public final class FieldModifier { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessor.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/InPlaceObjectAccessor.java similarity index 91% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessor.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/InPlaceObjectAccessor.java index f48130627..89943838f 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessor.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/InPlaceObjectAccessor.java @@ -1,11 +1,11 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; import java.lang.reflect.Field; import nl.jqno.equalsverifier.internal.reflection.FieldIterable; import nl.jqno.equalsverifier.internal.reflection.Instantiator; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; import org.objenesis.Objenesis; /** diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ObjectAccessor.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/ObjectAccessor.java similarity index 95% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ObjectAccessor.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/ObjectAccessor.java index 329980e52..7cdd484cb 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ObjectAccessor.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/ObjectAccessor.java @@ -1,9 +1,9 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; import nl.jqno.equalsverifier.internal.reflection.RecordsHelper; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; import org.objenesis.Objenesis; /** diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessor.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/RecordObjectAccessor.java similarity index 93% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessor.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/RecordObjectAccessor.java index 8c45295aa..98a80dd49 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessor.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/RecordObjectAccessor.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; import java.lang.reflect.Field; import java.util.List; @@ -8,7 +8,7 @@ import nl.jqno.equalsverifier.internal.reflection.RecordProbe; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; import org.objenesis.Objenesis; /** diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactory.java index 7cac47f5d..7587ac03d 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactory.java @@ -8,7 +8,7 @@ import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; /** * Abstract implementation of {@link PrefabValueFactory} that provides helper functions for dealing 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..5b8f782c1 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 @@ -4,7 +4,7 @@ import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; public class CopyFactory extends AbstractGenericFactory { 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..abbf32cac 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 @@ -6,7 +6,7 @@ import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; @SuppressWarnings({ "unchecked", "rawtypes" }) public final class EnumMapFactory extends AbstractGenericFactory { 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..f6dae8634 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 @@ -6,7 +6,7 @@ import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; /** * Implementation of {@link PrefabValueFactory} that instantiates EnumSets using reflection, while diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/ExternalFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/ExternalFactory.java index da625da89..d777d7a64 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/ExternalFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/ExternalFactory.java @@ -7,8 +7,8 @@ import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factoryproviders.FactoryProvider; public class ExternalFactory implements PrefabValueFactory { 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 1eb12b579..917f7eb88 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 @@ -6,8 +6,8 @@ import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.InstanceCreator; 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; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.mutation.ClassAccessor; import org.objenesis.Objenesis; /** 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..40030f4de 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 @@ -5,7 +5,7 @@ import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; /** * Implementation of {@link PrefabValueFactory} that specializes in creating implementations of diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/PrefabValueFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/PrefabValueFactory.java index 172bebbe9..e7c2c3c13 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/PrefabValueFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/PrefabValueFactory.java @@ -3,7 +3,7 @@ import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; /** * Creates instances of generic types for use as prefab value. diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleFactory.java index 8e54df590..3012b2cf5 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleFactory.java @@ -3,7 +3,7 @@ import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; /** * Implementation of {@link PrefabValueFactory} that holds on to two instances that have already 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..558a8465b 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 @@ -7,7 +7,7 @@ import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; public class SimpleGenericFactory extends AbstractGenericFactory { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/GuavaFactoryProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/GuavaFactoryProvider.java index e20df0d9b..e9860bd40 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/GuavaFactoryProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/GuavaFactoryProvider.java @@ -9,12 +9,9 @@ import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.AbstractGenericFactory; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.EnumMapFactory; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.EnumSetFactory; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.*; public final class GuavaFactoryProvider implements FactoryProvider { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProvider.java index 0ab9862b2..f601fa8cb 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProvider.java @@ -5,12 +5,16 @@ import static nl.jqno.equalsverifier.internal.reflection.Util.objects; import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.copy; -import java.util.*; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.function.Function; -import nl.jqno.equalsverifier.internal.reflection.*; +import nl.jqno.equalsverifier.internal.reflection.ConditionalInstantiator; +import nl.jqno.equalsverifier.internal.reflection.Tuple; +import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.AbstractGenericFactory; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/DefaultValueProviders.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/DefaultValueProviders.java index 7c85be7fe..664cd03b6 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/DefaultValueProviders.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/DefaultValueProviders.java @@ -1,7 +1,10 @@ package nl.jqno.equalsverifier.internal.util; -import nl.jqno.equalsverifier.internal.reflection.instantiation.*; +import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ChainedValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; import org.objenesis.Objenesis; public final class DefaultValueProviders { diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/architecture/ArchitectureTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/architecture/ArchitectureTest.java index f8f889290..8614a5eb5 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/architecture/ArchitectureTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/architecture/ArchitectureTest.java @@ -5,15 +5,9 @@ import com.tngtech.archunit.junit.AnalyzeClasses; import com.tngtech.archunit.junit.ArchTest; import com.tngtech.archunit.lang.ArchRule; -import nl.jqno.equalsverifier.ConfiguredEqualsVerifier; -import nl.jqno.equalsverifier.api.SingleTypeEqualsVerifierApi; -import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProviderCreatorTest; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProviderTest; -import nl.jqno.equalsverifier.internal.reflection.vintage.*; -import nl.jqno.equalsverifier.internal.util.Context; -import nl.jqno.equalsverifier.internal.util.PrefabValuesApi; +import nl.jqno.equalsverifier.internal.reflection.vintage.mutation.ClassAccessor; +import nl.jqno.equalsverifier.internal.reflection.vintage.mutation.FieldModifier; +import nl.jqno.equalsverifier.internal.reflection.vintage.mutation.ObjectAccessor; @AnalyzeClasses(packages = "nl.jqno.equalsverifier") public final class ArchitectureTest { @@ -21,22 +15,15 @@ public final class ArchitectureTest { @ArchTest public static final ArchRule ONLY_VINTAGE_INSTANTIATORS_CAN_USE_VINTAGE_REFLECTION = noClasses() .that() - .doNotBelongToAnyOf( - VintageValueProvider.class, - Context.class, - PrefabValuesApi.class, - JavaApiPrefabValues.class, - ConfiguredEqualsVerifier.class, - SingleTypeEqualsVerifierApi.class, - // 👇 Test classes - VintageValueProviderTest.class, - VintageValueProviderCreatorTest.class - ) - .and() .resideOutsideOfPackage("nl.jqno.equalsverifier.internal.reflection.vintage..") .should() .accessClassesThat() - .resideInAPackage("nl.jqno.equalsverifier.internal.reflection.vintage.."); + .resideInAPackage("nl.jqno.equalsverifier.internal.reflection.vintage.mutation..") + .orShould() + .accessClassesThat() + .resideInAPackage( + "nl.jqno.equalsverifier.internal.reflection.vintage.mutation.prefabvalues.." + ); @ArchTest public static final ArchRule DONT_USE_VINTAGE_REFLECTION_DIRECTLY = noClasses() diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/util/PrefabValuesApiTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/PrefabValuesApiTest.java similarity index 82% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/util/PrefabValuesApiTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/PrefabValuesApiTest.java index cae0f474d..b8c43352c 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/util/PrefabValuesApiTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/PrefabValuesApiTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.util; +package nl.jqno.equalsverifier.internal.reflection.vintage; import static nl.jqno.equalsverifier.internal.testhelpers.Util.coverThePrivateConstructor; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderCreatorTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/VintageValueProviderCreatorTest.java similarity index 96% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderCreatorTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/VintageValueProviderCreatorTest.java index fd76c8c7c..2a6808a9a 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderCreatorTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/VintageValueProviderCreatorTest.java @@ -1,12 +1,12 @@ -package nl.jqno.equalsverifier.internal.reflection.instantiation; +package nl.jqno.equalsverifier.internal.reflection.vintage; import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; import static org.junit.jupiter.api.Assertions.*; import nl.jqno.equalsverifier.internal.exceptions.RecursionException; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; -import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCacheFactory; +import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.mutation.FactoryCacheFactory; import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; import nl.jqno.equalsverifier.testhelpers.types.Point; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/VintageValueProviderTest.java similarity index 98% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/VintageValueProviderTest.java index 1ba7896e3..dab6fa67e 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/VintageValueProviderTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.instantiation; +package nl.jqno.equalsverifier.internal.reflection.vintage; import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; import static nl.jqno.equalsverifier.internal.testhelpers.Util.defaultEquals; @@ -11,8 +11,8 @@ import java.util.List; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; import nl.jqno.equalsverifier.testhelpers.types.Point; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessorTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/ClassAccessorTest.java similarity index 95% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessorTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/ClassAccessorTest.java index 252bf69ca..17cb4b1e0 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessorTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/ClassAccessorTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -9,7 +9,8 @@ import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; import nl.jqno.equalsverifier.testhelpers.types.PointContainer; import nl.jqno.equalsverifier.testhelpers.types.RecursiveTypeHelper.TwoStepNodeA; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCacheFactory.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/FactoryCacheFactory.java similarity index 85% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCacheFactory.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/FactoryCacheFactory.java index be7c8020f..9a07e1245 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCacheFactory.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/FactoryCacheFactory.java @@ -1,7 +1,9 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; +import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; + public final class FactoryCacheFactory { private FactoryCacheFactory() {} diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/FieldModifierTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/FieldModifierTest.java similarity index 95% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/FieldModifierTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/FieldModifierTest.java index e0b2562b2..060709d09 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/FieldModifierTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/FieldModifierTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertSame; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorCopyingTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/InPlaceObjectAccessorCopyingTest.java similarity index 97% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorCopyingTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/InPlaceObjectAccessorCopyingTest.java index a224280df..71fa1f1aa 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorCopyingTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/InPlaceObjectAccessorCopyingTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotSame; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorScramblingTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/InPlaceObjectAccessorScramblingTest.java similarity index 96% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorScramblingTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/InPlaceObjectAccessorScramblingTest.java index 0f997ed47..f6e6aca62 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorScramblingTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/InPlaceObjectAccessorScramblingTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; import static org.junit.jupiter.api.Assertions.*; @@ -11,7 +11,8 @@ import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; import nl.jqno.equalsverifier.testhelpers.types.Point; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/InPlaceObjectAccessorTest.java similarity index 92% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/InPlaceObjectAccessorTest.java index 85152215a..b44d77d52 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/InPlaceObjectAccessorTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactoryTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactoryTest.java index f480f042a..b35ebc104 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactoryTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactoryTest.java @@ -8,7 +8,7 @@ import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java index 60593ad52..074f279ee 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java @@ -12,8 +12,8 @@ import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; import nl.jqno.equalsverifier.testhelpers.types.RecursiveTypeHelper.Node; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactoryTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactoryTest.java index 677a949bb..664462bcf 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactoryTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactoryTest.java @@ -9,7 +9,7 @@ import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; import nl.jqno.equalsverifier.testhelpers.types.TypeHelper.OneElementEnum; import org.junit.jupiter.api.BeforeEach; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactoryTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactoryTest.java index fe9af463e..1065d71e2 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactoryTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactoryTest.java @@ -8,7 +8,7 @@ import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; import nl.jqno.equalsverifier.testhelpers.types.Pair; import org.junit.jupiter.api.BeforeEach; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProviderTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProviderTest.java index b91a6265c..f782fae61 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProviderTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProviderTest.java @@ -10,7 +10,7 @@ import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factoryproviders.JavaFxFactoryProvider.PropertyFactory; import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; diff --git a/equalsverifier-release-verify/src/test/java/nl/jqno/equalsverifier/verify_release/jar/helper/JarAsserter.java b/equalsverifier-release-verify/src/test/java/nl/jqno/equalsverifier/verify_release/jar/helper/JarAsserter.java index 2da2a26f3..be86ac31b 100644 --- a/equalsverifier-release-verify/src/test/java/nl/jqno/equalsverifier/verify_release/jar/helper/JarAsserter.java +++ b/equalsverifier-release-verify/src/test/java/nl/jqno/equalsverifier/verify_release/jar/helper/JarAsserter.java @@ -23,7 +23,7 @@ public JarAsserter(JarReader reader) { public void assertPresenceOfCoreClasses() { assertPresenceOf( EV + "/EqualsVerifier.class", - EV + "/internal/reflection/vintage/ClassAccessor.class", + EV + "/internal/reflection/vintage/mutation/ClassAccessor.class", EV + "/internal/checkers/HierarchyChecker.class" ); } From bd52b93f4a6d2e1ad9f0b180cfe3248453dae2cb Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Tue, 26 Nov 2024 21:49:38 +0100 Subject: [PATCH 15/18] Fixes name --- .../{ClassAccessorSealedTest.java => ClassProbeSealedTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/{ClassAccessorSealedTest.java => ClassProbeSealedTest.java} (94%) diff --git a/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/ClassAccessorSealedTest.java b/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/ClassProbeSealedTest.java similarity index 94% rename from equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/ClassAccessorSealedTest.java rename to equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/ClassProbeSealedTest.java index 2b7ad0633..f9539c7a5 100644 --- a/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/ClassAccessorSealedTest.java +++ b/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/ClassProbeSealedTest.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test; -public class ClassAccessorSealedTest { +public class ClassProbeSealedTest { @Test public void isNotSealed() { From 6a81d7f78d1d1c544824b0a24402f99a6131a2cb Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Thu, 28 Nov 2024 15:50:50 +0100 Subject: [PATCH 16/18] Fixes PITest mutants --- .../instantiation/CachedValueProvider.java | 14 +------------- .../internal/reflection/vintage/FactoryCache.java | 2 +- .../instantiation/CachedValueProviderTest.java | 10 ++++++++++ .../reflection/vintage/FactoryCacheTest.java | 7 +++++++ 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProvider.java index 40015c14a..e564ecb99 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProvider.java @@ -22,18 +22,6 @@ public void put(TypeTag tag, String label, Tuple tuple) { cache.put(Key.of(tag, label), tuple); } - /** - * Checks if a value is already present in the cache. - * - * @param tag The type for which we want to see if a value is present. - * @param label The label that the value should be linked to. - * @return Whether a value for the given tag and label is present in the cache. - */ - public boolean contains(TypeTag tag, String label) { - Key key = Key.of(tag, label); - return cache.containsKey(key); - } - /** * {@inheritDoc}} */ @@ -51,7 +39,7 @@ public Optional> provide(TypeTag tag, Attributes attributes) { return Optional.empty(); } - private static final class Key { + static final class Key { final TypeTag tag; final String label; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCache.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCache.java index 9dc7a52ef..61ea3e55b 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCache.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCache.java @@ -140,7 +140,7 @@ private void addAll(FactoryCache to, FactoryCache from) { } } - private static final class Key { + static final class Key { final String typeName; final String label; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProviderTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProviderTest.java index c3b4f7a3c..db4c5d5c9 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProviderTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProviderTest.java @@ -3,8 +3,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Optional; +import nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider.Key; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import org.junit.jupiter.api.Test; @@ -49,4 +51,12 @@ public void aQueryWithLabelPrefersRegisteredValueWithThatLabel() { public void anUnregisteredValueCanNotBeFound() { assertEquals(Optional.empty(), sut.provide(INT, Attributes.unlabeled())); } + + @Test + public void key() { + EqualsVerifier + .forClass(Key.class) + .withPrefabValues(TypeTag.class, new TypeTag(String.class), new TypeTag(Integer.class)) + .verify(); + } } diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCacheTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCacheTest.java index 66a17eff3..614d06fdd 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCacheTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCacheTest.java @@ -2,6 +2,8 @@ import static org.junit.jupiter.api.Assertions.*; +import nl.jqno.equalsverifier.EqualsVerifier; +import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache.Key; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.SimpleFactory; import org.junit.jupiter.api.Test; @@ -122,4 +124,9 @@ public void merge() { assertFalse(a.contains(INT_CLASS)); assertFalse(b.contains(STRING_CLASS)); } + + @Test + public void key() { + EqualsVerifier.forClass(Key.class).verify(); + } } From fbbff9c080f3de393b7d4affe5c0c2221d943008 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Thu, 28 Nov 2024 16:30:52 +0100 Subject: [PATCH 17/18] Adds test where elements from 2 generic types are cast to their type --- .../extended_contract/GenericTypesTest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java index 554c4ab08..43bddc2f6 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java @@ -90,6 +90,11 @@ public void succeed_whenToStringLooksAtNonCollectionGenericContent() { EqualsVerifier.forClass(SparseArrayToStringContainer.class).verify(); } + @Test + public void succeed_whenEqualsLooksAtGenericContent_givenTwoGenericFields() { + EqualsVerifier.forClass(TwoGenericsContainerWithIntrospection.class).verify(); + } + @Test public void succeed_whenClassHasTypeVariableThatExtendsSomething() { EqualsVerifier.forClass(TypeVariableExtendsContainer.class).verify(); @@ -745,6 +750,38 @@ public String toString() { } } + public static final class TwoGenericsContainerWithIntrospection { + + private final List stringList = new ArrayList<>(); + private final List intList = new ArrayList<>(); + + @SuppressWarnings("unused") + @Override + public boolean equals(Object obj) { + if (stringList != null && stringList.size() > 0) { + String key = stringList.get(0); // force a cast + } + if (intList != null && intList.size() > 0) { + Integer key = intList.get(0); // force a cast + } + + if (!(obj instanceof TwoGenericsContainerWithIntrospection)) { + return false; + } + TwoGenericsContainerWithIntrospection other = + (TwoGenericsContainerWithIntrospection) obj; + return ( + Objects.equals(stringList, other.stringList) && + Objects.equals(intList, other.intList) + ); + } + + @Override + public int hashCode() { + return Objects.hash(stringList, intList); + } + } + @SuppressWarnings("unused") static final class TypeVariableExtendsContainer> { From 486c14464f1e64d6dcd5270e1d076b7547c49588 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Fri, 29 Nov 2024 15:19:40 +0100 Subject: [PATCH 18/18] Removes unused helper code --- .../testhelpers/TestValueProviders.java | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/TestValueProviders.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/TestValueProviders.java index 915790688..3e971ef63 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/TestValueProviders.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/TestValueProviders.java @@ -1,20 +1,12 @@ package nl.jqno.equalsverifier.internal.testhelpers; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.Optional; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; -@SuppressFBWarnings( - value = "DM_STRING_CTOR", - justification = "We really do need a separate instances with the same value" -) public final class TestValueProviders { - public static final Tuple INTS = Tuple.of(42, 1337, 42); - public static final Tuple STRINGS = Tuple.of("abc", "xyz", new String("abc")); - private TestValueProviders() {} public static ValueProvider empty() { @@ -25,23 +17,4 @@ public Optional> provide(TypeTag tag, Attributes attributes) { } }; } - - public static ValueProvider simple() { - return new ValueProvider() { - @SuppressWarnings("unchecked") - @Override - public Optional> provide(TypeTag tag, Attributes attributes) { - if (tag.getType().equals(int.class)) { - return Optional.of((Tuple) INTS); - } - if (tag.getType().equals(Integer.class)) { - return Optional.of((Tuple) INTS); - } - if (tag.getType().equals(String.class)) { - return Optional.of((Tuple) STRINGS); - } - return Optional.empty(); - } - }; - } }