Skip to content

Commit

Permalink
Replaces GenericPrefabValueProvider with FactoryCache
Browse files Browse the repository at this point in the history
  • Loading branch information
jqno committed Nov 17, 2024
1 parent 1d0838a commit b3755a9
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 339 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import nl.jqno.equalsverifier.api.MultipleTypeEqualsVerifierApi;
import nl.jqno.equalsverifier.api.SingleTypeEqualsVerifierApi;
import nl.jqno.equalsverifier.internal.reflection.PackageScanner;
import nl.jqno.equalsverifier.internal.reflection.instantiation.GenericPrefabValueProvider.GenericFactories;
import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache;
import nl.jqno.equalsverifier.internal.util.ListBuilders;
import nl.jqno.equalsverifier.internal.util.PrefabValuesApi;
Expand All @@ -22,33 +21,24 @@ public final class ConfiguredEqualsVerifier implements EqualsVerifierApi<Void> {

private final EnumSet<Warning> warningsToSuppress;
private final FactoryCache factoryCache;
private final GenericFactories genericFactories;
private boolean usingGetClass;
private Function<String, String> fieldnameToGetter;
private final Objenesis objenesis = new ObjenesisStd();

/** Constructor. */
public ConfiguredEqualsVerifier() {
this(
EnumSet.noneOf(Warning.class),
new FactoryCache(),
new GenericFactories(),
false,
null
);
this(EnumSet.noneOf(Warning.class), new FactoryCache(), false, null);
}

/** Private constructor. For internal use only. */
private ConfiguredEqualsVerifier(
EnumSet<Warning> warningsToSuppress,
FactoryCache factoryCache,
GenericFactories genericFactories,
boolean usingGetClass,
Function<String, String> fieldnameToGetter
) {
this.warningsToSuppress = warningsToSuppress;
this.factoryCache = factoryCache;
this.genericFactories = genericFactories;
this.usingGetClass = usingGetClass;
this.fieldnameToGetter = fieldnameToGetter;
}
Expand All @@ -62,7 +52,6 @@ public ConfiguredEqualsVerifier copy() {
return new ConfiguredEqualsVerifier(
EnumSet.copyOf(warningsToSuppress),
new FactoryCache().merge(factoryCache),
genericFactories.copy(),
usingGetClass,
fieldnameToGetter
);
Expand All @@ -88,7 +77,7 @@ public <S> ConfiguredEqualsVerifier withGenericPrefabValues(
Class<S> otherType,
Func1<?, S> factory
) {
PrefabValuesApi.addGenericPrefabValues(genericFactories, otherType, factory);
PrefabValuesApi.addGenericPrefabValues(factoryCache, otherType, factory);
return this;
}

Expand All @@ -98,7 +87,7 @@ public <S> ConfiguredEqualsVerifier withGenericPrefabValues(
Class<S> otherType,
Func2<?, ?, S> factory
) {
PrefabValuesApi.addGenericPrefabValues(genericFactories, otherType, factory);
PrefabValuesApi.addGenericPrefabValues(factoryCache, otherType, factory);
return this;
}

Expand Down Expand Up @@ -139,7 +128,6 @@ public <T> SingleTypeEqualsVerifierApi<T> forClass(Class<T> type) {
type,
EnumSet.copyOf(warningsToSuppress),
new FactoryCache().merge(factoryCache),
genericFactories.copy(),
objenesis,
usingGetClass,
fieldnameToGetter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import nl.jqno.equalsverifier.Warning;
import nl.jqno.equalsverifier.internal.checkers.*;
import nl.jqno.equalsverifier.internal.exceptions.MessagingException;
import nl.jqno.equalsverifier.internal.reflection.instantiation.GenericPrefabValueProvider.GenericFactories;
import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache;
import nl.jqno.equalsverifier.internal.util.*;
import nl.jqno.equalsverifier.internal.util.Formatter;
Expand All @@ -32,7 +31,6 @@ public class SingleTypeEqualsVerifierApi<T> implements EqualsVerifierApi<T> {
private boolean hasRedefinedSuperclass = false;
private Class<? extends T> redefinedSubclass = null;
private FactoryCache factoryCache = new FactoryCache();
private GenericFactories genericFactories = new GenericFactories();
private CachedHashCodeInitializer<T> cachedHashCodeInitializer =
CachedHashCodeInitializer.passthrough();
private Function<String, String> fieldnameToGetter = null;
Expand Down Expand Up @@ -72,7 +70,6 @@ public SingleTypeEqualsVerifierApi(Class<T> type, Objenesis objenesis) {
* @param type The class for which the {@code equals} method should be tested.
* @param warningsToSuppress A list of warnings to suppress in {@code EqualsVerifier}.
* @param factoryCache Factories that can be used to create values.
* @param genericFactories ValueProvider that records generic prefab values.
* @param objenesis To instantiate non-record classes.
* @param usingGetClass Whether {@code getClass} is used in the implementation of the {@code
* equals} method, instead of an {@code instanceof} check.
Expand All @@ -86,15 +83,13 @@ public SingleTypeEqualsVerifierApi(
Class<T> type,
EnumSet<Warning> warningsToSuppress,
FactoryCache factoryCache,
GenericFactories genericFactories,
Objenesis objenesis,
boolean usingGetClass,
Function<String, String> converter
) {
this(type, objenesis);
this.warningsToSuppress = EnumSet.copyOf(warningsToSuppress);
this.factoryCache = factoryCache;
this.genericFactories = genericFactories;
this.usingGetClass = usingGetClass;
this.fieldnameToGetter = converter;
}
Expand Down Expand Up @@ -171,7 +166,7 @@ public <S> SingleTypeEqualsVerifierApi<T> withGenericPrefabValues(
Class<S> otherType,
Func1<?, S> factory
) {
PrefabValuesApi.addGenericPrefabValues(genericFactories, otherType, factory);
PrefabValuesApi.addGenericPrefabValues(factoryCache, otherType, factory);
return this;
}

Expand All @@ -181,7 +176,7 @@ public <S> SingleTypeEqualsVerifierApi<T> withGenericPrefabValues(
Class<S> otherType,
Func2<?, ?, S> factory
) {
PrefabValuesApi.addGenericPrefabValues(genericFactories, otherType, factory);
PrefabValuesApi.addGenericPrefabValues(factoryCache, otherType, factory);
return this;
}

Expand Down Expand Up @@ -448,7 +443,7 @@ private void performVerification() {
Validations.validateClassCanBeVerified(type);

Configuration<T> config = buildConfig();
Context<T> context = new Context<>(config, factoryCache, genericFactories, objenesis);
Context<T> context = new Context<>(config, factoryCache, objenesis);
Validations.validateProcessedAnnotations(
type,
config.getAnnotationCache(),
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import nl.jqno.equalsverifier.internal.reflection.ClassProbe;
import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues;
import nl.jqno.equalsverifier.internal.reflection.instantiation.GenericPrefabValueProvider.GenericFactories;
import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator;
import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider;
import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache;
Expand All @@ -22,18 +21,13 @@ public final class Context<T> {
value = "EI_EXPOSE_REP2",
justification = "FieldCache is inherently mutable"
)
public Context(
Configuration<T> configuration,
FactoryCache factoryCache,
GenericFactories genericFactories,
Objenesis objenesis
) {
public Context(Configuration<T> configuration, FactoryCache factoryCache, Objenesis objenesis) {
this.type = configuration.getType();
this.configuration = configuration;
this.classProbe = new ClassProbe<>(configuration.getType());

FactoryCache cache = JavaApiPrefabValues.build().merge(factoryCache);
this.valueProvider = DefaultValueProviders.create(cache, genericFactories, objenesis);
this.valueProvider = DefaultValueProviders.create(cache, objenesis);
this.subjectCreator = new SubjectCreator<>(configuration, valueProvider, objenesis);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
package nl.jqno.equalsverifier.internal.util;

import nl.jqno.equalsverifier.internal.reflection.instantiation.*;
import nl.jqno.equalsverifier.internal.reflection.instantiation.GenericPrefabValueProvider.GenericFactories;
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.vintage.FactoryCache;
import org.objenesis.Objenesis;

public final class DefaultValueProviders {

private DefaultValueProviders() {}

public static ValueProvider create(
FactoryCache factoryCache,
GenericFactories genericFactories,
Objenesis objenesis
) {
public static ValueProvider create(FactoryCache factoryCache, Objenesis objenesis) {
ChainedValueProvider mainChain = new ChainedValueProvider();
ChainedValueProvider vintageChain = new ChainedValueProvider();

ValueProvider vintage = new VintageValueProvider(vintageChain, factoryCache, objenesis);
ValueProvider genericPrefab = new GenericPrefabValueProvider(genericFactories, mainChain);

mainChain.register(genericPrefab, vintage);
vintageChain.register(genericPrefab);
mainChain.register(vintage);

return mainChain;
}
Expand Down
Loading

0 comments on commit b3755a9

Please sign in to comment.