From 36c788701f98c60fbea417198dbbb3407fa599bc Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Thu, 6 Jun 2024 20:26:14 +0300 Subject: [PATCH 1/5] WIP: fixup nullability annotations and generic variance --- .../main/java/net/jqwik/api/Arbitraries.java | 78 +++++++++---------- .../main/java/net/jqwik/api/Arbitrary.java | 4 +- api/src/main/java/net/jqwik/api/Builders.java | 8 +- .../main/java/net/jqwik/api/Combinators.java | 78 +++++++++---------- .../java/net/jqwik/api/RandomGenerator.java | 3 +- .../main/java/net/jqwik/api/Shrinkable.java | 2 +- api/src/main/java/net/jqwik/api/Tuple.java | 34 ++++---- .../jqwik/api/arbitraries/ArrayArbitrary.java | 6 +- .../api/arbitraries/FunctionArbitrary.java | 4 +- .../api/arbitraries/IteratorArbitrary.java | 6 +- .../jqwik/api/arbitraries/ListArbitrary.java | 6 +- .../jqwik/api/arbitraries/MapArbitrary.java | 4 +- .../jqwik/api/arbitraries/SetArbitrary.java | 6 +- .../api/arbitraries/SizableArbitrary.java | 4 +- .../api/arbitraries/StreamArbitrary.java | 6 +- .../api/arbitraries/StreamableArbitrary.java | 4 +- .../api/arbitraries/TraverseArbitrary.java | 4 +- .../jqwik/api/arbitraries/TypeArbitrary.java | 4 +- .../api/statistics/StatisticsCoverage.java | 2 +- .../customized-parameter-generation.md | 10 +-- .../StatisticsCoverageExamples.java | 5 +- .../engine/facades/ArbitrariesFacadeImpl.java | 28 +++---- .../engine/facades/CombinatorsFacadeImpl.java | 2 +- .../statistics/StatisticsCollectorImpl.java | 6 +- .../arbitraries/DefaultArrayArbitrary.java | 2 +- .../arbitraries/DefaultFunctionArbitrary.java | 14 ++-- .../arbitraries/DefaultIteratorArbitrary.java | 2 +- .../arbitraries/DefaultListArbitrary.java | 8 +- .../arbitraries/DefaultSetArbitrary.java | 2 +- .../arbitraries/DefaultStreamArbitrary.java | 2 +- .../arbitraries/EdgeCasesSupport.java | 2 +- .../arbitraries/FrequencyOfArbitrary.java | 4 +- .../FromGeneratorWithSizeArbitrary.java | 4 +- .../properties/arbitraries/LazyArbitrary.java | 4 +- .../arbitraries/LazyOfArbitrary.java | 6 +- .../arbitraries/OneOfArbitrary.java | 5 +- .../arbitraries/RecursiveArbitrary.java | 6 +- .../combinations/DefaultListCombinator.java | 2 +- .../exhaustive/ExhaustiveGenerators.java | 2 +- .../FlatMappedExhaustiveGenerator.java | 6 +- .../randomized/AbstractFunctionGenerator.java | 6 +- .../randomized/ConstantFunctionGenerator.java | 2 +- .../randomized/FrequencyGenerator.java | 2 +- .../randomized/FunctionGenerator.java | 2 +- .../randomized/RandomGenerators.java | 4 +- .../shrinking/ChooseValueShrinkable.java | 4 +- .../support/ChooseRandomlyByFrequency.java | 6 +- .../statistics/StatisticsCoverageTests.java | 8 +- kotlin/build.gradle | 1 + .../jqwik/kotlin/api/BuildersExtensions.kt | 6 +- .../net/jqwik/kotlin/api/SequenceArbitrary.kt | 4 +- .../kotlin/api/SizableArbitraryExtensions.kt | 2 +- .../jqwik/kotlin/CollectionExtensionsTests.kt | 4 +- .../net/jqwik/kotlin/InternalModifierTests.kt | 6 +- 54 files changed, 231 insertions(+), 211 deletions(-) diff --git a/api/src/main/java/net/jqwik/api/Arbitraries.java b/api/src/main/java/net/jqwik/api/Arbitraries.java index b46c0943c..cefb5d81a 100644 --- a/api/src/main/java/net/jqwik/api/Arbitraries.java +++ b/api/src/main/java/net/jqwik/api/Arbitraries.java @@ -25,13 +25,13 @@ public static abstract class ArbitrariesFacade { implementation = FacadeLoader.load(ArbitrariesFacade.class); } - public abstract Arbitrary oneOf(Collection> all); + public abstract Arbitrary oneOf(Collection> all); public abstract ActionSequenceArbitrary sequences(Arbitrary> actionArbitrary); - public abstract Arbitrary frequencyOf(List>> frequencies); + public abstract Arbitrary frequencyOf(List>> frequencies); - public abstract <@Nullable T> Arbitrary just(@Nullable T value); + public abstract Arbitrary just(T value); public abstract IntegerArbitrary integers(); @@ -57,36 +57,36 @@ public static abstract class ArbitrariesFacade { public abstract Arbitrary defaultFor(TypeUsage typeUsage, Function> noDefaultResolver); - public abstract Arbitrary lazy(Supplier> arbitrarySupplier); + public abstract Arbitrary lazy(Supplier> arbitrarySupplier); public abstract TypeArbitrary forType(Class targetType); - public abstract MapArbitrary maps(Arbitrary keysArbitrary, Arbitrary valuesArbitrary); + public abstract MapArbitrary maps(Arbitrary keysArbitrary, Arbitrary valuesArbitrary); - public abstract Arbitrary> entries(Arbitrary keysArbitrary, Arbitrary valuesArbitrary); + public abstract Arbitrary> entries(Arbitrary keysArbitrary, Arbitrary valuesArbitrary); - public abstract Arbitrary recursive( - Supplier> base, - Function, Arbitrary> recur, + public abstract Arbitrary recursive( + Supplier> base, + Function, ? extends Arbitrary> recur, int minDepth, int maxDepth ); - public abstract Arbitrary lazyOf(List>> suppliers); + public abstract Arbitrary lazyOf(List>> suppliers); public abstract TraverseArbitrary traverse(Class targetType, Traverser traverser); public abstract Arbitrary of(char[] chars); - public abstract Arbitrary of(Collection values); + public abstract Arbitrary of(Collection values); - public abstract Arbitrary create(Supplier supplier); + public abstract Arbitrary create(Supplier supplier); - public abstract Arbitrary> shuffle(List values); + public abstract Arbitrary> shuffle(List values); - public abstract Arbitrary fromGenerator(IntFunction> generatorSupplier); + public abstract Arbitrary fromGenerator(IntFunction> generatorSupplier); - public abstract Arbitrary frequency(List> frequencies); + public abstract Arbitrary frequency(List> frequencies); } private Arbitraries() { @@ -99,7 +99,7 @@ private Arbitraries() { * @param The type of values to generate * @return a new arbitrary instance */ - public static Arbitrary fromGenerator(RandomGenerator generator) { + public static Arbitrary fromGenerator(RandomGenerator generator) { return fromGeneratorWithSize(ignore -> generator); } @@ -111,7 +111,7 @@ public static Arbitrary fromGenerator(RandomGenerator generator) { * @return a new arbitrary instance */ @API(status = EXPERIMENTAL, since = "1.8.0") - public static Arbitrary fromGeneratorWithSize(IntFunction> generatorSupplier) { + public static Arbitrary fromGeneratorWithSize(IntFunction> generatorSupplier) { return ArbitrariesFacade.implementation.fromGenerator(generatorSupplier); } @@ -123,7 +123,7 @@ public static Arbitrary fromGeneratorWithSize(IntFunction The type of values to generate * @return a new arbitrary instance */ - public static Arbitrary randomValue(Function generator) { + public static Arbitrary randomValue(Function generator) { IntFunction> generatorSupplier = ignore -> random -> Shrinkable.unshrinkable(generator.apply(random)); return fromGeneratorWithSize(generatorSupplier); } @@ -153,7 +153,7 @@ public static Arbitrary randoms() { * @return a new arbitrary instance */ @SafeVarargs - public static Arbitrary of(T... values) { + public static Arbitrary of(T... values) { return of(Arrays.asList(values)); } @@ -172,7 +172,7 @@ public static Arbitrary of(T... values) { * @return a new arbitrary instance */ @API(status = MAINTAINED, since = "1.3.1") - public static <@Nullable T> Arbitrary of(Collection values) { + public static Arbitrary of(Collection values) { return ArbitrariesFacade.implementation.of(values); } @@ -192,7 +192,7 @@ public static Arbitrary of(T... values) { */ @API(status = MAINTAINED, since = "1.3.0") @SafeVarargs - public static Arbitrary ofSuppliers(Supplier... valueSuppliers) { + public static Arbitrary ofSuppliers(Supplier... valueSuppliers) { return of(valueSuppliers).map(Supplier::get); } @@ -211,7 +211,7 @@ public static Arbitrary ofSuppliers(Supplier... valueSuppliers) { * @return a new arbitrary instance */ @API(status = MAINTAINED, since = "1.3.1") - public static Arbitrary ofSuppliers(Collection> valueSuppliers) { + public static Arbitrary ofSuppliers(Collection> valueSuppliers) { return of(valueSuppliers).map(Supplier::get); } @@ -247,7 +247,7 @@ public static > Arbitrary of(Class enumClass) { */ @SuppressWarnings("unchecked") @SafeVarargs - public static Arbitrary oneOf(Arbitrary first, Arbitrary... rest) { + public static Arbitrary oneOf(Arbitrary first, Arbitrary... rest) { List> all = new ArrayList<>(); all.add(first); for (Arbitrary arbitrary : rest) { @@ -264,7 +264,7 @@ public static Arbitrary oneOf(Arbitrary first, Arbitrary Arbitrary oneOf(Collection> choices) { + public static Arbitrary oneOf(Collection> choices) { if (choices.isEmpty()) { String message = "oneOf() must not be called with no choices"; throw new JqwikException(message); @@ -285,7 +285,7 @@ public static Arbitrary oneOf(Collection> choices) * @return a new arbitrary instance */ @SafeVarargs - public static Arbitrary frequency(Tuple2... frequencies) { + public static Arbitrary frequency(Tuple2... frequencies) { return frequency(Arrays.asList(frequencies)); } @@ -297,7 +297,7 @@ public static Arbitrary frequency(Tuple2... frequencies) { * @param The type of values to generate * @return a new arbitrary instance */ - public static <@Nullable T> Arbitrary frequency(List> frequencies) { + public static Arbitrary frequency(List> frequencies) { return ArbitrariesFacade.implementation.frequency(frequencies); } @@ -311,7 +311,7 @@ public static Arbitrary frequency(Tuple2... frequencies) { */ @SuppressWarnings("unchecked") @SafeVarargs - public static Arbitrary frequencyOf(Tuple2>... frequencies) { + public static Arbitrary frequencyOf(Tuple2>... frequencies) { List>> all = new ArrayList<>(); for (Tuple2> frequency : frequencies) { all.add(Tuple.of(frequency.get1(), (Arbitrary) frequency.get2())); @@ -327,7 +327,7 @@ public static Arbitrary frequencyOf(Tuple2 The type of values to generate * @return a new arbitrary instance */ - public static <@Nullable T> Arbitrary frequencyOf(List>> frequencies) { + public static Arbitrary frequencyOf(List>> frequencies) { // Simple flatMapping is not enough because of configurations return ArbitrariesFacade.implementation.frequencyOf(frequencies); } @@ -454,7 +454,7 @@ public static CharacterArbitrary chars() { * @return a new arbitrary instance */ @API(status = MAINTAINED, since = "1.1.1") - public static Arbitrary create(Supplier supplier) { + public static Arbitrary create(Supplier supplier) { return ArbitrariesFacade.implementation.create(supplier); } @@ -468,7 +468,7 @@ public static Arbitrary create(Supplier supplier) { * @return a new arbitrary instance */ @SafeVarargs - public static Arbitrary> shuffle(T... values) { + public static Arbitrary> shuffle(T... values) { return shuffle(Arrays.asList(values)); } @@ -481,7 +481,7 @@ public static Arbitrary> shuffle(T... values) { * @param The type of values to generate * @return a new arbitrary instance */ - public static Arbitrary> shuffle(List values) { + public static Arbitrary> shuffle(List values) { return ArbitrariesFacade.implementation.shuffle(values); } @@ -591,7 +591,7 @@ public static TraverseArbitrary traverse(Class targetType, Traverser t * @see #recursive(Supplier, Function, int) * @see #lazyOf(Supplier, Supplier[]) */ - public static Arbitrary lazy(Supplier> arbitrarySupplier) { + public static Arbitrary lazy(Supplier> arbitrarySupplier) { return ArbitrariesFacade.implementation.lazy(arbitrarySupplier); } @@ -609,9 +609,9 @@ public static Arbitrary lazy(Supplier> arbitrarySupplier) { * @return a new arbitrary instance * @see #lazy(Supplier) */ - public static Arbitrary recursive( - Supplier> base, - Function, Arbitrary> recur, + public static Arbitrary recursive( + Supplier> base, + Function, ? extends Arbitrary> recur, int depth ) { return ArbitrariesFacade.implementation.recursive(base, recur, depth, depth); @@ -633,9 +633,9 @@ public static Arbitrary recursive( * @see #lazy(Supplier) */ @API(status = MAINTAINED, since = "1.6.4") - public static Arbitrary recursive( - Supplier> base, - Function, Arbitrary> recur, + public static Arbitrary recursive( + Supplier> base, + Function, ? extends Arbitrary> recur, int minDepth, int maxDepth ) { @@ -671,7 +671,7 @@ public static Arbitrary recursive( @SuppressWarnings("unchecked") @SafeVarargs @API(status = MAINTAINED, since = "1.3.4") - public static Arbitrary lazyOf(Supplier> first, Supplier>... rest) { + public static Arbitrary lazyOf(Supplier> first, Supplier>... rest) { List>> all = new ArrayList<>(); all.add(() -> (Arbitrary) first.get()); for (Supplier> arbitrarySupplier : rest) { diff --git a/api/src/main/java/net/jqwik/api/Arbitrary.java b/api/src/main/java/net/jqwik/api/Arbitrary.java index f76f8c7b4..9f0c5ed08 100644 --- a/api/src/main/java/net/jqwik/api/Arbitrary.java +++ b/api/src/main/java/net/jqwik/api/Arbitrary.java @@ -6,7 +6,7 @@ import com.google.errorprone.annotations.*; import org.apiguardian.api.*; -import org.jspecify.annotations.Nullable; +import org.jspecify.annotations.*; import net.jqwik.api.arbitraries.*; @@ -20,7 +20,7 @@ */ @API(status = STABLE, since = "1.0") @CheckReturnValue -public interface Arbitrary<@Nullable T> { +public interface Arbitrary { @API(status = INTERNAL) abstract class ArbitraryFacade { diff --git a/api/src/main/java/net/jqwik/api/Builders.java b/api/src/main/java/net/jqwik/api/Builders.java index 3a7e317d4..b96949449 100644 --- a/api/src/main/java/net/jqwik/api/Builders.java +++ b/api/src/main/java/net/jqwik/api/Builders.java @@ -53,7 +53,7 @@ private BuilderCombinator(Supplier starter, List * @return new {@linkplain CombinableBuilder} instance */ - public <@Nullable T> CombinableBuilder use(Arbitrary arbitrary) { + public CombinableBuilder use(Arbitrary arbitrary) { return new CombinableBuilder<>(this, 1.0, arbitrary); } @@ -167,7 +167,7 @@ BuilderCombinator withMutator(double probabilityOfUse, Arbitrary arbi * * @param The builder's type */ - public static class CombinableBuilder { + public static class CombinableBuilder { private final BuilderCombinator combinator; private final double probabilityOfUse; private final Arbitrary arbitrary; @@ -201,7 +201,7 @@ public CombinableBuilder withProbability(double probabilityOfUse) { * @return new {@linkplain BuilderCombinator} instance */ @SuppressWarnings("unchecked") - public BuilderCombinator in(BiFunction toFunction) { + public BuilderCombinator in(BiFunction toFunction) { if (probabilityOfUse == 0.0) { return combinator; } @@ -217,7 +217,7 @@ public BuilderCombinator in(BiFunction toFunction) { * @param setter Use value provided by arbitrary to change a builder's property. * @return new {@linkplain BuilderCombinator} instance with same embedded builder */ - public BuilderCombinator inSetter(BiConsumer setter) { + public BuilderCombinator inSetter(BiConsumer setter) { BiFunction toFunction = (b, t) -> { setter.accept(b, t); return b; diff --git a/api/src/main/java/net/jqwik/api/Combinators.java b/api/src/main/java/net/jqwik/api/Combinators.java index da7011726..a8a21dfdc 100644 --- a/api/src/main/java/net/jqwik/api/Combinators.java +++ b/api/src/main/java/net/jqwik/api/Combinators.java @@ -68,7 +68,7 @@ public abstract Combinator8 a8 ); - public abstract ListCombinator combineList(List> listOfArbitraries); + public abstract ListCombinator combineList(List> listOfArbitraries); } private Combinators() { @@ -79,7 +79,7 @@ private Combinators() { * * @return Combinator2 instance which can be evaluated using {@linkplain Combinator2#as} */ - public static <@Nullable T1, @Nullable T2> Combinator2 combine(Arbitrary a1, Arbitrary a2) { + public static Combinator2 combine(Arbitrary a1, Arbitrary a2) { return CombinatorsFacade.implementation.combine2(a1, a2); } @@ -88,7 +88,7 @@ private Combinators() { * * @return Combinator3 instance which can be evaluated using {@linkplain Combinator3#as} */ - public static <@Nullable T1, @Nullable T2, @Nullable T3> Combinator3 combine(Arbitrary a1, Arbitrary a2, Arbitrary a3) { + public static Combinator3 combine(Arbitrary a1, Arbitrary a2, Arbitrary a3) { return CombinatorsFacade.implementation.combine3(a1, a2, a3); } @@ -97,7 +97,7 @@ private Combinators() { * * @return Combinator4 instance which can be evaluated using {@linkplain Combinator4#as} */ - public static <@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4> Combinator4 combine( + public static Combinator4 combine( Arbitrary a1, Arbitrary a2, Arbitrary a3, Arbitrary a4 ) { @@ -109,7 +109,7 @@ private Combinators() { * * @return Combinator5 instance which can be evaluated using {@linkplain Combinator5#as} */ - public static <@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5> Combinator5 combine( + public static Combinator5 combine( Arbitrary a1, Arbitrary a2, Arbitrary a3, Arbitrary a4, Arbitrary a5 ) { @@ -121,7 +121,7 @@ private Combinators() { * * @return Combinator6 instance which can be evaluated using {@linkplain Combinator6#as} */ - public static <@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6> Combinator6 combine( + public static Combinator6 combine( Arbitrary a1, Arbitrary a2, Arbitrary a3, Arbitrary a4, Arbitrary a5, Arbitrary a6 ) { @@ -133,7 +133,7 @@ private Combinators() { * * @return Combinator7 instance which can be evaluated using {@linkplain Combinator7#as} */ - public static <@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6, @Nullable T7> Combinator7 combine( + public static Combinator7 combine( Arbitrary a1, Arbitrary a2, Arbitrary a3, Arbitrary a4, Arbitrary a5, Arbitrary a6, Arbitrary a7 ) { @@ -145,7 +145,7 @@ private Combinators() { * * @return Combinator8 instance which can be evaluated using {@linkplain Combinator8#as} */ - public static <@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6, @Nullable T7, @Nullable T8> Combinator8 combine( + public static Combinator8 combine( Arbitrary a1, Arbitrary a2, Arbitrary a3, Arbitrary a4, Arbitrary a5, Arbitrary a6, Arbitrary a7, Arbitrary a8 ) { @@ -157,14 +157,14 @@ private Combinators() { * * @return ListCombinator instance which can be evaluated using {@linkplain ListCombinator#as} */ - public static <@Nullable T> ListCombinator combine(List> listOfArbitraries) { + public static ListCombinator combine(List> listOfArbitraries) { return CombinatorsFacade.implementation.combineList(listOfArbitraries); } /** * Combinator for two values. */ - public interface Combinator2<@Nullable T1, @Nullable T2> { + public interface Combinator2 { /** * Combine two values. @@ -173,7 +173,7 @@ public interface Combinator2<@Nullable T1, @Nullable T2> { * @param return type * @return arbitrary instance */ - <@Nullable R> Arbitrary as(F2 combinator); + Arbitrary as(F2 combinator); /** * Filter two values to only let them pass if the predicate is true. @@ -191,7 +191,7 @@ public interface Combinator2<@Nullable T1, @Nullable T2> { * @param return type of arbitrary * @return arbitrary instance */ - default <@Nullable R> Arbitrary flatAs(F2> flatCombinator) { + default Arbitrary flatAs(F2> flatCombinator) { return as(flatCombinator).flatMap(Function.identity()); } } @@ -199,7 +199,7 @@ public interface Combinator2<@Nullable T1, @Nullable T2> { /** * Combinator for three values. */ - public interface Combinator3<@Nullable T1, @Nullable T2, @Nullable T3> { + public interface Combinator3 { /** * Combine three values. @@ -208,7 +208,7 @@ public interface Combinator3<@Nullable T1, @Nullable T2, @Nullable T3> { * @param return type * @return arbitrary instance */ - <@Nullable R> Arbitrary as(F3 combinator); + Arbitrary as(F3 combinator); /** * Filter three values to only let them pass if the predicate is true. @@ -226,7 +226,7 @@ public interface Combinator3<@Nullable T1, @Nullable T2, @Nullable T3> { * @param return type of arbitrary * @return arbitrary instance */ - default <@Nullable R> Arbitrary flatAs(F3> flatCombinator) { + default Arbitrary flatAs(F3> flatCombinator) { return as(flatCombinator).flatMap(Function.identity()); } @@ -235,7 +235,7 @@ public interface Combinator3<@Nullable T1, @Nullable T2, @Nullable T3> { /** * Combinator for four values. */ - public interface Combinator4<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4> { + public interface Combinator4 { /** * Combine four values. @@ -244,7 +244,7 @@ public interface Combinator4<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable * @param return type * @return arbitrary instance */ - <@Nullable R> Arbitrary as(F4 combinator); + Arbitrary as(F4 combinator); /** * Filter four values to only let them pass if the predicate is true. @@ -262,7 +262,7 @@ public interface Combinator4<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable * @param return type of arbitrary * @return arbitrary instance */ - default <@Nullable R> Arbitrary flatAs(F4> flatCombinator) { + default Arbitrary flatAs(F4> flatCombinator) { return as(flatCombinator).flatMap(Function.identity()); } @@ -271,7 +271,7 @@ public interface Combinator4<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable /** * Combinator for five values. */ - public interface Combinator5<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5> { + public interface Combinator5 { /** * Combine five values. @@ -280,7 +280,7 @@ public interface Combinator5<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable * @param return type * @return arbitrary instance */ - <@Nullable R> Arbitrary as(F5 combinator); + Arbitrary as(F5 combinator); /** * Filter five values to only let them pass if the predicate is true. @@ -298,7 +298,7 @@ public interface Combinator5<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable * @param return type of arbitrary * @return arbitrary instance */ - default <@Nullable R> Arbitrary flatAs(F5> flatCombinator) { + default Arbitrary flatAs(F5> flatCombinator) { return as(flatCombinator).flatMap(Function.identity()); } } @@ -306,7 +306,7 @@ public interface Combinator5<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable /** * Combinator for six values. */ - public interface Combinator6<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6> { + public interface Combinator6 { /** * Combine six values. @@ -315,7 +315,7 @@ public interface Combinator6<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable * @param return type * @return arbitrary instance */ - <@Nullable R> Arbitrary as(F6 combinator); + Arbitrary as(F6 combinator); /** * Filter six values to only let them pass if the predicate is true. @@ -333,7 +333,7 @@ public interface Combinator6<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable * @param return type of arbitrary * @return arbitrary instance */ - default <@Nullable R> Arbitrary flatAs(F6> flatCombinator) { + default Arbitrary flatAs(F6> flatCombinator) { return as(flatCombinator).flatMap(Function.identity()); } @@ -342,7 +342,7 @@ public interface Combinator6<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable /** * Combinator for seven values. */ - public interface Combinator7<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6, @Nullable T7> { + public interface Combinator7 { /** * Combine seven values. @@ -351,7 +351,7 @@ public interface Combinator7<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable * @param return type * @return arbitrary instance */ - <@Nullable R> Arbitrary as(F7 combinator); + Arbitrary as(F7 combinator); /** * Filter seven values to only let them pass if the predicate is true. @@ -369,7 +369,7 @@ public interface Combinator7<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable * @param return type of arbitrary * @return arbitrary instance */ - default <@Nullable R> Arbitrary flatAs(F7> flatCombinator) { + default Arbitrary flatAs(F7> flatCombinator) { return as(flatCombinator).flatMap(Function.identity()); } @@ -378,7 +378,7 @@ public interface Combinator7<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable /** * Combinator for eight values. */ - public interface Combinator8<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6, @Nullable T7, @Nullable T8> { + public interface Combinator8 { /** * Combine eight values. @@ -387,7 +387,7 @@ public interface Combinator8<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable * @param return type * @return arbitrary instance */ - <@Nullable R> Arbitrary as(F8 combinator); + Arbitrary as(F8 combinator); /** * Filter eight values to only let them pass if the predicate is true. @@ -405,7 +405,7 @@ public interface Combinator8<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable * @param return type of arbitrary * @return arbitrary instance */ - default <@Nullable R> Arbitrary flatAs(F8> flatCombinator) { + default Arbitrary flatAs(F8> flatCombinator) { return as(flatCombinator).flatMap(Function.identity()); } } @@ -422,7 +422,7 @@ public interface ListCombinator<@Nullable T> { * @param return type * @return arbitrary instance */ - <@Nullable R> Arbitrary as(Function, R> combinator); + Arbitrary as(Function, R> combinator); /** * Filter list of values to only let them pass if the predicate is true. @@ -440,50 +440,50 @@ public interface ListCombinator<@Nullable T> { * @param return type of arbitrary * @return arbitrary instance */ - default <@Nullable R> Arbitrary flatAs(Function, Arbitrary> flatCombinator) { + default Arbitrary flatAs(Function, Arbitrary> flatCombinator) { return as(flatCombinator).flatMap(Function.identity()); } } @FunctionalInterface @API(status = INTERNAL) - public interface F2<@Nullable T1, @Nullable T2, @Nullable R> { + public interface F2 { R apply(T1 t1, T2 t2); } @FunctionalInterface @API(status = INTERNAL) - public interface F3<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable R> { + public interface F3 { R apply(T1 t1, T2 t2, T3 t3); } @FunctionalInterface @API(status = INTERNAL) - public interface F4<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable R> { + public interface F4 { R apply(T1 t1, T2 t2, T3 t3, T4 t4); } @FunctionalInterface @API(status = INTERNAL) - public interface F5<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable R> { + public interface F5 { R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5); } @FunctionalInterface @API(status = INTERNAL) - public interface F6<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6, @Nullable R> { + public interface F6 { R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6); } @FunctionalInterface @API(status = INTERNAL) - public interface F7<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6, @Nullable T7, @Nullable R> { + public interface F7 { R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7); } @FunctionalInterface @API(status = INTERNAL) - public interface F8<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6, @Nullable T7, @Nullable T8, @Nullable R> { + public interface F8 { R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8); } diff --git a/api/src/main/java/net/jqwik/api/RandomGenerator.java b/api/src/main/java/net/jqwik/api/RandomGenerator.java index 694d66742..b47f3871e 100644 --- a/api/src/main/java/net/jqwik/api/RandomGenerator.java +++ b/api/src/main/java/net/jqwik/api/RandomGenerator.java @@ -5,11 +5,12 @@ import java.util.stream.*; import org.apiguardian.api.*; +import org.jspecify.annotations.*; import static org.apiguardian.api.API.Status.*; @API(status = STABLE, since = "1.0") -public interface RandomGenerator { +public interface RandomGenerator { @API(status = INTERNAL) abstract class RandomGeneratorFacade { diff --git a/api/src/main/java/net/jqwik/api/Shrinkable.java b/api/src/main/java/net/jqwik/api/Shrinkable.java index c99d9bd3c..c7a4c87db 100644 --- a/api/src/main/java/net/jqwik/api/Shrinkable.java +++ b/api/src/main/java/net/jqwik/api/Shrinkable.java @@ -10,7 +10,7 @@ import static org.apiguardian.api.API.Status.*; @API(status = STABLE, since = "1.0") -public interface Shrinkable extends Comparable> { +public interface Shrinkable extends Comparable> { @API(status = INTERNAL) abstract class ShrinkableFacade { diff --git a/api/src/main/java/net/jqwik/api/Tuple.java b/api/src/main/java/net/jqwik/api/Tuple.java index 438d36e99..6b97d3cc1 100644 --- a/api/src/main/java/net/jqwik/api/Tuple.java +++ b/api/src/main/java/net/jqwik/api/Tuple.java @@ -37,23 +37,23 @@ static Tuple0 empty() { return Tuple.of(); } - static <@Nullable T1> Tuple1 of(T1 v1) { + static Tuple1 of(T1 v1) { return new Tuple1<>(v1); } - static <@Nullable T1, @Nullable T2> Tuple2 of(T1 v1, T2 v2) { + static Tuple2 of(T1 v1, T2 v2) { return new Tuple2<>(v1, v2); } - static <@Nullable T1, @Nullable T2, @Nullable T3> Tuple3 of(T1 v1, T2 v2, T3 v3) { + static Tuple3 of(T1 v1, T2 v2, T3 v3) { return new Tuple3<>(v1, v2, v3); } - static <@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4> Tuple4 of(T1 v1, T2 v2, T3 v3, T4 v4) { + static Tuple4 of(T1 v1, T2 v2, T3 v3, T4 v4) { return new Tuple4<>(v1, v2, v3, v4); } - static <@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5> Tuple5 of( + static Tuple5 of( T1 v1, T2 v2, T3 v3, @@ -63,7 +63,7 @@ static Tuple0 empty() { return new Tuple5<>(v1, v2, v3, v4, v5); } - static <@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6> Tuple6 of( + static Tuple6 of( T1 v1, T2 v2, T3 v3, @@ -74,7 +74,7 @@ static Tuple0 empty() { return new Tuple6<>(v1, v2, v3, v4, v5, v6); } - static <@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6, @Nullable T7> Tuple7 of( + static Tuple7 of( T1 v1, T2 v2, T3 v3, @@ -86,7 +86,7 @@ static Tuple0 empty() { return new Tuple7<>(v1, v2, v3, v4, v5, v6, v7); } - static <@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6, @Nullable T7, @Nullable T8> Tuple8 of( + static Tuple8 of( T1 v1, T2 v2, T3 v3, @@ -122,10 +122,10 @@ public String toString() { } } - class Tuple1<@Nullable T1> extends Tuple0 { + class Tuple1 extends Tuple0 { final T1 v1; - private Tuple1(@Nullable T1 v1) { + private Tuple1(T1 v1) { super(); this.v1 = v1; } @@ -163,7 +163,7 @@ public String toString() { } } - class Tuple2<@Nullable T1, @Nullable T2> extends Tuple1 { + class Tuple2 extends Tuple1 { final T2 v2; private Tuple2(T1 v1, T2 v2) { @@ -200,7 +200,7 @@ public int hashCode() { } } - class Tuple3<@Nullable T1, @Nullable T2, @Nullable T3> extends Tuple2 { + class Tuple3 extends Tuple2 { final T3 v3; private Tuple3(T1 v1, T2 v2, T3 v3) { @@ -238,7 +238,7 @@ public int hashCode() { } } - class Tuple4<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4> extends Tuple3 { + class Tuple4 extends Tuple3 { final T4 v4; private Tuple4(T1 v1, T2 v2, T3 v3, T4 v4) { @@ -277,7 +277,7 @@ public int hashCode() { } } - class Tuple5<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5> extends Tuple4 { + class Tuple5 extends Tuple4 { final T5 v5; private Tuple5(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5) { @@ -317,7 +317,7 @@ public int hashCode() { } } - class Tuple6<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6> extends Tuple5 { + class Tuple6 extends Tuple5 { final T6 v6; private Tuple6(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6) { @@ -358,7 +358,7 @@ public int hashCode() { } } - class Tuple7<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6, @Nullable T7> extends Tuple6 { + class Tuple7 extends Tuple6 { final T7 v7; private Tuple7( @@ -408,7 +408,7 @@ public int hashCode() { } } - class Tuple8<@Nullable T1, @Nullable T2, @Nullable T3, @Nullable T4, @Nullable T5, @Nullable T6, @Nullable T7, @Nullable T8> extends Tuple7 { + class Tuple8 extends Tuple7 { final T8 v8; private Tuple8( diff --git a/api/src/main/java/net/jqwik/api/arbitraries/ArrayArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/ArrayArbitrary.java index 7a93878bf..cee278c1b 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/ArrayArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/ArrayArbitrary.java @@ -12,9 +12,11 @@ /** * Fluent interface to add functionality to arbitraries that generate instances * of Arrays + * + * @param type of the resulting array class */ @API(status = MAINTAINED, since = "1.4.0") -public interface ArrayArbitrary<@Nullable T, A> extends StreamableArbitrary { +public interface ArrayArbitrary extends StreamableArbitrary { /** * Fix the size to {@code size}. @@ -76,6 +78,6 @@ default ArrayArbitrary ofSize(int size) { * @return new arbitrary instance */ @API(status = MAINTAINED, since = "1.4.0") - ArrayArbitrary uniqueElements(Function by); + ArrayArbitrary uniqueElements(Function by); } diff --git a/api/src/main/java/net/jqwik/api/arbitraries/FunctionArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/FunctionArbitrary.java index 85bec6760..808963692 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/FunctionArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/FunctionArbitrary.java @@ -17,7 +17,7 @@ * @param The return type of the functional interface */ @API(status = MAINTAINED, since = "1.3.0") -public interface FunctionArbitrary extends Arbitrary { +public interface FunctionArbitrary extends Arbitrary { /** * @@ -28,6 +28,6 @@ public interface FunctionArbitrary extends Arbitrary { * @param answer A function that produces a concrete answer or throws an exception * @return A new instance of function arbitrary */ - FunctionArbitrary when(Predicate> parameterCondition, Function, R> answer); + FunctionArbitrary when(Predicate> parameterCondition, Function, ? extends R> answer); } diff --git a/api/src/main/java/net/jqwik/api/arbitraries/IteratorArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/IteratorArbitrary.java index d854a02b4..0d6d8e16c 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/IteratorArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/IteratorArbitrary.java @@ -7,6 +7,8 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; /** @@ -14,7 +16,7 @@ * of type {@linkplain Iterator} */ @API(status = MAINTAINED, since = "1.3.2") -public interface IteratorArbitrary extends Arbitrary>, StreamableArbitrary> { +public interface IteratorArbitrary extends Arbitrary>, StreamableArbitrary> { /** * Fix the size to {@code size}. @@ -76,6 +78,6 @@ default IteratorArbitrary ofSize(int size) { * @return new arbitrary instance */ @API(status = MAINTAINED, since = "1.4.0") - IteratorArbitrary uniqueElements(Function by); + IteratorArbitrary uniqueElements(Function by); } diff --git a/api/src/main/java/net/jqwik/api/arbitraries/ListArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/ListArbitrary.java index ed7ae6a8e..4c2e69655 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/ListArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/ListArbitrary.java @@ -16,7 +16,7 @@ * of type {@linkplain List} */ @API(status = MAINTAINED, since = "1.3.2") -public interface ListArbitrary extends Arbitrary>, StreamableArbitrary> { +public interface ListArbitrary extends Arbitrary>, StreamableArbitrary> { /** * Fix the size to {@code size}. @@ -72,7 +72,7 @@ default ListArbitrary ofSize(int size) { * @return arbitrary of a list of Us */ @API(status = MAINTAINED, since = "1.4.0") - Arbitrary> flatMapEach(BiFunction, T, Arbitrary> flatMapper); + Arbitrary> flatMapEach(BiFunction, ? super T, ? extends Arbitrary> flatMapper); /** * Add the constraint that elements of the generated list must be unique, @@ -100,5 +100,5 @@ default ListArbitrary ofSize(int size) { * @return new arbitrary instance */ @API(status = MAINTAINED, since = "1.4.0") - ListArbitrary<@Nullable T> uniqueElements(Function<@Nullable T, Object> by); + ListArbitrary uniqueElements(Function by); } diff --git a/api/src/main/java/net/jqwik/api/arbitraries/MapArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/MapArbitrary.java index fb0ec32c4..1f9ef22dc 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/MapArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/MapArbitrary.java @@ -7,6 +7,8 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; /** @@ -14,7 +16,7 @@ * of type {@linkplain Map} */ @API(status = MAINTAINED, since = "1.3.2") -public interface MapArbitrary extends Arbitrary>, SizableArbitrary> { +public interface MapArbitrary extends Arbitrary>, SizableArbitrary> { /** * Fix the size to {@code size}. diff --git a/api/src/main/java/net/jqwik/api/arbitraries/SetArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/SetArbitrary.java index d8a66e983..f9a9fe1b5 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/SetArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/SetArbitrary.java @@ -7,6 +7,8 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; /** @@ -14,7 +16,7 @@ * of type {@linkplain Set} */ @API(status = MAINTAINED, since = "1.3.2") -public interface SetArbitrary extends Arbitrary>, StreamableArbitrary> { +public interface SetArbitrary extends Arbitrary>, StreamableArbitrary> { /** * Fix the size to {@code size}. @@ -94,6 +96,6 @@ default SetArbitrary ofSize(int size) { * @return new arbitrary instance */ @API(status = MAINTAINED, since = "1.4.0") - SetArbitrary uniqueElements(Function by); + SetArbitrary uniqueElements(Function by); } diff --git a/api/src/main/java/net/jqwik/api/arbitraries/SizableArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/SizableArbitrary.java index 0035cab95..8f270a035 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/SizableArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/SizableArbitrary.java @@ -4,13 +4,15 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; /** * Fluent interface to configure arbitraries that have size constraints for generated values, e.g. collections and arrays. */ @API(status = MAINTAINED, since = "1.0") -public interface SizableArbitrary extends Arbitrary { +public interface SizableArbitrary extends Arbitrary { /** * Fix the size to {@code size}. diff --git a/api/src/main/java/net/jqwik/api/arbitraries/StreamArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/StreamArbitrary.java index 1c5d93d3c..c200f6b37 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/StreamArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/StreamArbitrary.java @@ -7,6 +7,8 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; /** @@ -14,7 +16,7 @@ * of type {@linkplain Stream} */ @API(status = MAINTAINED, since = "1.3.2") -public interface StreamArbitrary extends Arbitrary>, StreamableArbitrary> { +public interface StreamArbitrary extends Arbitrary>, StreamableArbitrary> { /** * Fix the size to {@code size}. @@ -76,6 +78,6 @@ default StreamArbitrary ofSize(int size) { * @return new arbitrary instance */ @API(status = MAINTAINED, since = "1.4.0") - StreamArbitrary uniqueElements(Function by); + StreamArbitrary uniqueElements(Function by); } diff --git a/api/src/main/java/net/jqwik/api/arbitraries/StreamableArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/StreamableArbitrary.java index 4f8c70f52..d45d63565 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/StreamableArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/StreamableArbitrary.java @@ -17,7 +17,7 @@ * can be streamed, e.g. {@link List}, {@link Set}, {@link Stream} and Arrays */ @API(status = MAINTAINED, since = "1.2.1") -public interface StreamableArbitrary extends SizableArbitrary { +public interface StreamableArbitrary extends SizableArbitrary { /** * Given an {@code initial} argument use {@code accumulator} to produce @@ -79,6 +79,6 @@ default StreamableArbitrary ofSize(int size) { * @return new arbitrary instance */ @API(status = MAINTAINED, since = "1.7.3") - StreamableArbitrary<@Nullable T, U> uniqueElements(Function<@Nullable T, Object> by); + StreamableArbitrary uniqueElements(Function by); } diff --git a/api/src/main/java/net/jqwik/api/arbitraries/TraverseArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/TraverseArbitrary.java index adc5cfe64..5a7ec3c20 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/TraverseArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/TraverseArbitrary.java @@ -8,6 +8,8 @@ import net.jqwik.api.*; import net.jqwik.api.providers.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; /** @@ -15,7 +17,7 @@ * of a given type {@code T} from the type's available constructors and factory methods. */ @API(status = MAINTAINED, since = "1.8.0") -public interface TraverseArbitrary extends Arbitrary { +public interface TraverseArbitrary extends Arbitrary { /** * A traverser describes how to travers a given type by providing a hook to diff --git a/api/src/main/java/net/jqwik/api/arbitraries/TypeArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/TypeArbitrary.java index d5101fc32..0ea63796a 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/TypeArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/TypeArbitrary.java @@ -7,6 +7,8 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; /** @@ -24,7 +26,7 @@ * @see net.jqwik.api.domains.DomainContext */ @API(status = MAINTAINED, since = "1.2") -public interface TypeArbitrary extends Arbitrary { +public interface TypeArbitrary extends Arbitrary { /** * Add public constructors of class {@code T} to be used diff --git a/api/src/main/java/net/jqwik/api/statistics/StatisticsCoverage.java b/api/src/main/java/net/jqwik/api/statistics/StatisticsCoverage.java index e841d5978..03856d196 100644 --- a/api/src/main/java/net/jqwik/api/statistics/StatisticsCoverage.java +++ b/api/src/main/java/net/jqwik/api/statistics/StatisticsCoverage.java @@ -80,7 +80,7 @@ interface CoverageChecker { * @param query A {@link Predicate} that takes the collected values as parameter * and returns true if the specific values shall be counted. */ - CoverageChecker checkQuery(Predicate> query); + CoverageChecker checkQuery(Predicate> query); /** * Match collected values against a regular expression. diff --git a/documentation/src/docs/include/customized-parameter-generation.md b/documentation/src/docs/include/customized-parameter-generation.md index 4970f3270..264bf2a8c 100644 --- a/documentation/src/docs/include/customized-parameter-generation.md +++ b/documentation/src/docs/include/customized-parameter-generation.md @@ -1051,14 +1051,14 @@ either [annotating parameters with `@UniqueElements`](#unique-elements) or by using one of the many `uniqueness(..)` configuration methods for collections and collection-like types: -- `ListArbitrary.uniqueElements(Function)` +- `ListArbitrary.uniqueElements(Function)` - `ListArbitrary.uniqueElements()` -- `SetArbitrary.uniqueElements(Function)` -- `StreamArbitrary.uniqueElements(Function)` +- `SetArbitrary.uniqueElements(Function)` +- `StreamArbitrary.uniqueElements(Function)` - `StreamArbitrary.uniqueElements()` -- `IteratorArbitrary.uniqueElements(Function)` +- `IteratorArbitrary.uniqueElements(Function)` - `IteratorArbitrary.uniqueElements()` -- `ArrayArbitrary.uniqueElements(Function)` +- `ArrayArbitrary.uniqueElements(Function)` - `ArrayArbitrary.uniqueElements()` - `MapArbitrary.uniqueKeys(Function)` - `MapArbitrary.uniqueValues(Function)` diff --git a/documentation/src/test/java/net/jqwik/docs/statistics/StatisticsCoverageExamples.java b/documentation/src/test/java/net/jqwik/docs/statistics/StatisticsCoverageExamples.java index 36762d99d..298371e65 100644 --- a/documentation/src/test/java/net/jqwik/docs/statistics/StatisticsCoverageExamples.java +++ b/documentation/src/test/java/net/jqwik/docs/statistics/StatisticsCoverageExamples.java @@ -57,7 +57,10 @@ void queryStatistics(@ForAll int anInt) { Statistics.collect(anInt); Statistics.coverage(coverage -> { - Predicate> isZero = params -> params.get(0) == 0; + // Note: coverage.checkQuery is untuped as it requires Predicate that must support **any** object + // So we can't have Predicate> here as checkQuery would not be able to call our + // predicate with Object values. + Predicate> isZero = params -> (Integer) params.get(0) == 0; coverage.checkQuery(isZero).percentage(p -> p > 5.0); }); } diff --git a/engine/src/main/java/net/jqwik/engine/facades/ArbitrariesFacadeImpl.java b/engine/src/main/java/net/jqwik/engine/facades/ArbitrariesFacadeImpl.java index 00eab6625..f4a318285 100644 --- a/engine/src/main/java/net/jqwik/engine/facades/ArbitrariesFacadeImpl.java +++ b/engine/src/main/java/net/jqwik/engine/facades/ArbitrariesFacadeImpl.java @@ -16,6 +16,8 @@ import net.jqwik.engine.properties.arbitraries.randomized.*; import net.jqwik.engine.properties.stateful.*; +import org.jspecify.annotations.*; + import static net.jqwik.engine.properties.arbitraries.ArbitrariesSupport.*; /** @@ -24,12 +26,12 @@ public class ArbitrariesFacadeImpl extends Arbitraries.ArbitrariesFacade { @Override - public Arbitrary just(T value) { + public Arbitrary just(T value) { return new JustArbitrary<>(value); } @Override - public Arbitrary oneOf(Collection> choices) { + public Arbitrary oneOf(Collection> choices) { return new OneOfArbitrary<>(choices); } @@ -39,8 +41,8 @@ public ActionSequenceArbitrary sequences(Arbitrary> a } @Override - public Arbitrary frequencyOf(List>> frequencies) { - List>> aboveZeroFrequencies = + public Arbitrary frequencyOf(List>> frequencies) { + List>> aboveZeroFrequencies = frequencies.stream().filter(f -> f.get1() > 0).collect(Collectors.toList()); if (aboveZeroFrequencies.size() == 1) { @@ -105,12 +107,12 @@ public CharacterArbitrary chars() { } @Override - public Arbitrary lazy(Supplier> arbitrarySupplier) { + public Arbitrary lazy(Supplier> arbitrarySupplier) { return new LazyArbitrary<>(arbitrarySupplier); } @Override - public Arbitrary lazyOf(List>> suppliers) { + public Arbitrary lazyOf(List>> suppliers) { int hashIdentifier = calculateIdentifier(suppliers.size()); return LazyOfArbitrary.of(hashIdentifier, suppliers); } @@ -142,12 +144,12 @@ public Arbitrary> shuffle(List values) { } @Override - public Arbitrary fromGenerator(IntFunction> generatorSupplier) { + public Arbitrary fromGenerator(IntFunction> generatorSupplier) { return new FromGeneratorWithSizeArbitrary<>(generatorSupplier); } @Override - public Arbitrary frequency(List> frequencies) { + public Arbitrary frequency(List> frequencies) { List> frequenciesAbove0 = frequencies.stream() .filter(f -> f.get1() > 0) .collect(Collectors.toList()); @@ -259,9 +261,9 @@ private static Set> createDefaultArbitraries( } @Override - public Arbitrary recursive( - Supplier> base, - Function, Arbitrary> recur, + public Arbitrary recursive( + Supplier> base, + Function, ? extends Arbitrary> recur, int minDepth, int maxDepth ) { @@ -285,8 +287,8 @@ public Arbitrary recursive( } private Arbitrary recursive( - Supplier> base, - Function, Arbitrary> recur, + Supplier> base, + Function, ? extends Arbitrary> recur, int depth ) { return new RecursiveArbitrary<>(base, recur, depth); diff --git a/engine/src/main/java/net/jqwik/engine/facades/CombinatorsFacadeImpl.java b/engine/src/main/java/net/jqwik/engine/facades/CombinatorsFacadeImpl.java index d11d16de1..27b8dfaa0 100644 --- a/engine/src/main/java/net/jqwik/engine/facades/CombinatorsFacadeImpl.java +++ b/engine/src/main/java/net/jqwik/engine/facades/CombinatorsFacadeImpl.java @@ -81,7 +81,7 @@ public Combinators.Combinator8 Combinators.ListCombinator combineList(List> listOfArbitraries) { + public Combinators.ListCombinator combineList(List> listOfArbitraries) { return new DefaultListCombinator<>(listOfArbitraries); } diff --git a/engine/src/main/java/net/jqwik/engine/hooks/statistics/StatisticsCollectorImpl.java b/engine/src/main/java/net/jqwik/engine/hooks/statistics/StatisticsCollectorImpl.java index 95b5725b6..cee4275a6 100644 --- a/engine/src/main/java/net/jqwik/engine/hooks/statistics/StatisticsCollectorImpl.java +++ b/engine/src/main/java/net/jqwik/engine/hooks/statistics/StatisticsCollectorImpl.java @@ -80,7 +80,7 @@ private StatisticsEntry statisticsEntry(Object[] values) { .orElse(StatisticsEntryImpl.nullFor(key)); } - private StatisticsEntry query(Predicate> query, int countAll) { + private StatisticsEntry query(Predicate> query, int countAll) { return statisticsEntries() .stream() .filter(entry -> { @@ -198,9 +198,9 @@ public CoverageChecker check(Object... values) { @SuppressWarnings("unchecked") @Override - public CoverageChecker checkQuery(Predicate> query) { + public CoverageChecker checkQuery(Predicate> query) { int countAll = countAllCollects(); - StatisticsEntry entry = query((Predicate>) query, countAll); + StatisticsEntry entry = query(query, countAll); return new CoverageCheckerImpl(label, entry, countAll); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultArrayArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultArrayArbitrary.java index 0f6e55912..4b7fadece 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultArrayArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultArrayArbitrary.java @@ -95,7 +95,7 @@ public ArrayArbitrary uniqueElements() { } @Override - public ArrayArbitrary uniqueElements(Function by) { + public ArrayArbitrary uniqueElements(Function by) { FeatureExtractor featureExtractor = by::apply; return (ArrayArbitrary) super.uniqueElements(featureExtractor); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultFunctionArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultFunctionArbitrary.java index a275971e0..e21459f08 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultFunctionArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultFunctionArbitrary.java @@ -13,7 +13,7 @@ public class DefaultFunctionArbitrary extends TypedCloneable implements Fu private final Class functionalType; private final Arbitrary resultArbitrary; - private final List>, Function, R>>> conditions = new ArrayList<>(); + private final List>, Function, ? extends R>>> conditions = new ArrayList<>(); public DefaultFunctionArbitrary(Class functionalType, Arbitrary resultArbitrary) { this.functionalType = functionalType; @@ -52,15 +52,15 @@ public boolean equals(Object o) { } private boolean conditionsAreEqual( - List>, Function, R>>> left, - List>, Function, R>>> right + List>, Function, ? extends R>>> left, + List>, Function, ? extends R>>> right ) { if (left.size() != right.size()) { return false; } for (int i = 0; i < left.size(); i++) { - Tuple2>, Function, R>> leftCondition = left.get(i); - Tuple2>, Function, R>> rightCondition = right.get(i); + Tuple2>, Function, ? extends R>> leftCondition = left.get(i); + Tuple2>, Function, ? extends R>> rightCondition = right.get(i); if (!LambdaSupport.areEqual(leftCondition.get1(), rightCondition.get1())) { return false; } @@ -94,14 +94,14 @@ private ConstantFunctionGenerator createConstantFunctionGenerator(final in } @Override - public FunctionArbitrary when(Predicate> parameterCondition, Function, R> answer) { + public FunctionArbitrary when(Predicate> parameterCondition, Function, ? extends R> answer) { DefaultFunctionArbitrary clone = typedClone(); clone.conditions.addAll(this.conditions); clone.addCondition(Tuple.of(parameterCondition, answer)); return clone; } - private void addCondition(Tuple2>, Function, R>> condition) { + private void addCondition(Tuple2>, Function, ? extends R>> condition) { conditions.add(condition); } } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultIteratorArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultIteratorArbitrary.java index ffef597f4..cd14bc789 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultIteratorArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultIteratorArbitrary.java @@ -60,7 +60,7 @@ public IteratorArbitrary withSizeDistribution(RandomDistribution distribution } @Override - public IteratorArbitrary uniqueElements(Function by) { + public IteratorArbitrary uniqueElements(Function by) { FeatureExtractor featureExtractor = by::apply; return (IteratorArbitrary) super.uniqueElements(featureExtractor); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultListArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultListArbitrary.java index 0691b3587..389031013 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultListArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultListArbitrary.java @@ -12,7 +12,7 @@ import org.jspecify.annotations.*; -public class DefaultListArbitrary extends MultivalueArbitraryBase> implements ListArbitrary { +public class DefaultListArbitrary extends MultivalueArbitraryBase> implements ListArbitrary { public DefaultListArbitrary(Arbitrary elementArbitrary) { super(elementArbitrary); @@ -68,9 +68,9 @@ public Arbitrary> mapEach(BiFunction, T, U> mapper) { // TODO: Remove duplication with DefaultSetArbitrary.flatMapEach() @Override - public Arbitrary> flatMapEach(BiFunction, T, Arbitrary> flatMapper) { + public Arbitrary> flatMapEach(BiFunction, ? super T, ? extends Arbitrary> flatMapper) { return this.flatMap(elements -> { - List> arbitraries = + List> arbitraries = elements.stream() .map(e -> flatMapper.apply(elements, e)) .collect(Collectors.toList()); @@ -79,7 +79,7 @@ public Arbitrary> flatMapEach(BiFunction, T, Arbitrary> f } @Override - public ListArbitrary<@Nullable T> uniqueElements(Function<@Nullable T, Object> by) { + public ListArbitrary uniqueElements(Function by) { FeatureExtractor featureExtractor = by::apply; return (ListArbitrary) super.uniqueElements(featureExtractor); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultSetArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultSetArbitrary.java index ad48dd029..5ede6e77f 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultSetArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultSetArbitrary.java @@ -93,7 +93,7 @@ public SetArbitrary uniqueElements() { } @Override - public SetArbitrary uniqueElements(Function by) { + public SetArbitrary uniqueElements(Function by) { FeatureExtractor featureExtractor = by::apply; return (SetArbitrary) super.uniqueElements(featureExtractor); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultStreamArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultStreamArbitrary.java index fa289d647..c706cdb5a 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultStreamArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultStreamArbitrary.java @@ -62,7 +62,7 @@ public StreamArbitrary withSizeDistribution(RandomDistribution distribution) } @Override - public StreamArbitrary uniqueElements(Function by) { + public StreamArbitrary uniqueElements(Function by) { FeatureExtractor featureExtractor = by::apply; return (StreamArbitrary) super.uniqueElements(featureExtractor); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/EdgeCasesSupport.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/EdgeCasesSupport.java index 2bb22e671..1f0ad50c9 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/EdgeCasesSupport.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/EdgeCasesSupport.java @@ -52,7 +52,7 @@ public static EdgeCases choose(final List values, int maxEdgeCases) { return EdgeCasesSupport.fromShrinkables(shrinkables); } - public static EdgeCases concatFrom(final List> arbitraries, int maxEdgeCases) { + public static EdgeCases concatFrom(final List> arbitraries, int maxEdgeCases) { List>> shrinkables = new ArrayList<>(); for (Arbitrary arbitrary : arbitraries) { shrinkables.add(new ChooseValueShrinkable<>(arbitrary, arbitraries)); diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FrequencyOfArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FrequencyOfArbitrary.java index 4c884eca7..2fb69bcc5 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FrequencyOfArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FrequencyOfArbitrary.java @@ -13,10 +13,10 @@ public class FrequencyOfArbitrary implements Arbitrary, SelfConfiguringArbitrary { - private final List>> frequencies; + private final List>> frequencies; private final boolean isGeneratorMemoizable; - public FrequencyOfArbitrary(List>> frequencies) { + public FrequencyOfArbitrary(List>> frequencies) { this.frequencies = frequencies; this.isGeneratorMemoizable = frequencies.stream().allMatch(t -> t.get2().isGeneratorMemoizable()); if (this.frequencies.isEmpty()) { diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FromGeneratorWithSizeArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FromGeneratorWithSizeArbitrary.java index 9497e236d..38971e03b 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FromGeneratorWithSizeArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FromGeneratorWithSizeArbitrary.java @@ -7,9 +7,9 @@ public class FromGeneratorWithSizeArbitrary implements Arbitrary { - private final IntFunction> supplier; + private final IntFunction> supplier; - public FromGeneratorWithSizeArbitrary(IntFunction> generatorSupplier) { + public FromGeneratorWithSizeArbitrary(IntFunction> generatorSupplier) { this.supplier = generatorSupplier; } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyArbitrary.java index 49dd53c5a..9da910f76 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyArbitrary.java @@ -8,11 +8,11 @@ import net.jqwik.api.providers.*; public class LazyArbitrary implements Arbitrary, SelfConfiguringArbitrary { - private final Supplier> arbitrarySupplier; + private final Supplier> arbitrarySupplier; private final List> configurations = new ArrayList<>(); private Arbitrary arbitrary; - public LazyArbitrary(Supplier> arbitrarySupplier) { + public LazyArbitrary(Supplier> arbitrarySupplier) { this.arbitrarySupplier = arbitrarySupplier; } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyOfArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyOfArbitrary.java index 4cd3798f1..9afd129f8 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyOfArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyOfArbitrary.java @@ -24,13 +24,13 @@ private static Store>> arbitrariesStore() { } @SuppressWarnings("unchecked") - public static Arbitrary of(int hashIdentifier, List>> suppliers) { + public static Arbitrary of(int hashIdentifier, List>> suppliers) { // It's important for good shrinking to work that the same arbitrary usage is handled by the same arbitrary instance LazyOfArbitrary arbitrary = arbitrariesStore().get().computeIfAbsent(hashIdentifier, ignore -> new LazyOfArbitrary<>(suppliers)); return (Arbitrary) arbitrary; } - private final List>> suppliers; + private final List>> suppliers; private final Deque>> generatedParts = new ArrayDeque<>(); @@ -45,7 +45,7 @@ private Store>> createGeneratorsStore() { } } - public LazyOfArbitrary(List>> suppliers) { + public LazyOfArbitrary(List>> suppliers) { this.suppliers = suppliers; } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/OneOfArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/OneOfArbitrary.java index 8c3eacb7b..a928246f6 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/OneOfArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/OneOfArbitrary.java @@ -16,8 +16,9 @@ public class OneOfArbitrary implements Arbitrary, SelfConfiguringArbitrary private final boolean isGeneratorMemoizable; @SuppressWarnings("unchecked") - public OneOfArbitrary(Collection> choices) { + public OneOfArbitrary(Collection> choices) { for (Arbitrary choice : choices) { + // TODO: double-check cast all.add((Arbitrary) choice); } isGeneratorMemoizable = all.stream().allMatch(Arbitrary::isGeneratorMemoizable); @@ -39,7 +40,7 @@ public boolean isGeneratorMemoizable() { } private RandomGenerator rawGeneration(int genSize, boolean withEmbeddedEdgeCases) { - List>> frequencies = + List>> frequencies = all.stream() .map(a -> Tuple.of(1, a)) .collect(Collectors.toList()); diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/RecursiveArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/RecursiveArbitrary.java index c713a968b..1494c3b00 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/RecursiveArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/RecursiveArbitrary.java @@ -7,8 +7,8 @@ import net.jqwik.api.support.*; public class RecursiveArbitrary implements Arbitrary { - private final Supplier> base; - private final Function, Arbitrary> recur; + private final Supplier> base; + private final Function, ? extends Arbitrary> recur; private final int depth; // Not used for exhaustive generation @@ -16,7 +16,7 @@ public class RecursiveArbitrary implements Arbitrary { private boolean isGeneratorMemoizable = true; - public RecursiveArbitrary(Supplier> base, Function, Arbitrary> recur, int depth) { + public RecursiveArbitrary(Supplier> base, Function, ? extends Arbitrary> recur, int depth) { this.base = base; this.recur = recur; this.depth = depth; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultListCombinator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultListCombinator.java index 8d4c84f5d..5c661c4f7 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultListCombinator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultListCombinator.java @@ -15,7 +15,7 @@ public class DefaultListCombinator implements Combinators.ListCombinator { protected final Arbitrary[] arbitraries; @SuppressWarnings("unchecked") - public DefaultListCombinator(List> listOfArbitraries) { + public DefaultListCombinator(List> listOfArbitraries) { this(listOfArbitraries.toArray(new Arbitrary[0])); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/ExhaustiveGenerators.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/ExhaustiveGenerators.java index e5281d736..2c8b50ca7 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/ExhaustiveGenerators.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/ExhaustiveGenerators.java @@ -97,7 +97,7 @@ public static Optional>> shuffle(List values, public static Optional> flatMap( ExhaustiveGenerator base, - Function> mapper, + Function> mapper, long maxNumberOfSamples ) { Optional optionalMaxCount = FlatMappedExhaustiveGenerator.calculateMaxCounts(base, mapper, maxNumberOfSamples); diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/FlatMappedExhaustiveGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/FlatMappedExhaustiveGenerator.java index 8241a4ada..3db50eaa9 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/FlatMappedExhaustiveGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/FlatMappedExhaustiveGenerator.java @@ -10,11 +10,11 @@ public class FlatMappedExhaustiveGenerator implements ExhaustiveGenerator { private final ExhaustiveGenerator baseGenerator; private final long maxCount; - private final Function> mapper; + private final Function> mapper; public static Optional calculateMaxCounts( ExhaustiveGenerator baseGenerator, - Function> mapper, + Function> mapper, long maxNumberOfSamples ) { long choices = 0; @@ -31,7 +31,7 @@ public static Optional calculateMaxCounts( return Optional.of(choices); } - public FlatMappedExhaustiveGenerator(ExhaustiveGenerator baseGenerator, long maxCount, Function> mapper) { + public FlatMappedExhaustiveGenerator(ExhaustiveGenerator baseGenerator, long maxCount, Function> mapper) { this.baseGenerator = baseGenerator; this.maxCount = maxCount; this.mapper = mapper; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/AbstractFunctionGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/AbstractFunctionGenerator.java index 67fcb862d..9edab461f 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/AbstractFunctionGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/AbstractFunctionGenerator.java @@ -13,12 +13,12 @@ abstract class AbstractFunctionGenerator implements RandomGenerator { final Class functionalType; final RandomGenerator resultGenerator; - final List>, Function, R>>> conditions; + final List>, Function, ? extends R>>> conditions; AbstractFunctionGenerator( Class functionalType, RandomGenerator resultGenerator, - List>, Function, R>>> conditions + List>, Function, ? extends R>>> conditions ) { this.functionalType = functionalType; this.resultGenerator = resultGenerator; @@ -70,7 +70,7 @@ private Object handleToStringOfConstantMethod(final R constant) { // Returns result wrapped in array to allow null as result protected Optional conditionalResult(Object[] args) { Optional conditionalResult = Optional.empty(); - for (Tuple2>, Function, R>> condition : conditions) { + for (Tuple2>, Function, ? extends R>> condition : conditions) { List params = Arrays.asList(args); if (condition.get1().test(params)) { Object[] result = new Object[]{condition.get2().apply(params)}; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/ConstantFunctionGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/ConstantFunctionGenerator.java index 31743d2b8..4343f8304 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/ConstantFunctionGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/ConstantFunctionGenerator.java @@ -11,7 +11,7 @@ public class ConstantFunctionGenerator extends AbstractFunctionGenerator functionalType, RandomGenerator resultGenerator, - List>, Function, R>>> conditions + List>, Function, ? extends R>>> conditions ) { super(functionalType, resultGenerator, conditions); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FrequencyGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FrequencyGenerator.java index 6f0ccd185..cedb08da0 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FrequencyGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FrequencyGenerator.java @@ -8,7 +8,7 @@ class FrequencyGenerator extends ChooseRandomlyByFrequency implements RandomGenerator { - FrequencyGenerator(List> frequencies) { + FrequencyGenerator(List> frequencies) { super(frequencies); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FunctionGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FunctionGenerator.java index f1750e2f5..12022209d 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FunctionGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FunctionGenerator.java @@ -18,7 +18,7 @@ public class FunctionGenerator extends AbstractFunctionGenerator { public FunctionGenerator( Class functionalType, RandomGenerator resultGenerator, - List>, Function, R>>> conditions + List>, Function, ? extends R>>> conditions ) { super(functionalType, resultGenerator, conditions); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/RandomGenerators.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/RandomGenerators.java index cf1a30fd2..5e6fb3a1e 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/RandomGenerators.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/RandomGenerators.java @@ -174,12 +174,12 @@ public static RandomGenerator samples(T[] samples) { return samplesFromShrinkables(shrinkables); } - public static RandomGenerator frequency(List> frequencies) { + public static RandomGenerator frequency(List> frequencies) { return new FrequencyGenerator<>(frequencies); } public static RandomGenerator frequencyOf( - List>> frequencies, + List>> frequencies, int genSize, boolean withEmbeddedEdgeCases ) { diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/ChooseValueShrinkable.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/ChooseValueShrinkable.java index 96ee7c9ca..c3bf061a7 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/ChooseValueShrinkable.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/ChooseValueShrinkable.java @@ -7,9 +7,9 @@ public class ChooseValueShrinkable extends AbstractValueShrinkable { - private final List values; + private final List values; - public ChooseValueShrinkable(T value, List values) { + public ChooseValueShrinkable(T value, List values) { super(value); this.values = values; } diff --git a/engine/src/main/java/net/jqwik/engine/support/ChooseRandomlyByFrequency.java b/engine/src/main/java/net/jqwik/engine/support/ChooseRandomlyByFrequency.java index 891abaf78..1b1faf86e 100644 --- a/engine/src/main/java/net/jqwik/engine/support/ChooseRandomlyByFrequency.java +++ b/engine/src/main/java/net/jqwik/engine/support/ChooseRandomlyByFrequency.java @@ -11,7 +11,7 @@ public class ChooseRandomlyByFrequency implements Function { private int size = 0; private List valuesToChooseFrom; - public ChooseRandomlyByFrequency(List> frequencies) { + public ChooseRandomlyByFrequency(List> frequencies) { calculateUpperBorders(frequencies); if (size <= 0) { throw new JqwikException(String.format( @@ -25,11 +25,11 @@ protected List possibleValues() { return valuesToChooseFrom; } - private void calculateUpperBorders(List> frequencies) { + private void calculateUpperBorders(List> frequencies) { List values = new ArrayList<>(frequencies.size()); // Zero-frequency elements are possible, so we start with a list, and transform to array later List upperBounds = new ArrayList<>(frequencies.size()); - for (Tuple.Tuple2 tuple : frequencies) { + for (Tuple.Tuple2 tuple : frequencies) { int frequency = tuple.get1(); if (frequency <= 0) continue; diff --git a/engine/src/test/java/net/jqwik/api/statistics/StatisticsCoverageTests.java b/engine/src/test/java/net/jqwik/api/statistics/StatisticsCoverageTests.java index fede04bb1..1e5cf24f7 100644 --- a/engine/src/test/java/net/jqwik/api/statistics/StatisticsCoverageTests.java +++ b/engine/src/test/java/net/jqwik/api/statistics/StatisticsCoverageTests.java @@ -240,7 +240,7 @@ void checkCountForQuery(@ForAll @IntRange(min = 1, max = 100) int anInt) { Statistics.collect(anInt); Statistics.coverage(coverage -> { - Predicate> query = params -> params.get(0) <= 10; + Predicate> query = params -> (Integer) params.get(0) <= 10; coverage.checkQuery(query).count(c -> c == 10); }); } @@ -250,7 +250,7 @@ void checkPercentageForQuery(@ForAll @IntRange(min = 1, max = 100) int anInt) { Statistics.collect(anInt); Statistics.coverage(coverage -> { - Predicate> query = params -> params.get(0) <= 50; + Predicate> query = params -> (Integer) params.get(0) <= 50; coverage.checkQuery(query).percentage(p -> { assertThat(p).isCloseTo(50.0, Offset.offset(0.1)); }); @@ -263,7 +263,7 @@ void checkCountsAreAddedUp(@ForAll @IntRange(min = 1, max = 100) int anInt) { Statistics.label("twice").collect(anInt); Statistics.label("twice").coverage(coverage -> { - Predicate> query = params -> params.get(0) <= 10; + Predicate> query = params -> (Integer) params.get(0) <= 10; coverage.checkQuery(query).count(c -> c == 20); }); } @@ -274,7 +274,7 @@ void queryWithWrongTypeFails(@ForAll int anInt) { Statistics.collect(anInt); Statistics.coverage(coverage -> { - Predicate> query = params -> !params.get(0).isEmpty(); + Predicate> query = params -> !((String)params.get(0)).isEmpty(); coverage.checkQuery(query).count(c -> c == 10); }); } diff --git a/kotlin/build.gradle b/kotlin/build.gradle index 311c9d46a..1b849e9f8 100644 --- a/kotlin/build.gradle +++ b/kotlin/build.gradle @@ -78,6 +78,7 @@ signing { tasks.withType(KotlinCompile).configureEach { compilerOptions { freeCompilerArgs = [ + "-Xnullability-annotations=@org.jspecify.annotations:strict", "-Xemit-jvm-type-annotations" // Required for annotations on type variables ] apiVersion = KotlinVersion.KOTLIN_1_9 diff --git a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/BuildersExtensions.kt b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/BuildersExtensions.kt index a25baa473..b8a2771a8 100644 --- a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/BuildersExtensions.kt +++ b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/BuildersExtensions.kt @@ -9,10 +9,8 @@ import java.util.function.BiFunction * Convenience function for Kotlin to not use backticked `in` function. */ @API(status = API.Status.EXPERIMENTAL, since = "1.6.0") -fun BuilderCombinator.use(arbitrary: Arbitrary, combinator: (B, T) -> B): BuilderCombinator +fun BuilderCombinator.use(arbitrary: Arbitrary, combinator: (B, T) -> B): BuilderCombinator where B : Any { - // This explicit conversion form combinator to toFunction is necessary - // since the implicit conversion (just handing in combinator) creates nullability warning - val toFunction: BiFunction = BiFunction { b, t -> combinator(b, t) } + val toFunction = BiFunction { b, t -> combinator(b, t) } return this.use(arbitrary).`in`(toFunction) } diff --git a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/SequenceArbitrary.kt b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/SequenceArbitrary.kt index 9a0b023e5..1b75d2170 100644 --- a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/SequenceArbitrary.kt +++ b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/SequenceArbitrary.kt @@ -15,7 +15,7 @@ import java.util.function.Function * of type [Sequence] */ @API(status = EXPERIMENTAL, since = "1.6.0") -class SequenceArbitrary(elementArbitrary: Arbitrary) : ArbitraryDecorator>(), +class SequenceArbitrary(elementArbitrary: Arbitrary) : ArbitraryDecorator>(), SizableArbitrary> { private var listArbitrary: ListArbitrary @@ -80,7 +80,7 @@ class SequenceArbitrary(elementArbitrary: Arbitrary) : ArbitraryDecorator< * * @return new arbitrary instance */ - fun uniqueElements(by: Function): SequenceArbitrary { + fun uniqueElements(by: Function): SequenceArbitrary { val clone = typedClone>() clone.listArbitrary = listArbitrary.uniqueElements(by) return clone diff --git a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/SizableArbitraryExtensions.kt b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/SizableArbitraryExtensions.kt index 67d802fd9..0b9ddd1c9 100644 --- a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/SizableArbitraryExtensions.kt +++ b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/SizableArbitraryExtensions.kt @@ -19,4 +19,4 @@ fun IteratorArbitrary.ofSize(range: IntRange): IteratorArbitrary = ofM fun MapArbitrary.ofSize(range: IntRange): MapArbitrary = ofMinSize(range.first).ofMaxSize(range.last) @API(status = API.Status.EXPERIMENTAL, since = "1.6.0") -fun ArrayArbitrary.ofSize(range: IntRange): ArrayArbitrary = ofMinSize(range.first).ofMaxSize(range.last) +fun ArrayArbitrary.ofSize(range: IntRange): ArrayArbitrary = ofMinSize(range.first).ofMaxSize(range.last) diff --git a/kotlin/src/test/kotlin/net/jqwik/kotlin/CollectionExtensionsTests.kt b/kotlin/src/test/kotlin/net/jqwik/kotlin/CollectionExtensionsTests.kt index 531372020..b0115584b 100644 --- a/kotlin/src/test/kotlin/net/jqwik/kotlin/CollectionExtensionsTests.kt +++ b/kotlin/src/test/kotlin/net/jqwik/kotlin/CollectionExtensionsTests.kt @@ -1,7 +1,7 @@ package net.jqwik.kotlin -import net.jqwik.api.Example -import net.jqwik.api.ForAll +import net.jqwik.api.* +import net.jqwik.kotlin.api.any import net.jqwik.kotlin.api.anySubset import net.jqwik.kotlin.api.anyValue import net.jqwik.kotlin.api.ofSize diff --git a/kotlin/src/test/kotlin/net/jqwik/kotlin/InternalModifierTests.kt b/kotlin/src/test/kotlin/net/jqwik/kotlin/InternalModifierTests.kt index 62d84be0b..bed36587d 100644 --- a/kotlin/src/test/kotlin/net/jqwik/kotlin/InternalModifierTests.kt +++ b/kotlin/src/test/kotlin/net/jqwik/kotlin/InternalModifierTests.kt @@ -1,12 +1,10 @@ package net.jqwik.kotlin -import net.jqwik.api.ForAll -import net.jqwik.api.Property -import net.jqwik.api.PropertyDefaults -import net.jqwik.api.Provide +import net.jqwik.api.* import net.jqwik.api.lifecycle.AfterContainer import net.jqwik.api.lifecycle.AfterProperty import net.jqwik.kotlin.api.any +import kotlin.random.Random @PropertyDefaults(tries = 10) internal class InternalModifierTests { From 949f47265ca5d7c5d01b76fad6286cdc6fd8d471 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Fri, 7 Jun 2024 15:15:27 +0300 Subject: [PATCH 2/5] Fix more nullability issues --- .../main/java/net/jqwik/api/Arbitraries.java | 20 +++---- .../main/java/net/jqwik/api/Arbitrary.java | 44 +++++++------- .../java/net/jqwik/api/ArbitrarySupplier.java | 6 +- api/src/main/java/net/jqwik/api/Builders.java | 5 +- .../main/java/net/jqwik/api/Combinators.java | 58 +++++++++---------- .../main/java/net/jqwik/api/EdgeCases.java | 13 +++-- .../net/jqwik/api/ExhaustiveGenerator.java | 15 ++--- .../main/java/net/jqwik/api/Falsifier.java | 6 +- .../main/java/net/jqwik/api/Functions.java | 6 +- .../java/net/jqwik/api/RandomGenerator.java | 28 ++++----- .../main/java/net/jqwik/api/Shrinkable.java | 20 +++---- .../java/net/jqwik/api/ShrinkingDistance.java | 7 +-- api/src/main/java/net/jqwik/api/Table.java | 20 ++++--- api/src/main/java/net/jqwik/api/Tuple.java | 16 ++--- .../api/arbitraries/ArbitraryDecorator.java | 4 +- .../api/arbitraries/FunctionArbitrary.java | 2 +- .../jqwik/api/arbitraries/ListArbitrary.java | 2 +- .../jqwik/api/arbitraries/SetArbitrary.java | 4 +- .../api/arbitraries/StreamableArbitrary.java | 2 +- .../jqwik/api/arbitraries/TypeArbitrary.java | 4 +- .../jqwik/api/arbitraries/package-info.java | 2 +- .../configurators/ArbitraryConfigurator.java | 4 +- .../ArbitraryConfiguratorBase.java | 7 ++- .../SelfConfiguringArbitrary.java | 4 +- .../jqwik/api/configurators/package-info.java | 2 +- .../jqwik/api/constraints/package-info.java | 2 +- .../net/jqwik/api/domains/package-info.java | 2 +- .../api/facades/ShrinkingSupportFacade.java | 14 +++-- .../api/facades/TestingSupportFacade.java | 4 +- .../net/jqwik/api/facades/package-info.java | 4 +- .../net/jqwik/api/footnotes/package-info.java | 2 +- .../java/net/jqwik/api/lifecycle/Store.java | 16 ++--- .../main/java/net/jqwik/api/package-info.java | 2 +- .../net/jqwik/api/providers/package-info.java | 2 +- .../net/jqwik/api/sessions/package-info.java | 2 +- .../main/java/net/jqwik/api/state/Action.java | 20 ++++--- .../net/jqwik/api/state/ActionBuilder.java | 13 ++--- .../java/net/jqwik/api/state/ActionChain.java | 8 +-- .../main/java/net/jqwik/api/state/Chain.java | 8 ++- .../net/jqwik/api/state/ChainArbitrary.java | 2 +- .../net/jqwik/api/state/ChangeDetector.java | 13 +++-- .../net/jqwik/api/state/Transformation.java | 4 +- .../java/net/jqwik/api/state/Transformer.java | 12 ++-- .../net/jqwik/api/state/package-info.java | 2 +- .../java/net/jqwik/api/stateful/Action.java | 3 +- .../jqwik/api/stateful/ActionSequence.java | 2 +- .../api/stateful/ActionSequenceArbitrary.java | 4 +- .../net/jqwik/api/stateful/Invariant.java | 3 +- .../net/jqwik/api/stateful/package-info.java | 2 +- .../api/statistics/StatisticsCoverage.java | 12 ++-- .../jqwik/api/statistics/package-info.java | 2 +- .../jqwik/api/support/CollectorsSupport.java | 3 +- .../jqwik/api/support/HashCodeSupport.java | 2 +- .../customized-parameter-generation.md | 2 +- .../OddConfigurator.java | 4 +- .../jqwik/engine/descriptor/package-info.java | 4 ++ .../jqwik/engine/discovery/package-info.java | 4 ++ .../discovery/predicates/package-info.java | 4 ++ .../engine/discovery/specs/package-info.java | 4 ++ .../execution/ContainerInstancesCreator.java | 5 +- .../engine/execution/GenerationInfo.java | 14 +++-- .../lifecycle/CurrentDomainContext.java | 4 +- .../lifecycle/CurrentTestDescriptor.java | 3 +- .../lifecycle/PlainExecutionResult.java | 10 ++-- .../execution/lifecycle/ScopedStore.java | 4 +- .../execution/lifecycle/StoreRepository.java | 13 +++-- .../execution/lifecycle/package-info.java | 4 ++ .../jqwik/engine/execution/package-info.java | 4 ++ .../execution/pipeline/package-info.java | 4 ++ .../reporting/ParameterChangesDetector.java | 12 ++-- .../execution/reporting/package-info.java | 4 ++ .../engine/facades/ActionChainFacadeImpl.java | 4 +- .../engine/facades/ArbitrariesFacadeImpl.java | 30 +++++----- .../engine/facades/ArbitraryFacadeImpl.java | 38 ++++++------ .../jqwik/engine/facades/ChainFacadeImpl.java | 4 +- .../engine/facades/CombinatorsFacadeImpl.java | 4 +- .../engine/facades/EdgeCasesFacadeImpl.java | 4 +- .../ExhaustiveGeneratorFacadeImpl.java | 10 ++-- .../engine/facades/FunctionsFacadeImpl.java | 4 +- .../net/jqwik/engine/facades/Memoize.java | 8 ++- .../facades/RandomGeneratorFacadeImpl.java | 18 +++--- .../engine/facades/SampleStreamFacade.java | 9 +-- .../engine/facades/ShrinkableFacadeImpl.java | 10 ++-- .../facades/ShrinkingSupportFacadeImpl.java | 24 ++++---- .../jqwik/engine/facades/StoreFacadeImpl.java | 7 ++- .../facades/TestingSupportFacadeImpl.java | 4 +- .../jqwik/engine/facades/package-info.java | 4 ++ .../engine/hooks/lifecycle/package-info.java | 4 ++ .../net/jqwik/engine/hooks/package-info.java | 4 ++ .../statistics/StatisticsCollectorImpl.java | 12 ++-- .../engine/hooks/statistics/package-info.java | 4 ++ .../java/net/jqwik/engine/package-info.java | 4 ++ .../engine/properties/FeatureExtractor.java | 10 ++-- .../properties/PropertyCheckResult.java | 23 ++++---- .../RandomizedShrinkablesGenerator.java | 2 +- .../engine/properties/UniquenessChecker.java | 10 ++-- .../arbitraries/ArbitraryCollect.java | 4 +- .../arbitraries/ArbitraryFilter.java | 4 +- .../arbitraries/ArbitraryFlatMap.java | 4 +- .../properties/arbitraries/ArbitraryMap.java | 8 ++- .../arbitraries/CreateArbitrary.java | 4 +- .../arbitraries/DefaultArrayArbitrary.java | 4 +- .../arbitraries/DefaultListArbitrary.java | 4 +- .../arbitraries/DefaultSetArbitrary.java | 4 +- .../arbitraries/DefaultTypeArbitrary.java | 10 ++-- .../arbitraries/EdgeCasesSupport.java | 30 +++++----- .../arbitraries/FrequencyArbitrary.java | 6 +- .../arbitraries/FrequencyOfArbitrary.java | 4 +- .../GenericEdgeCasesConfiguration.java | 8 +-- .../IntegralGeneratingArbitrary.java | 2 +- .../properties/arbitraries/JustArbitrary.java | 6 +- .../arbitraries/LazyOfArbitrary.java | 4 +- .../arbitraries/MappedEdgeCasesConsumer.java | 2 +- .../arbitraries/MultivalueArbitraryBase.java | 4 +- .../arbitraries/ReportableStream.java | 8 ++- .../arbitraries/UseGeneratorsArbitrary.java | 4 +- .../combinations/CombineArbitrary.java | 14 ++--- .../combinations/DefaultCombinator2.java | 22 +++---- .../combinations/DefaultCombinator3.java | 20 +++---- .../combinations/DefaultCombinator4.java | 22 +++---- .../combinations/DefaultCombinator5.java | 22 +++---- .../combinations/DefaultCombinator6.java | 22 +++---- .../combinations/DefaultCombinator7.java | 22 +++---- .../combinations/DefaultCombinator8.java | 22 +++---- .../combinations/DefaultListCombinator.java | 20 +++---- .../combinations/package-info.java | 4 ++ .../CombinedExhaustiveGenerator.java | 4 +- .../exhaustive/ExhaustiveGenerators.java | 22 +++---- .../FilteredExhaustiveGenerator.java | 4 +- .../FlatMappedExhaustiveGenerator.java | 4 +- .../IgnoreExceptionExhaustiveGenerator.java | 4 +- .../IterableBasedExhaustiveGenerator.java | 4 +- .../exhaustive/ListExhaustiveGenerator.java | 4 +- .../exhaustive/MappedExhaustiveGenerator.java | 8 ++- .../PermutationExhaustiveGenerator.java | 6 +- .../exhaustive/SetExhaustiveGenerator.java | 4 +- .../WithNullExhaustiveGenerator.java | 4 +- .../arbitraries/exhaustive/package-info.java | 4 ++ .../properties/arbitraries/package-info.java | 4 ++ .../randomized/CollectGenerator.java | 4 +- .../randomized/ContainerGenerator.java | 8 +-- .../randomized/FilteredGenerator.java | 4 +- .../randomized/RandomGenerators.java | 48 +++++++-------- .../randomized/WithEdgeCasesGenerator.java | 4 +- .../arbitraries/randomized/package-info.java | 4 ++ .../UniqueElementsConfigurator.java | 16 ++--- .../configurators/package-info.java | 4 ++ .../jqwik/engine/properties/package-info.java | 4 ++ .../AggressiveSizeOfListShrinker.java | 12 ++-- .../shrinking/CollectShrinkable.java | 12 ++-- .../shrinking/CombinedShrinkable.java | 4 +- .../shrinking/FilteredShrinkable.java | 4 +- .../FixedValueFlatMappedShrinkable.java | 10 ++-- .../shrinking/FlatMappedShrinkable.java | 12 ++-- .../shrinking/MappedShrinkable.java | 4 +- .../OneAfterTheOtherParameterShrinker.java | 4 +- .../shrinking/PropertyShrinker.java | 2 +- .../shrinking/ShrinkableContainer.java | 17 +++--- .../properties/shrinking/ShrinkableList.java | 8 +-- .../properties/shrinking/ShrinkableSet.java | 12 ++-- .../shrinking/ShrinkableString.java | 11 ++-- .../shrinking/ShrinkingCommons.java | 12 ++-- .../shrinking/SizeOfListShrinker.java | 20 ++++--- .../properties/shrinking/Unshrinkable.java | 4 +- .../properties/shrinking/package-info.java | 4 ++ .../state/DefaultChainArbitrary.java | 6 +- .../state/SequentialActionChain.java | 14 ++--- .../properties/state/ShrinkableChain.java | 20 +++---- .../state/ShrinkableChainIteration.java | 10 ++-- .../engine/properties/state/package-info.java | 4 ++ .../properties/stateful/ActionGenerator.java | 4 +- .../stateful/RandomActionGenerator.java | 4 +- .../stateful/ShrinkablesActionGenerator.java | 4 +- .../properties/stateful/package-info.java | 4 ++ .../jqwik/engine/providers/package-info.java | 4 ++ .../jqwik/engine/recording/package-info.java | 4 ++ .../jqwik/engine/support/Combinatorics.java | 26 +++++---- .../engine/support/JqwikStreamSupport.java | 10 ++-- .../engine/support/StreamConcatenation.java | 4 +- .../combinatorics/CombinedIterator.java | 16 ++--- .../support/combinatorics/ConcatIterator.java | 8 +-- .../combinatorics/PermutationIterator.java | 4 +- .../support/combinatorics/SetIterator.java | 4 +- .../support/combinatorics/package-info.java | 4 ++ .../jqwik/engine/support/package-info.java | 4 ++ .../engine/support/types/package-info.java | 4 ++ .../net/jqwik/api/ArbitraryTestHelper.java | 4 +- .../java/net/jqwik/api/ArbitraryTests.java | 2 +- .../net/jqwik/api/ListArbitraryTests.java | 3 +- .../java/net/jqwik/api/SetArbitraryTests.java | 3 +- .../constraints/UniqueElementsProperties.java | 4 +- .../ContextIsArbitraryConfigurator.java | 4 +- .../shrinking/ArbitraryShrinkingTests.java | 2 +- .../shrinking/CollectShrinkableTests.java | 14 ++--- .../shrinking/CombinedShrinkableTests.java | 10 ++-- .../jqwik/kotlin/api/AnyForSubtypeOfDsl.kt | 10 ++-- .../jqwik/kotlin/api/ArbitraryExtensions.kt | 2 +- .../jqwik/kotlin/api/BuildersExtensions.kt | 2 +- .../jqwik/kotlin/api/CollectionExtensions.kt | 4 +- .../net/jqwik/kotlin/api/JqwikGlobals.kt | 19 +++--- .../net/jqwik/kotlin/api/SequenceArbitrary.kt | 2 +- .../KotlinUniqueElementsConfigurator.kt | 2 +- .../net/jqwik/testing/CheckReporting.java | 2 +- .../net/jqwik/testing/ShrinkingSupport.java | 20 ++++--- .../net/jqwik/testing/TestingFalsifier.java | 7 ++- .../net/jqwik/testing/TestingSupport.java | 48 +++++++-------- 206 files changed, 1022 insertions(+), 766 deletions(-) create mode 100644 engine/src/main/java/net/jqwik/engine/descriptor/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/discovery/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/discovery/predicates/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/discovery/specs/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/execution/lifecycle/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/execution/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/execution/pipeline/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/execution/reporting/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/facades/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/hooks/lifecycle/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/hooks/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/hooks/statistics/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/properties/arbitraries/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/properties/configurators/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/properties/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/properties/shrinking/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/properties/state/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/properties/stateful/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/providers/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/recording/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/support/combinatorics/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/support/package-info.java create mode 100644 engine/src/main/java/net/jqwik/engine/support/types/package-info.java diff --git a/api/src/main/java/net/jqwik/api/Arbitraries.java b/api/src/main/java/net/jqwik/api/Arbitraries.java index cefb5d81a..9879ff6e4 100644 --- a/api/src/main/java/net/jqwik/api/Arbitraries.java +++ b/api/src/main/java/net/jqwik/api/Arbitraries.java @@ -27,7 +27,7 @@ public static abstract class ArbitrariesFacade { public abstract Arbitrary oneOf(Collection> all); - public abstract ActionSequenceArbitrary sequences(Arbitrary> actionArbitrary); + public abstract ActionSequenceArbitrary sequences(Arbitrary> actionArbitrary); public abstract Arbitrary frequencyOf(List>> frequencies); @@ -55,7 +55,7 @@ public static abstract class ArbitrariesFacade { public abstract Arbitrary defaultFor(Class type, Class[] typeParameters); - public abstract Arbitrary defaultFor(TypeUsage typeUsage, Function> noDefaultResolver); + public abstract Arbitrary defaultFor(TypeUsage typeUsage, Function> noDefaultResolver); public abstract Arbitrary lazy(Supplier> arbitrarySupplier); @@ -78,7 +78,7 @@ public static abstract class ArbitrariesFacade { public abstract Arbitrary of(char[] chars); - public abstract Arbitrary of(Collection values); + public abstract Arbitrary of(Collection values); public abstract Arbitrary create(Supplier supplier); @@ -172,7 +172,7 @@ public static Arbitrary randoms() { * @return a new arbitrary instance */ @API(status = MAINTAINED, since = "1.3.1") - public static Arbitrary of(Collection values) { + public static Arbitrary of(Collection values) { return ArbitrariesFacade.implementation.of(values); } @@ -430,7 +430,7 @@ public static CharacterArbitrary chars() { * @return a new arbitrary instance */ @API(status = MAINTAINED, since = "1.3.2") - public static <@Nullable T> Arbitrary just(@Nullable T value) { + public static Arbitrary just(T value) { return ArbitrariesFacade.implementation.just(value); } @@ -515,7 +515,7 @@ public static Arbitrary defaultFor(Class type, Class... typeParamet * @return a new arbitrary instance */ @API(status = MAINTAINED, since = "1.1") - public static Arbitrary defaultFor(TypeUsage typeUsage) { + public static Arbitrary defaultFor(TypeUsage typeUsage) { return defaultFor(typeUsage, ignore -> {throw new CannotFindArbitraryException(typeUsage);}); } @@ -534,7 +534,7 @@ public static Arbitrary defaultFor(TypeUsage typeUsage) { * @return a new arbitrary instance */ @API(status = EXPERIMENTAL, since = "1.6.1") - public static Arbitrary defaultFor(TypeUsage typeUsage, Function> noDefaultResolver) { + public static Arbitrary defaultFor(TypeUsage typeUsage, Function> noDefaultResolver) { return ArbitrariesFacade.implementation.defaultFor(typeUsage, noDefaultResolver); } @@ -739,8 +739,8 @@ public static Arbitrary nothing() { * @return a new arbitrary instance */ @API(status = MAINTAINED, since = "1.6.4") - public static <@Nullable T> SetArbitrary subsetOf(Collection values) { - return of(values).set(); + public static SetArbitrary subsetOf(Collection values) { + return Arbitraries.of(values).set(); } /** @@ -750,7 +750,7 @@ public static Arbitrary nothing() { */ @SafeVarargs @API(status = MAINTAINED, since = "1.6.4") - public static SetArbitrary subsetOf(T... values) { + public static SetArbitrary subsetOf(T... values) { return subsetOf(Arrays.asList(values)); } diff --git a/api/src/main/java/net/jqwik/api/Arbitrary.java b/api/src/main/java/net/jqwik/api/Arbitrary.java index 9f0c5ed08..2baafceab 100644 --- a/api/src/main/java/net/jqwik/api/Arbitrary.java +++ b/api/src/main/java/net/jqwik/api/Arbitrary.java @@ -30,39 +30,39 @@ abstract class ArbitraryFacade { implementation = FacadeLoader.load(ArbitraryFacade.class); } - public abstract ListArbitrary list(Arbitrary elementArbitrary); + public abstract ListArbitrary list(Arbitrary elementArbitrary); - public abstract SetArbitrary set(Arbitrary elementArbitrary); + public abstract SetArbitrary set(Arbitrary elementArbitrary); - public abstract StreamArbitrary stream(Arbitrary elementArbitrary); + public abstract StreamArbitrary stream(Arbitrary elementArbitrary); - public abstract IteratorArbitrary iterator(Arbitrary elementArbitrary); + public abstract IteratorArbitrary iterator(Arbitrary elementArbitrary); - public abstract ArrayArbitrary array(Arbitrary elementArbitrary, Class arrayClass); + public abstract ArrayArbitrary array(Arbitrary elementArbitrary, Class arrayClass); - public abstract Stream sampleStream(Arbitrary arbitrary); + public abstract Stream sampleStream(Arbitrary arbitrary); - public abstract Arbitrary injectNull(Arbitrary self, double nullProbability); + public abstract Arbitrary<@Nullable T> injectNull(Arbitrary self, double nullProbability); - public abstract Arbitrary filter(Arbitrary self, Predicate filterPredicate, int maxMisses); + public abstract Arbitrary filter(Arbitrary self, Predicate filterPredicate, int maxMisses); - public abstract Arbitrary map(Arbitrary self, Function mapper); + public abstract Arbitrary map(Arbitrary self, Function mapper); - public abstract Arbitrary flatMap(Arbitrary self, Function> mapper); + public abstract Arbitrary flatMap(Arbitrary self, Function> mapper); - public abstract Arbitrary ignoreExceptions(Arbitrary self, int maxThrows, Class[] exceptionTypes); + public abstract Arbitrary ignoreExceptions(Arbitrary self, int maxThrows, Class[] exceptionTypes); - public abstract Arbitrary dontShrink(Arbitrary self); + public abstract Arbitrary dontShrink(Arbitrary self); - public abstract Arbitrary configureEdgeCases(Arbitrary self, Consumer> configurator); + public abstract Arbitrary configureEdgeCases(Arbitrary self, Consumer> configurator); - public abstract Arbitrary withoutEdgeCases(Arbitrary self); + public abstract Arbitrary withoutEdgeCases(Arbitrary self); - public abstract RandomGenerator memoizedGenerator(Arbitrary self, int genSize, boolean withEdgeCases); + public abstract RandomGenerator memoizedGenerator(Arbitrary self, int genSize, boolean withEdgeCases); - public abstract Arbitrary fixGenSize(Arbitrary self, int genSize); + public abstract Arbitrary fixGenSize(Arbitrary self, int genSize); - public abstract Arbitrary> collect(Arbitrary self, Predicate> until); + public abstract Arbitrary> collect(Arbitrary self, Predicate> until); } /** @@ -208,7 +208,7 @@ default void forEachValue(Consumer action) { * @return a new arbitrary instance * @throws TooManyFilterMissesException if filtering will fail to come up with a value after 10000 tries */ - default Arbitrary filter(Predicate filterPredicate) { + default Arbitrary filter(Predicate filterPredicate) { return filter(10000, filterPredicate); } @@ -222,7 +222,7 @@ default Arbitrary filter(Predicate filterPredicate) { * @throws TooManyFilterMissesException if filtering will fail to come up with a value after {@code maxMisses} tries */ @API(status = EXPERIMENTAL, since = "1.7.0") - default Arbitrary filter(int maxMisses, Predicate filterPredicate) { + default Arbitrary filter(int maxMisses, Predicate filterPredicate) { return ArbitraryFacade.implementation.filter(this, filterPredicate, maxMisses); } @@ -234,7 +234,7 @@ default Arbitrary filter(int maxMisses, Predicate filterPredicate) { * @param mapper the function used to map * @return a new arbitrary instance */ - default Arbitrary map(Function mapper) { + default Arbitrary map(Function mapper) { return ArbitraryFacade.implementation.map(this, mapper); } @@ -246,7 +246,7 @@ default Arbitrary map(Function mapper) { * @param mapper the function used to map to arbitrary * @return a new arbitrary instance */ - default Arbitrary flatMap(Function> mapper) { + default Arbitrary flatMap(Function> mapper) { return ArbitraryFacade.implementation.flatMap(this, mapper); } @@ -359,7 +359,7 @@ default Arbitrary> optional(double presenceProbability) { * @return a new arbitrary instance */ @API(status = MAINTAINED, since = "1.3.0") - default Arbitrary> collect(Predicate> until) { + default Arbitrary> collect(Predicate> until) { return ArbitraryFacade.implementation.collect(this, until); } diff --git a/api/src/main/java/net/jqwik/api/ArbitrarySupplier.java b/api/src/main/java/net/jqwik/api/ArbitrarySupplier.java index 0e569fc67..7a604414c 100644 --- a/api/src/main/java/net/jqwik/api/ArbitrarySupplier.java +++ b/api/src/main/java/net/jqwik/api/ArbitrarySupplier.java @@ -36,8 +36,7 @@ public interface ArbitrarySupplier extends Supplier> { * * @return A new arbitrary instance */ - @Nullable - default Arbitrary supplyFor(TypeUsage targetType) { + default @Nullable Arbitrary supplyFor(TypeUsage targetType) { return get(); } @@ -50,8 +49,7 @@ default Arbitrary supplyFor(TypeUsage targetType) { * * @return A new arbitrary instance */ - @Nullable - default Arbitrary get() { + default @Nullable Arbitrary get() { throw new JqwikException("You have to override either ArbitrarySupplier.get() or ArbitrarySupplier.supplyFor()"); } diff --git a/api/src/main/java/net/jqwik/api/Builders.java b/api/src/main/java/net/jqwik/api/Builders.java index b96949449..c6c3ef290 100644 --- a/api/src/main/java/net/jqwik/api/Builders.java +++ b/api/src/main/java/net/jqwik/api/Builders.java @@ -64,11 +64,10 @@ private BuilderCombinator(Supplier starter, List the target object's type * @return arbitrary of target object */ - public Arbitrary build(Function buildFunction) { + public Arbitrary build(Function buildFunction) { class Holder { - @Nullable - final Object value; + final @Nullable Object value; Holder(@Nullable Object value) { this.value = value; diff --git a/api/src/main/java/net/jqwik/api/Combinators.java b/api/src/main/java/net/jqwik/api/Combinators.java index a8a21dfdc..60efb4c89 100644 --- a/api/src/main/java/net/jqwik/api/Combinators.java +++ b/api/src/main/java/net/jqwik/api/Combinators.java @@ -68,7 +68,7 @@ public abstract Combinator8 a8 ); - public abstract ListCombinator combineList(List> listOfArbitraries); + public abstract ListCombinator combineList(List> listOfArbitraries); } private Combinators() { @@ -173,7 +173,7 @@ public interface Combinator2 return type * @return arbitrary instance */ - Arbitrary as(F2 combinator); + Arbitrary as(F2 combinator); /** * Filter two values to only let them pass if the predicate is true. @@ -182,7 +182,7 @@ public interface Combinator2 filter(F2 filter); + Combinator2 filter(F2 filter); /** * Combine two values to create a new arbitrary. @@ -191,7 +191,7 @@ public interface Combinator2 return type of arbitrary * @return arbitrary instance */ - default Arbitrary flatAs(F2> flatCombinator) { + default Arbitrary flatAs(F2> flatCombinator) { return as(flatCombinator).flatMap(Function.identity()); } } @@ -208,7 +208,7 @@ public interface Combinator3 return type * @return arbitrary instance */ - Arbitrary as(F3 combinator); + Arbitrary as(F3 combinator); /** * Filter three values to only let them pass if the predicate is true. @@ -217,7 +217,7 @@ public interface Combinator3 filter(F3 filter); + Combinator3 filter(F3 filter); /** * Combine three values to create a new arbitrary. @@ -226,7 +226,7 @@ public interface Combinator3 return type of arbitrary * @return arbitrary instance */ - default Arbitrary flatAs(F3> flatCombinator) { + default Arbitrary flatAs(F3> flatCombinator) { return as(flatCombinator).flatMap(Function.identity()); } @@ -244,7 +244,7 @@ public interface Combinator4 return type * @return arbitrary instance */ - Arbitrary as(F4 combinator); + Arbitrary as(F4 combinator); /** * Filter four values to only let them pass if the predicate is true. @@ -253,7 +253,7 @@ public interface Combinator4 filter(F4 filter); + Combinator4 filter(F4 filter); /** * Combine four values to create a new arbitrary. @@ -262,7 +262,7 @@ public interface Combinator4 return type of arbitrary * @return arbitrary instance */ - default Arbitrary flatAs(F4> flatCombinator) { + default Arbitrary flatAs(F4> flatCombinator) { return as(flatCombinator).flatMap(Function.identity()); } @@ -280,7 +280,7 @@ public interface Combinator5 return type * @return arbitrary instance */ - Arbitrary as(F5 combinator); + Arbitrary as(F5 combinator); /** * Filter five values to only let them pass if the predicate is true. @@ -289,7 +289,7 @@ public interface Combinator5 filter(F5 filter); + Combinator5 filter(F5 filter); /** * Combine five values to create a new arbitrary. @@ -298,7 +298,7 @@ public interface Combinator5 return type of arbitrary * @return arbitrary instance */ - default Arbitrary flatAs(F5> flatCombinator) { + default Arbitrary flatAs(F5> flatCombinator) { return as(flatCombinator).flatMap(Function.identity()); } } @@ -315,7 +315,7 @@ public interface Combinator6 return type * @return arbitrary instance */ - Arbitrary as(F6 combinator); + Arbitrary as(F6 combinator); /** * Filter six values to only let them pass if the predicate is true. @@ -324,7 +324,7 @@ public interface Combinator6 filter(F6 filter); + Combinator6 filter(F6 filter); /** * Combine six values to create a new arbitrary. @@ -333,7 +333,7 @@ public interface Combinator6 return type of arbitrary * @return arbitrary instance */ - default Arbitrary flatAs(F6> flatCombinator) { + default Arbitrary flatAs(F6> flatCombinator) { return as(flatCombinator).flatMap(Function.identity()); } @@ -351,7 +351,7 @@ public interface Combinator7 return type * @return arbitrary instance */ - Arbitrary as(F7 combinator); + Arbitrary as(F7 combinator); /** * Filter seven values to only let them pass if the predicate is true. @@ -360,7 +360,7 @@ public interface Combinator7 filter(F7 filter); + Combinator7 filter(F7 filter); /** * Combine seven values to create a new arbitrary. @@ -369,7 +369,7 @@ public interface Combinator7 return type of arbitrary * @return arbitrary instance */ - default Arbitrary flatAs(F7> flatCombinator) { + default Arbitrary flatAs(F7> flatCombinator) { return as(flatCombinator).flatMap(Function.identity()); } @@ -387,7 +387,7 @@ public interface Combinator8 return type * @return arbitrary instance */ - Arbitrary as(F8 combinator); + Arbitrary as(F8 combinator); /** * Filter eight values to only let them pass if the predicate is true. @@ -396,7 +396,7 @@ public interface Combinator8 filter(F8 filter); + Combinator8 filter(F8 filter); /** * Combine eight values to create a new arbitrary. @@ -405,7 +405,7 @@ public interface Combinator8 return type of arbitrary * @return arbitrary instance */ - default Arbitrary flatAs(F8> flatCombinator) { + default Arbitrary flatAs(F8> flatCombinator) { return as(flatCombinator).flatMap(Function.identity()); } } @@ -413,7 +413,7 @@ public interface Combinator8 { + public interface ListCombinator { /** * Combine any number of values. @@ -422,7 +422,7 @@ public interface ListCombinator<@Nullable T> { * @param return type * @return arbitrary instance */ - Arbitrary as(Function, R> combinator); + Arbitrary as(Function, ? extends R> combinator); /** * Filter list of values to only let them pass if the predicate is true. @@ -431,7 +431,7 @@ public interface ListCombinator<@Nullable T> { * @return combinator instance */ @API(status = MAINTAINED, since = "1.8.0") - ListCombinator filter(Predicate> filter); + ListCombinator filter(Predicate> filter); /** * Combine list of values to create a new arbitrary. @@ -440,26 +440,26 @@ public interface ListCombinator<@Nullable T> { * @param return type of arbitrary * @return arbitrary instance */ - default Arbitrary flatAs(Function, Arbitrary> flatCombinator) { + default Arbitrary flatAs(Function, ? extends Arbitrary> flatCombinator) { return as(flatCombinator).flatMap(Function.identity()); } } @FunctionalInterface @API(status = INTERNAL) - public interface F2 { + public interface F2 { R apply(T1 t1, T2 t2); } @FunctionalInterface @API(status = INTERNAL) - public interface F3 { + public interface F3 { R apply(T1 t1, T2 t2, T3 t3); } @FunctionalInterface @API(status = INTERNAL) - public interface F4 { + public interface F4 { R apply(T1 t1, T2 t2, T3 t3, T4 t4); } diff --git a/api/src/main/java/net/jqwik/api/EdgeCases.java b/api/src/main/java/net/jqwik/api/EdgeCases.java index 863f75f42..fab4c9a3f 100644 --- a/api/src/main/java/net/jqwik/api/EdgeCases.java +++ b/api/src/main/java/net/jqwik/api/EdgeCases.java @@ -4,6 +4,7 @@ import java.util.function.*; import org.apiguardian.api.*; +import org.jspecify.annotations.*; import static org.apiguardian.api.API.Status.*; @@ -18,13 +19,13 @@ abstract class EdgeCasesFacade { implementation = FacadeLoader.load(EdgeCases.EdgeCasesFacade.class); } - public abstract EdgeCases fromSuppliers(List>> suppliers); + public abstract EdgeCases fromSuppliers(List>> suppliers); } @API(status = MAINTAINED, since = "1.8.0") interface Config { - static Consumer> noConfig() { + static Consumer> noConfig() { return config -> {}; } @@ -41,7 +42,7 @@ static Consumer> noConfig() { * @param filter A predicate * @return same configuration instance */ - Config filter(Predicate filter); + Config filter(Predicate filter); /** * Add one or more unshrinkable additional values as edge cases. @@ -86,17 +87,17 @@ default Iterator> iterator() { } @API(status = INTERNAL) - static EdgeCases fromSuppliers(List>> suppliers) { + static EdgeCases fromSuppliers(List>> suppliers) { return EdgeCasesFacade.implementation.fromSuppliers(suppliers); } @API(status = INTERNAL) - static EdgeCases none() { + static EdgeCases none() { return fromSuppliers(Collections.emptyList()); } @API(status = INTERNAL) - static EdgeCases fromSupplier(Supplier> supplier) { + static EdgeCases fromSupplier(Supplier> supplier) { return fromSuppliers(Collections.singletonList(supplier)); } diff --git a/api/src/main/java/net/jqwik/api/ExhaustiveGenerator.java b/api/src/main/java/net/jqwik/api/ExhaustiveGenerator.java index b542cd5ec..3547228ee 100644 --- a/api/src/main/java/net/jqwik/api/ExhaustiveGenerator.java +++ b/api/src/main/java/net/jqwik/api/ExhaustiveGenerator.java @@ -3,6 +3,7 @@ import java.util.function.*; import org.apiguardian.api.*; +import org.jspecify.annotations.*; import static org.apiguardian.api.API.Status.*; @@ -10,7 +11,7 @@ * Used only internally to run and compute exhaustive generation of parameters */ @API(status = INTERNAL) -public interface ExhaustiveGenerator extends Iterable { +public interface ExhaustiveGenerator extends Iterable { long MAXIMUM_SAMPLES_TO_GENERATE = Integer.MAX_VALUE; @@ -22,13 +23,13 @@ abstract class ExhaustiveGeneratorFacade { implementation = FacadeLoader.load(ExhaustiveGeneratorFacade.class); } - public abstract ExhaustiveGenerator map(ExhaustiveGenerator self, Function mapper); + public abstract ExhaustiveGenerator map(ExhaustiveGenerator self, Function mapper); - public abstract ExhaustiveGenerator filter(ExhaustiveGenerator self, Predicate filterPredicate, int maxMisses); + public abstract ExhaustiveGenerator filter(ExhaustiveGenerator self, Predicate filterPredicate, int maxMisses); - public abstract ExhaustiveGenerator injectNull(ExhaustiveGenerator self); + public abstract ExhaustiveGenerator<@Nullable T> injectNull(ExhaustiveGenerator self); - public abstract ExhaustiveGenerator ignoreExceptions( + public abstract ExhaustiveGenerator ignoreExceptions( ExhaustiveGenerator self, Class[] exceptionTypes, int maxThrows @@ -40,11 +41,11 @@ public abstract ExhaustiveGenerator ignoreExceptions( */ long maxCount(); - default ExhaustiveGenerator map(Function mapper) { + default ExhaustiveGenerator map(Function mapper) { return ExhaustiveGeneratorFacade.implementation.map(this, mapper); } - default ExhaustiveGenerator filter(Predicate filterPredicate, int maxMisses) { + default ExhaustiveGenerator filter(Predicate filterPredicate, int maxMisses) { return ExhaustiveGeneratorFacade.implementation.filter(this, filterPredicate, maxMisses); } diff --git a/api/src/main/java/net/jqwik/api/Falsifier.java b/api/src/main/java/net/jqwik/api/Falsifier.java index e1c2d04c7..1afc3fdfc 100644 --- a/api/src/main/java/net/jqwik/api/Falsifier.java +++ b/api/src/main/java/net/jqwik/api/Falsifier.java @@ -6,6 +6,8 @@ import net.jqwik.api.lifecycle.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; /** @@ -17,13 +19,13 @@ */ @FunctionalInterface @API(status = STABLE, since = "1.0") -public interface Falsifier { +public interface Falsifier { @API(status = INTERNAL) TryExecutionResult execute(T t); @API(status = INTERNAL) - default Falsifier withFilter(Predicate filter) { + default Falsifier withFilter(Predicate filter) { return value -> { if (!filter.test(value)) { return TryExecutionResult.invalid(); diff --git a/api/src/main/java/net/jqwik/api/Functions.java b/api/src/main/java/net/jqwik/api/Functions.java index 368d140fe..7c6c6edcf 100644 --- a/api/src/main/java/net/jqwik/api/Functions.java +++ b/api/src/main/java/net/jqwik/api/Functions.java @@ -4,6 +4,8 @@ import net.jqwik.api.arbitraries.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; @@ -20,7 +22,7 @@ public static abstract class FunctionsFacade { public abstract void ensureFunctionalType(Class functionalType); - public abstract FunctionArbitrary function(Class functionalType, Arbitrary resultArbitrary); + public abstract FunctionArbitrary function(Class functionalType, Arbitrary resultArbitrary); } @@ -65,7 +67,7 @@ private FunctionWrapper(Class functionalType) { * @return a new arbitrary instance */ @API(status = MAINTAINED, since = "1.6.0") - public FunctionArbitrary returning(Arbitrary resultArbitrary) { + public FunctionArbitrary returning(Arbitrary resultArbitrary) { return FunctionsFacade.implementation.function(functionalType, resultArbitrary); } } diff --git a/api/src/main/java/net/jqwik/api/RandomGenerator.java b/api/src/main/java/net/jqwik/api/RandomGenerator.java index b47f3871e..d49e2c18a 100644 --- a/api/src/main/java/net/jqwik/api/RandomGenerator.java +++ b/api/src/main/java/net/jqwik/api/RandomGenerator.java @@ -20,25 +20,25 @@ abstract class RandomGeneratorFacade { implementation = FacadeLoader.load(RandomGeneratorFacade.class); } - public abstract Shrinkable flatMap(Shrinkable self, Function> mapper, long nextLong); + public abstract Shrinkable flatMap(Shrinkable self, Function> mapper, long nextLong); - public abstract Shrinkable flatMap( + public abstract Shrinkable flatMap( Shrinkable wrappedShrinkable, - Function> mapper, + Function> mapper, int genSize, long nextLong, boolean withEmbeddedEdgeCases ); - public abstract RandomGenerator filter(RandomGenerator self, Predicate filterPredicate, int maxMisses); + public abstract RandomGenerator filter(RandomGenerator self, Predicate filterPredicate, int maxMisses); - public abstract RandomGenerator withEdgeCases(RandomGenerator self, int genSize, EdgeCases edgeCases); + public abstract RandomGenerator withEdgeCases(RandomGenerator self, int genSize, EdgeCases edgeCases); - public abstract RandomGenerator> collect(RandomGenerator self, Predicate> until); + public abstract RandomGenerator> collect(RandomGenerator self, Predicate> until); - public abstract RandomGenerator injectDuplicates(RandomGenerator self, double duplicateProbability); + public abstract RandomGenerator injectDuplicates(RandomGenerator self, double duplicateProbability); - public abstract RandomGenerator ignoreExceptions( + public abstract RandomGenerator ignoreExceptions( RandomGenerator self, Class[] exceptionTypes, int maxThrows @@ -52,12 +52,12 @@ public abstract RandomGenerator ignoreExceptions( Shrinkable next(Random random); @API(status = INTERNAL) - default RandomGenerator map(Function mapper) { + default RandomGenerator map(Function mapper) { return this.mapShrinkable(s -> s.map(mapper)); } @API(status = INTERNAL) - default RandomGenerator mapShrinkable(Function, Shrinkable> mapper) { + default RandomGenerator mapShrinkable(Function, ? extends Shrinkable> mapper) { return random -> { Shrinkable tShrinkable = RandomGenerator.this.next(random); return mapper.apply(tShrinkable); @@ -65,7 +65,7 @@ default RandomGenerator mapShrinkable(Function, Shrinkable< } @API(status = INTERNAL) - default RandomGenerator flatMap(Function> mapper) { + default RandomGenerator flatMap(Function> mapper) { return random -> { Shrinkable wrappedShrinkable = RandomGenerator.this.next(random); return RandomGeneratorFacade.implementation.flatMap(wrappedShrinkable, mapper, random.nextLong()); @@ -73,7 +73,7 @@ default RandomGenerator flatMap(Function> mapper) { } @API(status = INTERNAL) - default RandomGenerator flatMap(Function> mapper, int genSize, boolean withEmbeddedEdgeCases) { + default RandomGenerator flatMap(Function> mapper, int genSize, boolean withEmbeddedEdgeCases) { return random -> { Shrinkable wrappedShrinkable = RandomGenerator.this.next(random); return RandomGeneratorFacade.implementation @@ -82,7 +82,7 @@ default RandomGenerator flatMap(Function> mapper, int gen } @API(status = INTERNAL) - default RandomGenerator filter(Predicate filterPredicate, int maxMisses) { + default RandomGenerator filter(Predicate filterPredicate, int maxMisses) { return RandomGeneratorFacade.implementation.filter(this, filterPredicate, maxMisses); } @@ -97,7 +97,7 @@ default Stream> stream(Random random) { } @API(status = INTERNAL) - default RandomGenerator> collect(Predicate> until) { + default RandomGenerator> collect(Predicate> until) { return RandomGeneratorFacade.implementation.collect(this, until); } diff --git a/api/src/main/java/net/jqwik/api/Shrinkable.java b/api/src/main/java/net/jqwik/api/Shrinkable.java index c7a4c87db..57b017c5d 100644 --- a/api/src/main/java/net/jqwik/api/Shrinkable.java +++ b/api/src/main/java/net/jqwik/api/Shrinkable.java @@ -20,25 +20,25 @@ abstract class ShrinkableFacade { implementation = FacadeLoader.load(ShrinkableFacade.class); } - public abstract Shrinkable unshrinkable(@Nullable Supplier valueSupplier, ShrinkingDistance distance); + public abstract Shrinkable unshrinkable(Supplier valueSupplier, ShrinkingDistance distance); - public abstract Shrinkable map(Shrinkable self, Function mapper); + public abstract Shrinkable map(Shrinkable self, Function mapper); - public abstract Shrinkable filter(Shrinkable self, Predicate filter); + public abstract Shrinkable filter(Shrinkable self, Predicate filter); - public abstract Shrinkable flatMap(Shrinkable self, Function> flatMapper, int tries, long randomSeed); + public abstract Shrinkable flatMap(Shrinkable self, Function> flatMapper, int tries, long randomSeed); } - static Shrinkable unshrinkable(@Nullable T value) { + static Shrinkable unshrinkable(T value) { return unshrinkable(value, ShrinkingDistance.MIN); } - static Shrinkable unshrinkable(@Nullable T value, ShrinkingDistance distance) { + static Shrinkable unshrinkable(T value, ShrinkingDistance distance) { return ShrinkableFacade.implementation.unshrinkable(() -> value, distance); } @API(status = INTERNAL) - static Shrinkable supplyUnshrinkable(Supplier supplier) { + static Shrinkable supplyUnshrinkable(Supplier supplier) { return ShrinkableFacade.implementation.unshrinkable(supplier, ShrinkingDistance.MIN); } @@ -98,15 +98,15 @@ default Shrinkable asGeneric() { return (Shrinkable) this; } - default Shrinkable map(Function mapper) { + default Shrinkable map(Function mapper) { return ShrinkableFacade.implementation.map(this, mapper); } - default Shrinkable filter(Predicate filter) { + default Shrinkable filter(Predicate filter) { return ShrinkableFacade.implementation.filter(this, filter); } - default Shrinkable flatMap(Function> flatMapper, int tries, long randomSeed) { + default Shrinkable flatMap(Function> flatMapper, int tries, long randomSeed) { return ShrinkableFacade.implementation.flatMap(this, flatMapper, tries, randomSeed); } diff --git a/api/src/main/java/net/jqwik/api/ShrinkingDistance.java b/api/src/main/java/net/jqwik/api/ShrinkingDistance.java index 28584ecaf..cbc167582 100644 --- a/api/src/main/java/net/jqwik/api/ShrinkingDistance.java +++ b/api/src/main/java/net/jqwik/api/ShrinkingDistance.java @@ -49,7 +49,7 @@ public static ShrinkingDistance of(long... distances) { } @API(status = MAINTAINED, since = "1.0") - public static ShrinkingDistance forCollection(Collection> elements) { + public static ShrinkingDistance forCollection(Collection> elements) { // This is an optimization to avoid creating temporary arrays, which the old streams-based implementation did. long[] collectedDistances = sumUp(toDistances(elements)); ShrinkingDistance sumDistanceOfElements = new ShrinkingDistance(collectedDistances); @@ -57,7 +57,7 @@ public static ShrinkingDistance forCollection(Collection> elem } @API(status = MAINTAINED, since = "1.0") - public static ShrinkingDistance combine(List> shrinkables) { + public static ShrinkingDistance combine(List> shrinkables) { // This can happen e.g. when using Combinators.combine() with an empty list of arbitraries. if (shrinkables.isEmpty()) { return ShrinkingDistance.MIN; @@ -145,8 +145,7 @@ public ShrinkingDistance append(ShrinkingDistance other) { return new ShrinkingDistance(appendedDistances); } - @NonNull - private static List toDistances(Collection> shrinkables) { + private static List toDistances(Collection> shrinkables) { List listOfDistances = new ArrayList<>(shrinkables.size()); for (Shrinkable tShrinkable : shrinkables) { long[] longs = tShrinkable.distance().distances; diff --git a/api/src/main/java/net/jqwik/api/Table.java b/api/src/main/java/net/jqwik/api/Table.java index 66a998b2e..d77976107 100644 --- a/api/src/main/java/net/jqwik/api/Table.java +++ b/api/src/main/java/net/jqwik/api/Table.java @@ -7,54 +7,56 @@ import net.jqwik.api.Tuple.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; @API(status = MAINTAINED, since = "1.0") public class Table { @SafeVarargs - public static Iterable> of(E... elements) { + public static Iterable> of(E... elements) { return Arrays.stream(elements) .map(Tuple::of) .collect(Collectors.toList()); } @SafeVarargs - public static Iterable> of(Tuple1... tuples) { + public static Iterable> of(Tuple1... tuples) { return Arrays.asList(tuples); } @SafeVarargs - public static Iterable> of(Tuple2... tuples) { + public static Iterable> of(Tuple2... tuples) { return Arrays.asList(tuples); } @SafeVarargs - public static Iterable> of(Tuple3... tuples) { + public static Iterable> of(Tuple3... tuples) { return Arrays.asList(tuples); } @SafeVarargs - public static Iterable> of(Tuple4... tuples) { + public static Iterable> of(Tuple4... tuples) { return Arrays.asList(tuples); } @SafeVarargs - public static Iterable> of(Tuple5... tuples) { + public static Iterable> of(Tuple5... tuples) { return Arrays.asList(tuples); } @SafeVarargs - public static Iterable> of(Tuple6... tuples) { + public static Iterable> of(Tuple6... tuples) { return Arrays.asList(tuples); } @SafeVarargs - public static Iterable> of(Tuple7... tuples) { + public static Iterable> of(Tuple7... tuples) { return Arrays.asList(tuples); } @SafeVarargs - public static Iterable> of(Tuple8... tuples) { + public static Iterable> of(Tuple8... tuples) { return Arrays.asList(tuples); } } diff --git a/api/src/main/java/net/jqwik/api/Tuple.java b/api/src/main/java/net/jqwik/api/Tuple.java index 6b97d3cc1..226f32c1a 100644 --- a/api/src/main/java/net/jqwik/api/Tuple.java +++ b/api/src/main/java/net/jqwik/api/Tuple.java @@ -140,7 +140,7 @@ public T1 get1() { } @Override - public List items() { + public List<@Nullable Object> items() { return Arrays.asList(get1()); } @@ -181,7 +181,7 @@ public T2 get2() { } @Override - public List items() { + public List<@Nullable Object> items() { return Arrays.asList(get1(), get2()); } @@ -218,7 +218,7 @@ public T3 get3() { } @Override - public List items() { + public List<@Nullable Object> items() { return Arrays.asList(get1(), get2(), get3()); } @@ -256,7 +256,7 @@ public T4 get4() { } @Override - public List items() { + public List<@Nullable Object> items() { return Arrays.asList(get1(), get2(), get3(), get4()); } @@ -295,7 +295,7 @@ public T5 get5() { } @Override - public List items() { + public List<@Nullable Object> items() { return Arrays.asList(get1(), get2(), get3(), get4(), get5()); } @@ -335,7 +335,7 @@ public T6 get6() { } @Override - public List items() { + public List<@Nullable Object> items() { return Arrays.asList(get1(), get2(), get3(), get4(), get5(), get6()); } @@ -384,7 +384,7 @@ public T7 get7() { } @Override - public List items() { + public List<@Nullable Object> items() { return Arrays.asList(get1(), get2(), get3(), get4(), get5(), get6(), get7()); } @@ -435,7 +435,7 @@ public T8 get8() { } @Override - public List items() { + public List<@Nullable Object> items() { return Arrays.asList(get1(), get2(), get3(), get4(), get5(), get6(), get7(), get8()); } diff --git a/api/src/main/java/net/jqwik/api/arbitraries/ArbitraryDecorator.java b/api/src/main/java/net/jqwik/api/arbitraries/ArbitraryDecorator.java index ea8d78bba..7bdd4a314 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/ArbitraryDecorator.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/ArbitraryDecorator.java @@ -6,6 +6,8 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; /** @@ -21,7 +23,7 @@ @API(status = MAINTAINED, since = "1.4.0") public abstract class ArbitraryDecorator implements Cloneable, Arbitrary { - private Arbitrary instance = null; + private @Nullable Arbitrary instance = null; /** * Implement by calling jqwik's standard DSL for building arbitraries. diff --git a/api/src/main/java/net/jqwik/api/arbitraries/FunctionArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/FunctionArbitrary.java index 808963692..86dc42e82 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/FunctionArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/FunctionArbitrary.java @@ -17,7 +17,7 @@ * @param The return type of the functional interface */ @API(status = MAINTAINED, since = "1.3.0") -public interface FunctionArbitrary extends Arbitrary { +public interface FunctionArbitrary extends Arbitrary { /** * diff --git a/api/src/main/java/net/jqwik/api/arbitraries/ListArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/ListArbitrary.java index 4c2e69655..5acfae58e 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/ListArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/ListArbitrary.java @@ -61,7 +61,7 @@ default ListArbitrary ofSize(int size) { * @return arbitrary of a list of Us */ @API(status = MAINTAINED, since = "1.4.0") - Arbitrary> mapEach(BiFunction, T, U> mapper); + Arbitrary> mapEach(BiFunction, ? super T, ? extends U> mapper); /** * Flat-map over each element of the generated list giving access to all elements of the list. diff --git a/api/src/main/java/net/jqwik/api/arbitraries/SetArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/SetArbitrary.java index f9a9fe1b5..665c5277c 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/SetArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/SetArbitrary.java @@ -61,7 +61,7 @@ default SetArbitrary ofSize(int size) { * @return arbitrary of a set of Us */ @API(status = MAINTAINED, since = "1.4.0") - Arbitrary> mapEach(BiFunction, T, U> mapper); + Arbitrary> mapEach(BiFunction, ? super T, ? extends U> mapper); /** * Flat-map over each element of the generated set giving access to all elements of the set. @@ -72,7 +72,7 @@ default SetArbitrary ofSize(int size) { * @return arbitrary of a set of Us */ @API(status = MAINTAINED, since = "1.4.0") - Arbitrary> flatMapEach(BiFunction, T, Arbitrary> flatMapper); + Arbitrary> flatMapEach(BiFunction, ? super T, ? extends Arbitrary> flatMapper); /** * Do not use. Sets have unique elements anyway. diff --git a/api/src/main/java/net/jqwik/api/arbitraries/StreamableArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/StreamableArbitrary.java index d45d63565..f65c40bfa 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/StreamableArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/StreamableArbitrary.java @@ -28,7 +28,7 @@ public interface StreamableArbitrary extends Siza * @param The result type * @return The result of accumulating all elements in streamable */ - Arbitrary reduce(R initial, BiFunction accumulator); + Arbitrary reduce(R initial, BiFunction accumulator); /** * Fix the size to {@code size}. diff --git a/api/src/main/java/net/jqwik/api/arbitraries/TypeArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/TypeArbitrary.java index 0ea63796a..57dcf14fa 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/TypeArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/TypeArbitrary.java @@ -26,7 +26,7 @@ * @see net.jqwik.api.domains.DomainContext */ @API(status = MAINTAINED, since = "1.2") -public interface TypeArbitrary extends Arbitrary { +public interface TypeArbitrary extends Arbitrary { /** * Add public constructors of class {@code T} to be used @@ -76,7 +76,7 @@ public interface TypeArbitrary extends Arbitrary * @param filter Predicate to add only those factory methods for which the predicate returns true * @return new arbitrary instance */ - TypeArbitrary useFactoryMethods(Predicate filter); + TypeArbitrary useFactoryMethods(Predicate filter); /** * Enable recursive use of type arbitrary: diff --git a/api/src/main/java/net/jqwik/api/arbitraries/package-info.java b/api/src/main/java/net/jqwik/api/arbitraries/package-info.java index a02d1de34..af09d2ada 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/package-info.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/package-info.java @@ -1,4 +1,4 @@ @NullMarked package net.jqwik.api.arbitraries; -import org.jspecify.annotations.*; \ No newline at end of file +import org.jspecify.annotations.*; diff --git a/api/src/main/java/net/jqwik/api/configurators/ArbitraryConfigurator.java b/api/src/main/java/net/jqwik/api/configurators/ArbitraryConfigurator.java index 4c4aeae81..5c9d7fa9c 100644 --- a/api/src/main/java/net/jqwik/api/configurators/ArbitraryConfigurator.java +++ b/api/src/main/java/net/jqwik/api/configurators/ArbitraryConfigurator.java @@ -5,6 +5,8 @@ import net.jqwik.api.*; import net.jqwik.api.providers.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; /** @@ -26,7 +28,7 @@ public interface ArbitraryConfigurator extends Comparable * @return the newly configured arbitrary instance */ // Type variable T does not make any sense here. Removing it would breaks all implementors, though. - Arbitrary configure(Arbitrary arbitrary, TypeUsage targetType); + Arbitrary configure(Arbitrary arbitrary, TypeUsage targetType); /** * Determines the order in which a configurator will be applied in regards to other configurators. diff --git a/api/src/main/java/net/jqwik/api/configurators/ArbitraryConfiguratorBase.java b/api/src/main/java/net/jqwik/api/configurators/ArbitraryConfiguratorBase.java index f64c3d439..a7c0cda2e 100644 --- a/api/src/main/java/net/jqwik/api/configurators/ArbitraryConfiguratorBase.java +++ b/api/src/main/java/net/jqwik/api/configurators/ArbitraryConfiguratorBase.java @@ -6,6 +6,7 @@ import java.util.stream.*; import org.apiguardian.api.*; +import org.jspecify.annotations.*; import org.junit.platform.commons.support.*; import net.jqwik.api.*; @@ -38,7 +39,7 @@ public abstract class ArbitraryConfiguratorBase implements ArbitraryConfigurator private final static String CONFIG_METHOD_NAME_PATTERN = "configure.*"; @Override - public Arbitrary configure(Arbitrary arbitrary, TypeUsage targetType) { + public Arbitrary configure(Arbitrary arbitrary, TypeUsage targetType) { if (!acceptTargetType(targetType)) { return arbitrary; } @@ -68,7 +69,7 @@ private List configurationAnnotations(TypeUsage parameter) { } @SuppressWarnings("unchecked") - private Arbitrary configureWithMethod(Arbitrary arbitrary, Annotation annotation, Method configurationMethod) { + private Arbitrary configureWithMethod(Arbitrary arbitrary, Annotation annotation, Method configurationMethod) { Object configurationResult = invokeMethod(configurationMethod, this, arbitrary, annotation); if (configurationResult == null) { return arbitrary; @@ -80,7 +81,7 @@ private Arbitrary configureWithMethod(Arbitrary arbitrary, Annotation } @SuppressWarnings("unchecked") - private List findConfigurationMethods(Arbitrary arbitrary, TypeUsage targetType, Annotation annotation) { + private List findConfigurationMethods(Arbitrary arbitrary, TypeUsage targetType, Annotation annotation) { Class> arbitraryClass = (Class>) arbitrary.getClass(); return findMethods( getClass(), diff --git a/api/src/main/java/net/jqwik/api/configurators/SelfConfiguringArbitrary.java b/api/src/main/java/net/jqwik/api/configurators/SelfConfiguringArbitrary.java index 59c16d0ff..3fe98dda3 100644 --- a/api/src/main/java/net/jqwik/api/configurators/SelfConfiguringArbitrary.java +++ b/api/src/main/java/net/jqwik/api/configurators/SelfConfiguringArbitrary.java @@ -5,6 +5,8 @@ import net.jqwik.api.*; import net.jqwik.api.providers.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; /** @@ -32,7 +34,7 @@ public interface SelfConfiguringArbitrary { */ @SuppressWarnings("unchecked") @API(status = INTERNAL) - static Arbitrary configure(Arbitrary self, ArbitraryConfigurator configurator, TypeUsage targetType) { + static Arbitrary configure(Arbitrary self, ArbitraryConfigurator configurator, TypeUsage targetType) { if (self instanceof SelfConfiguringArbitrary) { return ((SelfConfiguringArbitrary) self).configure(configurator, targetType); } else { diff --git a/api/src/main/java/net/jqwik/api/configurators/package-info.java b/api/src/main/java/net/jqwik/api/configurators/package-info.java index eb47fc039..3660081f9 100644 --- a/api/src/main/java/net/jqwik/api/configurators/package-info.java +++ b/api/src/main/java/net/jqwik/api/configurators/package-info.java @@ -1,4 +1,4 @@ @NullMarked package net.jqwik.api.configurators; -import org.jspecify.annotations.*; \ No newline at end of file +import org.jspecify.annotations.*; diff --git a/api/src/main/java/net/jqwik/api/constraints/package-info.java b/api/src/main/java/net/jqwik/api/constraints/package-info.java index b988487c8..927d596c0 100644 --- a/api/src/main/java/net/jqwik/api/constraints/package-info.java +++ b/api/src/main/java/net/jqwik/api/constraints/package-info.java @@ -1,4 +1,4 @@ @NullMarked package net.jqwik.api.constraints; -import org.jspecify.annotations.*; \ No newline at end of file +import org.jspecify.annotations.*; diff --git a/api/src/main/java/net/jqwik/api/domains/package-info.java b/api/src/main/java/net/jqwik/api/domains/package-info.java index 4d063658e..834cb3e60 100644 --- a/api/src/main/java/net/jqwik/api/domains/package-info.java +++ b/api/src/main/java/net/jqwik/api/domains/package-info.java @@ -1,4 +1,4 @@ @NullMarked package net.jqwik.api.domains; -import org.jspecify.annotations.*; \ No newline at end of file +import org.jspecify.annotations.*; diff --git a/api/src/main/java/net/jqwik/api/facades/ShrinkingSupportFacade.java b/api/src/main/java/net/jqwik/api/facades/ShrinkingSupportFacade.java index 9d25b660e..abf6c4692 100644 --- a/api/src/main/java/net/jqwik/api/facades/ShrinkingSupportFacade.java +++ b/api/src/main/java/net/jqwik/api/facades/ShrinkingSupportFacade.java @@ -7,6 +7,8 @@ import net.jqwik.api.*; import net.jqwik.api.lifecycle.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; @API(status = INTERNAL) @@ -17,19 +19,19 @@ public abstract class ShrinkingSupportFacade { implementation = FacadeLoader.load(ShrinkingSupportFacade.class); } - public abstract T falsifyThenShrink(Arbitrary arbitrary, Random random, Falsifier falsifier); + public abstract T falsifyThenShrink(Arbitrary arbitrary, Random random, Falsifier falsifier); - public abstract T falsifyThenShrink(RandomGenerator arbitrary, Random random, Falsifier falsifier); + public abstract T falsifyThenShrink(RandomGenerator arbitrary, Random random, Falsifier falsifier); - public abstract T shrink( + public abstract T shrink( Shrinkable falsifiedShrinkable, - Falsifier falsifier, + Falsifier falsifier, Throwable originalError ); - public abstract ShrunkFalsifiedSample shrinkToSample( + public abstract ShrunkFalsifiedSample shrinkToSample( Shrinkable falsifiedShrinkable, - Falsifier falsifier, + Falsifier falsifier, Throwable originalError ); } diff --git a/api/src/main/java/net/jqwik/api/facades/TestingSupportFacade.java b/api/src/main/java/net/jqwik/api/facades/TestingSupportFacade.java index 5684cd428..faef84463 100644 --- a/api/src/main/java/net/jqwik/api/facades/TestingSupportFacade.java +++ b/api/src/main/java/net/jqwik/api/facades/TestingSupportFacade.java @@ -5,6 +5,8 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + public abstract class TestingSupportFacade { public static final TestingSupportFacade implementation; @@ -13,7 +15,7 @@ public abstract class TestingSupportFacade { implementation = FacadeLoader.load(TestingSupportFacade.class); } - public abstract Shrinkable generateUntil(RandomGenerator generator, Random random, Function condition); + public abstract Shrinkable generateUntil(RandomGenerator generator, Random random, Function condition); public abstract String singleLineReport(Object any); diff --git a/api/src/main/java/net/jqwik/api/facades/package-info.java b/api/src/main/java/net/jqwik/api/facades/package-info.java index b722f79bb..f6e7f1050 100644 --- a/api/src/main/java/net/jqwik/api/facades/package-info.java +++ b/api/src/main/java/net/jqwik/api/facades/package-info.java @@ -5,5 +5,7 @@ */ //@API(status = API.Status.INTERNAL) // Currently not allowed by api-guardian - +@NullMarked package net.jqwik.api.facades; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/api/src/main/java/net/jqwik/api/footnotes/package-info.java b/api/src/main/java/net/jqwik/api/footnotes/package-info.java index 8fb8b03d1..3eabfaace 100644 --- a/api/src/main/java/net/jqwik/api/footnotes/package-info.java +++ b/api/src/main/java/net/jqwik/api/footnotes/package-info.java @@ -1,4 +1,4 @@ @NullMarked package net.jqwik.api.footnotes; -import org.jspecify.annotations.*; \ No newline at end of file +import org.jspecify.annotations.*; diff --git a/api/src/main/java/net/jqwik/api/lifecycle/Store.java b/api/src/main/java/net/jqwik/api/lifecycle/Store.java index 3d3877a50..61eb2bbbc 100644 --- a/api/src/main/java/net/jqwik/api/lifecycle/Store.java +++ b/api/src/main/java/net/jqwik/api/lifecycle/Store.java @@ -6,6 +6,8 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; /** @@ -31,11 +33,11 @@ abstract class StoreFacade { implementation = FacadeLoader.load(Store.StoreFacade.class); } - public abstract Store create(Object identifier, Lifespan visibility, Supplier initialValueSupplier); + public abstract Store create(Object identifier, Lifespan visibility, Supplier initialValueSupplier); - public abstract Store get(Object identifier); + public abstract Store get(Object identifier); - public abstract Store free(Supplier initialValueSupplier); + public abstract Store free(Supplier initialValueSupplier); } /** @@ -63,7 +65,7 @@ interface CloseOnReset { * @param initialValueSupplier Supplies the value to be used for initializing the store depending on its lifespan * @return New store instance */ - static Store create(Object identifier, Lifespan lifespan, Supplier initialValueSupplier) { + static Store create(Object identifier, Lifespan lifespan, Supplier initialValueSupplier) { return StoreFacade.implementation.create(identifier, lifespan, initialValueSupplier); } @@ -82,7 +84,7 @@ static Store create(Object identifier, Lifespan lifespan, Supplier ini * @param initialValueSupplier Supplies the value to be used for initializing the store depending on its lifespan * @return New or existing store instance */ - static Store getOrCreate(Object identifier, Lifespan lifespan, Supplier initialValueSupplier) { + static Store getOrCreate(Object identifier, Lifespan lifespan, Supplier initialValueSupplier) { try { Store store = Store.get(identifier); if (!store.lifespan().equals(lifespan)) { @@ -107,7 +109,7 @@ static Store getOrCreate(Object identifier, Lifespan lifespan, Supplier Store get(Object identifier) { + static Store get(Object identifier) { return StoreFacade.implementation.get(identifier); } @@ -119,7 +121,7 @@ static Store get(Object identifier) { * @return New store instance */ @API(status = EXPERIMENTAL, since = "1.5.0") - static Store free(Supplier initializer) { + static Store free(Supplier initializer) { return StoreFacade.implementation.free(initializer); } } diff --git a/api/src/main/java/net/jqwik/api/package-info.java b/api/src/main/java/net/jqwik/api/package-info.java index 4269e07c0..89e01a538 100644 --- a/api/src/main/java/net/jqwik/api/package-info.java +++ b/api/src/main/java/net/jqwik/api/package-info.java @@ -1,4 +1,4 @@ @NullMarked package net.jqwik.api; -import org.jspecify.annotations.*; \ No newline at end of file +import org.jspecify.annotations.*; diff --git a/api/src/main/java/net/jqwik/api/providers/package-info.java b/api/src/main/java/net/jqwik/api/providers/package-info.java index 5d1718924..b00b6fe58 100644 --- a/api/src/main/java/net/jqwik/api/providers/package-info.java +++ b/api/src/main/java/net/jqwik/api/providers/package-info.java @@ -1,4 +1,4 @@ @NullMarked package net.jqwik.api.providers; -import org.jspecify.annotations.*; \ No newline at end of file +import org.jspecify.annotations.*; diff --git a/api/src/main/java/net/jqwik/api/sessions/package-info.java b/api/src/main/java/net/jqwik/api/sessions/package-info.java index bb70147d0..dc00a88df 100644 --- a/api/src/main/java/net/jqwik/api/sessions/package-info.java +++ b/api/src/main/java/net/jqwik/api/sessions/package-info.java @@ -1,4 +1,4 @@ @NullMarked package net.jqwik.api.sessions; -import org.jspecify.annotations.*; \ No newline at end of file +import org.jspecify.annotations.*; diff --git a/api/src/main/java/net/jqwik/api/state/Action.java b/api/src/main/java/net/jqwik/api/state/Action.java index 73a5909ad..1ab18f4f7 100644 --- a/api/src/main/java/net/jqwik/api/state/Action.java +++ b/api/src/main/java/net/jqwik/api/state/Action.java @@ -6,6 +6,8 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; /** @@ -30,33 +32,33 @@ * @see ActionChainArbitrary */ @API(status = EXPERIMENTAL, since = "1.7.0") -public interface Action { +public interface Action { /** * Create an unconditioned {@linkplain ActionBuilder}. */ - static ActionBuilder builder() { + static ActionBuilder builder() { return new ActionBuilder(); } /** * Create an {@linkplain ActionBuilder} with a precondition. */ - static ActionBuilder when(Predicate precondition) { + static ActionBuilder when(Predicate precondition) { return new ActionBuilder().when(precondition); } /** * Convenience method to create an independent {@linkplain Action} with a constant transformer */ - static Action.Independent just(Transformer transformer) { + static Action.Independent just(Transformer transformer) { return Action.builder().just(transformer); } /** * Convenience method to create an independent {@linkplain Action} with a description and a constant transformer */ - static Action.Independent just(String description, Transformer transformer) { + static Action.Independent just(String description, Transformer transformer) { return Action.builder().describeAs(description).just(transformer); } @@ -82,7 +84,7 @@ default boolean precondition(S state) { *

*/ @FunctionalInterface - interface Dependent extends Action { + interface Dependent extends Action { /** * Return an arbitrary for transformers that depends on the previous state. * @@ -109,7 +111,7 @@ interface Dependent extends Action { * @see JustTransform */ @FunctionalInterface - interface Independent extends Action { + interface Independent extends Action { /** * Return an arbitrary for transformers that does not depend on the previous state. * @@ -136,7 +138,7 @@ interface Independent extends Action { * you have to implement either {@linkplain Action.Dependent} or {@linkplain Action.Independent}. *

*/ - abstract class JustTransform implements Action.Independent { + abstract class JustTransform implements Action.Independent { @Override public Arbitrary> transformer() { @@ -166,7 +168,7 @@ String description() { * you have to implement either {@linkplain Action.Dependent} or {@linkplain Action.Independent}. *

*/ - abstract class JustMutate implements Action.Independent { + abstract class JustMutate implements Action.Independent { @Override public Arbitrary> transformer() { diff --git a/api/src/main/java/net/jqwik/api/state/ActionBuilder.java b/api/src/main/java/net/jqwik/api/state/ActionBuilder.java index 0adf57740..ceb414597 100644 --- a/api/src/main/java/net/jqwik/api/state/ActionBuilder.java +++ b/api/src/main/java/net/jqwik/api/state/ActionBuilder.java @@ -27,24 +27,22 @@ * @param Type of the object to transform through an action */ @API(status = EXPERIMENTAL, since = "1.7.0") -public class ActionBuilder { +public class ActionBuilder { - @Nullable - final private Predicate precondition; + final private @Nullable Predicate precondition; - @Nullable - final private String description; + final private @Nullable String description; ActionBuilder() { this(null, null); } - private ActionBuilder(@Nullable Predicate precondition, @Nullable String description) { + private ActionBuilder(@Nullable Predicate precondition, @Nullable String description) { this.precondition = precondition; this.description = description; } - public ActionBuilder when(Predicate precondition) { + public ActionBuilder when(Predicate precondition) { return new ActionBuilder<>(precondition, description); } @@ -69,7 +67,6 @@ public boolean precondition(S state) { }; } - @NonNull private Arbitrary> justTransformer(Transformer transformer) { Transformer withDescription = description == null ? transformer : Transformer.transform(description, transformer); return Arbitraries.just(withDescription); diff --git a/api/src/main/java/net/jqwik/api/state/ActionChain.java b/api/src/main/java/net/jqwik/api/state/ActionChain.java index a39ac42b3..e874f31e6 100644 --- a/api/src/main/java/net/jqwik/api/state/ActionChain.java +++ b/api/src/main/java/net/jqwik/api/state/ActionChain.java @@ -23,7 +23,7 @@ * @param The type of the object going through state transformations */ @API(status = EXPERIMENTAL, since = "1.7.0") -public interface ActionChain { +public interface ActionChain { @API(status = INTERNAL) abstract class ActionChainFacade { @@ -33,7 +33,7 @@ abstract class ActionChainFacade { implementation = FacadeLoader.load(ActionChainFacade.class); } - public abstract ActionChainArbitrary startWith(Supplier initialSupplier); + public abstract ActionChainArbitrary startWith(Supplier initialSupplier); } /** @@ -43,7 +43,7 @@ abstract class ActionChainFacade { * @param The type of state to be transformed through the chain. * @return new arbitrary instance */ - static ActionChainArbitrary startWith(Supplier initialSupplier) { + static ActionChainArbitrary startWith(Supplier initialSupplier) { return ActionChainFacade.implementation.startWith(initialSupplier); } @@ -136,6 +136,6 @@ default ActionChain withInvariant(Consumer invariant) { * @param peeker A consumer of a state object * @return the same chain instance */ - ActionChain peek(Consumer peeker); + ActionChain peek(Consumer peeker); } diff --git a/api/src/main/java/net/jqwik/api/state/Chain.java b/api/src/main/java/net/jqwik/api/state/Chain.java index 53b799a45..348393200 100644 --- a/api/src/main/java/net/jqwik/api/state/Chain.java +++ b/api/src/main/java/net/jqwik/api/state/Chain.java @@ -7,6 +7,8 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; /** @@ -28,7 +30,7 @@ * @param The type of state to be transformed in a chain */ @API(status = EXPERIMENTAL, since = "1.7.0") -public interface Chain extends Iterable { +public interface Chain extends Iterable { @API(status = INTERNAL) abstract class ChainFacade { @@ -38,7 +40,7 @@ abstract class ChainFacade { implementation = FacadeLoader.load(ChainFacade.class); } - public abstract ChainArbitrary startWith(Supplier initialSupplier); + public abstract ChainArbitrary startWith(Supplier initialSupplier); } /** @@ -48,7 +50,7 @@ abstract class ChainFacade { * @param The type of state to be transformed through the chain. * @return new arbitrary instance */ - static ChainArbitrary startWith(Supplier initialSupplier) { + static ChainArbitrary startWith(Supplier initialSupplier) { return ChainFacade.implementation.startWith(initialSupplier); } diff --git a/api/src/main/java/net/jqwik/api/state/ChainArbitrary.java b/api/src/main/java/net/jqwik/api/state/ChainArbitrary.java index fff13bff8..12d24ca2f 100644 --- a/api/src/main/java/net/jqwik/api/state/ChainArbitrary.java +++ b/api/src/main/java/net/jqwik/api/state/ChainArbitrary.java @@ -61,6 +61,6 @@ default ChainArbitrary infinite() { * * @return new instance of arbitrary */ - ChainArbitrary improveShrinkingWith(Supplier> detectorSupplier); + ChainArbitrary improveShrinkingWith(Supplier> detectorSupplier); } diff --git a/api/src/main/java/net/jqwik/api/state/ChangeDetector.java b/api/src/main/java/net/jqwik/api/state/ChangeDetector.java index 63f3599ee..b66c358d7 100644 --- a/api/src/main/java/net/jqwik/api/state/ChangeDetector.java +++ b/api/src/main/java/net/jqwik/api/state/ChangeDetector.java @@ -4,6 +4,7 @@ import java.util.function.*; import org.apiguardian.api.*; +import org.jspecify.annotations.*; import static org.apiguardian.api.API.Status.*; @@ -18,14 +19,14 @@ * @see ActionChainArbitrary#improveShrinkingWith(Supplier) */ @API(status = EXPERIMENTAL, since = "1.7.0") -public interface ChangeDetector { +public interface ChangeDetector { /** * A change detector that can be used for immutable types that implement an equals() method * @param the type of the stateful object * @return new instance of change detector */ - static ChangeDetector forImmutables() { + static ChangeDetector forImmutables() { return new ChangeDetector() { private T before = null; @@ -42,14 +43,14 @@ public boolean hasChanged(T after) { } @API(status = INTERNAL) - static ChangeDetector alwaysTrue() { - return new ChangeDetector() { + static ChangeDetector<@Nullable Object> alwaysTrue() { + return new ChangeDetector<@Nullable Object>() { @Override - public void before(T before) { + public void before(@Nullable Object before) { } @Override - public boolean hasChanged(T after) { + public boolean hasChanged(@Nullable Object after) { return true; } }; diff --git a/api/src/main/java/net/jqwik/api/state/Transformation.java b/api/src/main/java/net/jqwik/api/state/Transformation.java index ae5fe0294..d0efbd2db 100644 --- a/api/src/main/java/net/jqwik/api/state/Transformation.java +++ b/api/src/main/java/net/jqwik/api/state/Transformation.java @@ -6,6 +6,8 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; /** @@ -65,7 +67,7 @@ public Arbitrary> apply(Supplier supplier) { /** * Create a TransformerProvider with a precondition */ - static Builder when(Predicate precondition) { + static Builder when(Predicate precondition) { return new Builder(precondition); } diff --git a/api/src/main/java/net/jqwik/api/state/Transformer.java b/api/src/main/java/net/jqwik/api/state/Transformer.java index ba9488415..05f6de95e 100644 --- a/api/src/main/java/net/jqwik/api/state/Transformer.java +++ b/api/src/main/java/net/jqwik/api/state/Transformer.java @@ -24,14 +24,14 @@ */ @FunctionalInterface @API(status = EXPERIMENTAL, since = "1.7.0") -public interface Transformer extends Function<@NonNull T, @NonNull T> { +public interface Transformer extends Function { /** * The singleton object used for all calls to {@linkplain #endOfChain()}. */ Transformer END_OF_CHAIN = new Transformer() { @Override - public @NonNull Object apply(@NonNull Object t) { + public Object apply(Object t) { return t; } @@ -56,7 +56,7 @@ public String toString() { */ Transformer NOOP = new Transformer() { @Override - public @NonNull Object apply(@NonNull Object t) { + public Object apply(Object t) { return t; } @@ -88,7 +88,7 @@ public String toString() { * @return a transformer instance */ @SuppressWarnings("unchecked") - static Transformer endOfChain() { + static Transformer endOfChain() { return (Transformer) END_OF_CHAIN; } @@ -117,7 +117,7 @@ static Transformer noop() { * @param The type of the state to transform * @return a new instance of a transformer */ - static Transformer transform(String description, Function transform) { + static Transformer transform(String description, Function transform) { return new Transformer() { @Override public S apply(S s) { @@ -140,7 +140,7 @@ public String transformation() { * @param The type of the state to mutate * @return a new instance of a transformer */ - static Transformer mutate(String description, Consumer mutate) { + static Transformer mutate(String description, Consumer mutate) { Function transformer = s -> { mutate.accept(s); return s; diff --git a/api/src/main/java/net/jqwik/api/state/package-info.java b/api/src/main/java/net/jqwik/api/state/package-info.java index 01b997530..78b0d10a5 100644 --- a/api/src/main/java/net/jqwik/api/state/package-info.java +++ b/api/src/main/java/net/jqwik/api/state/package-info.java @@ -1,4 +1,4 @@ @NullMarked package net.jqwik.api.state; -import org.jspecify.annotations.*; \ No newline at end of file +import org.jspecify.annotations.*; diff --git a/api/src/main/java/net/jqwik/api/stateful/Action.java b/api/src/main/java/net/jqwik/api/stateful/Action.java index 774ba42b2..3fc69e516 100644 --- a/api/src/main/java/net/jqwik/api/stateful/Action.java +++ b/api/src/main/java/net/jqwik/api/stateful/Action.java @@ -1,6 +1,7 @@ package net.jqwik.api.stateful; import org.apiguardian.api.*; +import org.jspecify.annotations.*; import static org.apiguardian.api.API.Status.*; @@ -13,7 +14,7 @@ * @param Type of the state object */ @API(status = MAINTAINED, since = "1.0") -public interface Action { +public interface Action { /** * If this method returns false, the action will not be performed. diff --git a/api/src/main/java/net/jqwik/api/stateful/ActionSequence.java b/api/src/main/java/net/jqwik/api/stateful/ActionSequence.java index 7ad606a1e..ab67c5de5 100644 --- a/api/src/main/java/net/jqwik/api/stateful/ActionSequence.java +++ b/api/src/main/java/net/jqwik/api/stateful/ActionSequence.java @@ -14,7 +14,7 @@ * @param The type of the model */ @API(status = MAINTAINED, since = "1.0") -public interface ActionSequence { +public interface ActionSequence { enum RunState { NOT_RUN, RUNNING, FAILED, SUCCEEDED diff --git a/api/src/main/java/net/jqwik/api/stateful/ActionSequenceArbitrary.java b/api/src/main/java/net/jqwik/api/stateful/ActionSequenceArbitrary.java index ab6ba0379..021687c90 100644 --- a/api/src/main/java/net/jqwik/api/stateful/ActionSequenceArbitrary.java +++ b/api/src/main/java/net/jqwik/api/stateful/ActionSequenceArbitrary.java @@ -4,10 +4,12 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; @API(status = MAINTAINED, since = "1.0") -public interface ActionSequenceArbitrary extends Arbitrary> { +public interface ActionSequenceArbitrary extends Arbitrary> { /** * Set the intended number of steps of this sequence. diff --git a/api/src/main/java/net/jqwik/api/stateful/Invariant.java b/api/src/main/java/net/jqwik/api/stateful/Invariant.java index ea56e098a..6ae669657 100644 --- a/api/src/main/java/net/jqwik/api/stateful/Invariant.java +++ b/api/src/main/java/net/jqwik/api/stateful/Invariant.java @@ -1,12 +1,13 @@ package net.jqwik.api.stateful; import org.apiguardian.api.*; +import org.jspecify.annotations.*; import static org.apiguardian.api.API.Status.*; @FunctionalInterface @API(status = MAINTAINED, since = "1.0") -public interface Invariant { +public interface Invariant { void check(T model); } diff --git a/api/src/main/java/net/jqwik/api/stateful/package-info.java b/api/src/main/java/net/jqwik/api/stateful/package-info.java index 2c36d5d7b..a187f3992 100644 --- a/api/src/main/java/net/jqwik/api/stateful/package-info.java +++ b/api/src/main/java/net/jqwik/api/stateful/package-info.java @@ -1,4 +1,4 @@ @NullMarked package net.jqwik.api.stateful; -import org.jspecify.annotations.*; \ No newline at end of file +import org.jspecify.annotations.*; diff --git a/api/src/main/java/net/jqwik/api/statistics/StatisticsCoverage.java b/api/src/main/java/net/jqwik/api/statistics/StatisticsCoverage.java index 03856d196..975a1f9dc 100644 --- a/api/src/main/java/net/jqwik/api/statistics/StatisticsCoverage.java +++ b/api/src/main/java/net/jqwik/api/statistics/StatisticsCoverage.java @@ -22,7 +22,7 @@ interface CoverageChecker { * * @param countChecker a predicate to accept a selected value set's number of occurrences */ - void count(Predicate countChecker); + void count(Predicate countChecker); /** * Check the number of occurrences using one or more assertions. @@ -31,14 +31,14 @@ interface CoverageChecker { * and the count of all submitted value sets to compare with * or make a calculation */ - void count(BiPredicate countChecker); + void count(BiPredicate countChecker); /** * Check the number of occurrences returning true (ok) or false (fail). * * @param countChecker a predicate to accept a selected value set's number of occurrences */ - void count(Consumer countChecker); + void count(Consumer countChecker); /** * Check the number of occurrences using one or more assertions. @@ -47,7 +47,7 @@ interface CoverageChecker { * and the count of all submitted value sets to compare with * or make a calculation */ - void count(BiConsumer countChecker); + void count(BiConsumer countChecker); /** * Check the percentage of occurrences returning true (ok) or false (fail) @@ -55,7 +55,7 @@ interface CoverageChecker { * @param percentageChecker a predicate to accept a selected value set's * percentage (0.0 - 100.0) of occurrences */ - void percentage(Predicate percentageChecker); + void percentage(Predicate percentageChecker); /** * Check the number of occurrences returning true (ok) or false (fail). @@ -63,7 +63,7 @@ interface CoverageChecker { * @param percentageChecker a predicate to accept a selected value set's * percentage (0.0 - 100.0) of occurrences */ - void percentage(Consumer percentageChecker); + void percentage(Consumer percentageChecker); } diff --git a/api/src/main/java/net/jqwik/api/statistics/package-info.java b/api/src/main/java/net/jqwik/api/statistics/package-info.java index af38415d8..2a52f10c1 100644 --- a/api/src/main/java/net/jqwik/api/statistics/package-info.java +++ b/api/src/main/java/net/jqwik/api/statistics/package-info.java @@ -1,4 +1,4 @@ @NullMarked package net.jqwik.api.statistics; -import org.jspecify.annotations.*; \ No newline at end of file +import org.jspecify.annotations.*; diff --git a/api/src/main/java/net/jqwik/api/support/CollectorsSupport.java b/api/src/main/java/net/jqwik/api/support/CollectorsSupport.java index aad1eb313..acdc301a4 100644 --- a/api/src/main/java/net/jqwik/api/support/CollectorsSupport.java +++ b/api/src/main/java/net/jqwik/api/support/CollectorsSupport.java @@ -4,6 +4,7 @@ import java.util.stream.*; import org.apiguardian.api.*; +import org.jspecify.annotations.*; import static org.apiguardian.api.API.Status.*; @@ -16,7 +17,7 @@ public class CollectorsSupport { private CollectorsSupport() {} - public static Collector> toLinkedHashSet() { + public static Collector> toLinkedHashSet() { return Collectors.toCollection(LinkedHashSet::new); } } diff --git a/api/src/main/java/net/jqwik/api/support/HashCodeSupport.java b/api/src/main/java/net/jqwik/api/support/HashCodeSupport.java index 41ec8bf90..120a2c386 100644 --- a/api/src/main/java/net/jqwik/api/support/HashCodeSupport.java +++ b/api/src/main/java/net/jqwik/api/support/HashCodeSupport.java @@ -19,7 +19,7 @@ public static int hash(@Nullable Object o) { return baseHash(o) + 31; } - private static int baseHash(Object o) { + private static int baseHash(@Nullable Object o) { if (o == null) return 0; return o.hashCode(); diff --git a/documentation/src/docs/include/customized-parameter-generation.md b/documentation/src/docs/include/customized-parameter-generation.md index 264bf2a8c..b309f76f9 100644 --- a/documentation/src/docs/include/customized-parameter-generation.md +++ b/documentation/src/docs/include/customized-parameter-generation.md @@ -801,7 +801,7 @@ for the two String values - using `tuple2()` does that. If you want to include only part of all the values generated by an arbitrary, use -[`Arbitrary.filter(Predicate filterPredicate)`](/docs/${docsVersion}/javadoc/net/jqwik/api/Arbitrary.html#filter(java.util.function.Predicate)). +[`Arbitrary.filter(Predicate filterPredicate)`](/docs/${docsVersion}/javadoc/net/jqwik/api/Arbitrary.html#filter(java.util.function.Predicate)). The following arbitrary will filter out all even numbers from the stream of generated integers: diff --git a/documentation/src/test/java/net/jqwik/docs/arbitraryconfigurator/OddConfigurator.java b/documentation/src/test/java/net/jqwik/docs/arbitraryconfigurator/OddConfigurator.java index 859f849fc..d4ac20b9f 100644 --- a/documentation/src/test/java/net/jqwik/docs/arbitraryconfigurator/OddConfigurator.java +++ b/documentation/src/test/java/net/jqwik/docs/arbitraryconfigurator/OddConfigurator.java @@ -6,6 +6,8 @@ import net.jqwik.api.configurators.*; import net.jqwik.api.providers.*; +import org.jspecify.annotations.*; + public class OddConfigurator extends ArbitraryConfiguratorBase { public Arbitrary configureInteger(Arbitrary arbitrary, Odd odd) { @@ -22,7 +24,7 @@ public Arbitrary configureBigInteger(Arbitrary arbitrary class PlainOddConfigurator implements ArbitraryConfigurator { @Override - public Arbitrary configure(Arbitrary arbitrary, TypeUsage targetType) { + public Arbitrary configure(Arbitrary arbitrary, TypeUsage targetType) { if (!targetType.isOfType(Integer.class) && !targetType.isOfType(int.class)) { return arbitrary; } diff --git a/engine/src/main/java/net/jqwik/engine/descriptor/package-info.java b/engine/src/main/java/net/jqwik/engine/descriptor/package-info.java new file mode 100644 index 000000000..947646bd9 --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/descriptor/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine.descriptor; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/main/java/net/jqwik/engine/discovery/package-info.java b/engine/src/main/java/net/jqwik/engine/discovery/package-info.java new file mode 100644 index 000000000..4743bc28a --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/discovery/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine.discovery; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/main/java/net/jqwik/engine/discovery/predicates/package-info.java b/engine/src/main/java/net/jqwik/engine/discovery/predicates/package-info.java new file mode 100644 index 000000000..b8a34a95b --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/discovery/predicates/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine.discovery.predicates; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/main/java/net/jqwik/engine/discovery/specs/package-info.java b/engine/src/main/java/net/jqwik/engine/discovery/specs/package-info.java new file mode 100644 index 000000000..3814bf3fd --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/discovery/specs/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine.discovery.specs; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/main/java/net/jqwik/engine/execution/ContainerInstancesCreator.java b/engine/src/main/java/net/jqwik/engine/execution/ContainerInstancesCreator.java index 15f429a32..d9265efce 100644 --- a/engine/src/main/java/net/jqwik/engine/execution/ContainerInstancesCreator.java +++ b/engine/src/main/java/net/jqwik/engine/execution/ContainerInstancesCreator.java @@ -3,6 +3,7 @@ import java.lang.reflect.*; import java.util.*; +import org.jspecify.annotations.*; import org.junit.platform.engine.*; import net.jqwik.api.*; @@ -84,7 +85,7 @@ private ContainerInstances newInstancesOfBaseContainer(Constructor constructo return new ContainerInstances(createNewInstance(constructor, null)); } - private Object createNewInstance(Constructor constructor, Object outerInstance) { + private Object createNewInstance(Constructor constructor, @Nullable Object outerInstance) { return JqwikReflectionSupport.newInstance( constructor, resolveConstructorParameters(constructor, outerInstance) @@ -111,7 +112,7 @@ private List> allAccessibleConstructors(Class instanceClass) { private Object[] resolveConstructorParameters( Constructor constructor, - Object outerInstance + @Nullable Object outerInstance ) { Object[] args = new Object[constructor.getParameterCount()]; for (int i = 0; i < args.length; i++) { diff --git a/engine/src/main/java/net/jqwik/engine/execution/GenerationInfo.java b/engine/src/main/java/net/jqwik/engine/execution/GenerationInfo.java index c93cb5ff2..6bee9a491 100644 --- a/engine/src/main/java/net/jqwik/engine/execution/GenerationInfo.java +++ b/engine/src/main/java/net/jqwik/engine/execution/GenerationInfo.java @@ -8,26 +8,28 @@ import net.jqwik.api.lifecycle.*; import net.jqwik.engine.properties.shrinking.*; +import org.jspecify.annotations.*; + public class GenerationInfo implements Serializable { public final static GenerationInfo NULL = new GenerationInfo(null); - private final String randomSeed; + private final @Nullable String randomSeed; private final int generationIndex; // Store ordinals instead of enum objects so that serialization // in jqwik.database uses less disk space private final List> byteSequences; - public GenerationInfo(String randomSeed) { + public GenerationInfo(@Nullable String randomSeed) { this(randomSeed, 0); } - public GenerationInfo(String randomSeed, int generationIndex) { + public GenerationInfo(@Nullable String randomSeed, int generationIndex) { this(randomSeed, generationIndex, Collections.emptyList()); } - private GenerationInfo(String randomSeed, int generationIndex, List> byteSequences) { + private GenerationInfo(@Nullable String randomSeed, int generationIndex, List> byteSequences) { this.randomSeed = randomSeed != null ? (randomSeed.isEmpty() ? null : randomSeed) : null; this.generationIndex = generationIndex; this.byteSequences = byteSequences; @@ -59,7 +61,7 @@ public Optional>> generateOn(ParametersGenerator generat return useShrinkingSequences(sample); } - private Optional>> useShrinkingSequences(List> sample) { + private Optional>> useShrinkingSequences(@Nullable List> sample) { Optional>> shrunkSample = Optional.ofNullable(sample); for (List shrinkingSequence : shrinkingSequences()) { if (!shrunkSample.isPresent()) { @@ -78,7 +80,7 @@ private Optional>> shrink( return recreator.recreateFrom(shrinkingSequence); } - private List> useGenerationIndex(ParametersGenerator generator, TryLifecycleContext context) { + private @Nullable List> useGenerationIndex(ParametersGenerator generator, TryLifecycleContext context) { List> sample = null; for (int i = 0; i < generationIndex; i++) { if (generator.hasNext()) { diff --git a/engine/src/main/java/net/jqwik/engine/execution/lifecycle/CurrentDomainContext.java b/engine/src/main/java/net/jqwik/engine/execution/lifecycle/CurrentDomainContext.java index ac0b7b2c7..c54d70c75 100644 --- a/engine/src/main/java/net/jqwik/engine/execution/lifecycle/CurrentDomainContext.java +++ b/engine/src/main/java/net/jqwik/engine/execution/lifecycle/CurrentDomainContext.java @@ -9,6 +9,8 @@ import net.jqwik.engine.properties.configurators.*; import net.jqwik.engine.providers.*; +import org.jspecify.annotations.*; + public class CurrentDomainContext { public static final DomainContext GLOBAL_DOMAIN_CONTEXT = new GlobalDomainContext(); @@ -22,7 +24,7 @@ public static DomainContext get() { return currentContext.get(); } - public static T runWithContext(DomainContext context, Supplier runnable) { + public static T runWithContext(DomainContext context, Supplier runnable) { currentContext.set(context); try { return runnable.get(); diff --git a/engine/src/main/java/net/jqwik/engine/execution/lifecycle/CurrentTestDescriptor.java b/engine/src/main/java/net/jqwik/engine/execution/lifecycle/CurrentTestDescriptor.java index 608433379..6a80957b2 100644 --- a/engine/src/main/java/net/jqwik/engine/execution/lifecycle/CurrentTestDescriptor.java +++ b/engine/src/main/java/net/jqwik/engine/execution/lifecycle/CurrentTestDescriptor.java @@ -3,6 +3,7 @@ import java.util.*; import java.util.function.*; +import org.jspecify.annotations.*; import org.junit.platform.engine.*; public class CurrentTestDescriptor { @@ -11,7 +12,7 @@ public class CurrentTestDescriptor { // e.g. in JqwikIntegrationTests private static final ThreadLocal> descriptors = ThreadLocal.withInitial(ArrayList::new); - public static T runWithDescriptor(TestDescriptor currentDescriptor, Supplier executable) { + public static T runWithDescriptor(TestDescriptor currentDescriptor, Supplier executable) { push(currentDescriptor); try { return executable.get(); diff --git a/engine/src/main/java/net/jqwik/engine/execution/lifecycle/PlainExecutionResult.java b/engine/src/main/java/net/jqwik/engine/execution/lifecycle/PlainExecutionResult.java index 96881c5d3..087dc7ad7 100644 --- a/engine/src/main/java/net/jqwik/engine/execution/lifecycle/PlainExecutionResult.java +++ b/engine/src/main/java/net/jqwik/engine/execution/lifecycle/PlainExecutionResult.java @@ -6,13 +6,15 @@ import net.jqwik.api.lifecycle.*; import net.jqwik.engine.execution.*; +import org.jspecify.annotations.*; + public class PlainExecutionResult implements ExtendedPropertyExecutionResult { public static ExtendedPropertyExecutionResult successful() { return new PlainExecutionResult(Status.SUCCESSFUL, new GenerationInfo(null), null); } - public static ExtendedPropertyExecutionResult failed(Throwable throwable, String seed) { + public static ExtendedPropertyExecutionResult failed(Throwable throwable, @Nullable String seed) { if (throwable == null) { throw new IllegalArgumentException("throwable must never be null for failed PropertyExecutionResult"); } @@ -32,9 +34,9 @@ public static ExtendedPropertyExecutionResult aborted(Throwable throwable, Gener private final Status status; private final GenerationInfo generationInfo; - private final Throwable throwable; + private final @Nullable Throwable throwable; - private PlainExecutionResult(Status status, GenerationInfo generationInfo, Throwable throwable) { + private PlainExecutionResult(Status status, GenerationInfo generationInfo, @Nullable Throwable throwable) { this.status = status; this.generationInfo = generationInfo; this.throwable = throwable; @@ -56,7 +58,7 @@ public Optional throwable() { } @Override - public PropertyExecutionResult mapTo(Status newStatus, Throwable throwable) { + public PropertyExecutionResult mapTo(Status newStatus, @Nullable Throwable throwable) { return new PlainExecutionResult(newStatus, generationInfo, throwable); } diff --git a/engine/src/main/java/net/jqwik/engine/execution/lifecycle/ScopedStore.java b/engine/src/main/java/net/jqwik/engine/execution/lifecycle/ScopedStore.java index a37a3c58b..aeeb5e9a3 100644 --- a/engine/src/main/java/net/jqwik/engine/execution/lifecycle/ScopedStore.java +++ b/engine/src/main/java/net/jqwik/engine/execution/lifecycle/ScopedStore.java @@ -17,7 +17,7 @@ public class ScopedStore implements Store { private final Object identifier; private final Lifespan lifespan; private final TestDescriptor scope; - private final Supplier initialValueSupplier; + private final Supplier initialValueSupplier; private T value; private boolean initialized = false; @@ -26,7 +26,7 @@ public ScopedStore( Object identifier, Lifespan lifespan, TestDescriptor scope, - Supplier initialValueSupplier + Supplier initialValueSupplier ) { this.identifier = identifier; this.lifespan = lifespan; diff --git a/engine/src/main/java/net/jqwik/engine/execution/lifecycle/StoreRepository.java b/engine/src/main/java/net/jqwik/engine/execution/lifecycle/StoreRepository.java index ecafad478..bf0938db6 100644 --- a/engine/src/main/java/net/jqwik/engine/execution/lifecycle/StoreRepository.java +++ b/engine/src/main/java/net/jqwik/engine/execution/lifecycle/StoreRepository.java @@ -4,6 +4,7 @@ import java.util.function.*; import java.util.stream.*; +import org.jspecify.annotations.*; import org.junit.platform.engine.*; import net.jqwik.api.*; @@ -29,11 +30,11 @@ private static class IdentifiedStores extends LinkedHashMap storesByIdentifier = new LinkedHashMap<>(); - public ScopedStore create( + public ScopedStore create( TestDescriptor scope, Object identifier, Lifespan lifespan, - Supplier initialValueSupplier + Supplier initialValueSupplier ) { if (scope == null) { throw new IllegalArgumentException("scope must not be null"); @@ -52,7 +53,7 @@ public ScopedStore create( return store; } - private void addStore(Object identifier, ScopedStore newStore) { + private void addStore(Object identifier, ScopedStore newStore) { IdentifiedStores identifiedStores = storesByIdentifier.computeIfAbsent(newStore.getIdentifier(), ignore -> new IdentifiedStores()); Optional> conflictingStore = @@ -76,11 +77,11 @@ private void addStore(Object identifier, ScopedStore newStore) { storesByIdentifier.put(identifier, identifiedStores); } - private boolean isVisibleInAncestorOrDescendant(ScopedStore newStore, ScopedStore store) { + private boolean isVisibleInAncestorOrDescendant(ScopedStore newStore, ScopedStore store) { return store.isVisibleFor(newStore.getScope()) || newStore.isVisibleFor(store.getScope()); } - public Optional> get(TestDescriptor retriever, Object identifier) { + public Optional> get(TestDescriptor retriever, Object identifier) { if (identifier == null) { throw new IllegalArgumentException("identifier must not be null"); } @@ -94,7 +95,7 @@ public Optional> get(TestDescriptor retriever, Object identif } @SuppressWarnings("unchecked") - private Optional> getFirstVisibleStore(TestDescriptor retriever, IdentifiedStores identifiedStores) { + private Optional> getFirstVisibleStore(TestDescriptor retriever, IdentifiedStores identifiedStores) { return identifiedStores.values() .stream() .filter(store -> store.isVisibleFor(retriever)) diff --git a/engine/src/main/java/net/jqwik/engine/execution/lifecycle/package-info.java b/engine/src/main/java/net/jqwik/engine/execution/lifecycle/package-info.java new file mode 100644 index 000000000..5a16582fd --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/execution/lifecycle/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine.execution.lifecycle; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/main/java/net/jqwik/engine/execution/package-info.java b/engine/src/main/java/net/jqwik/engine/execution/package-info.java new file mode 100644 index 000000000..f1ba68d50 --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/execution/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine.execution; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/main/java/net/jqwik/engine/execution/pipeline/package-info.java b/engine/src/main/java/net/jqwik/engine/execution/pipeline/package-info.java new file mode 100644 index 000000000..af3be6ad5 --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/execution/pipeline/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine.execution.pipeline; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/main/java/net/jqwik/engine/execution/reporting/ParameterChangesDetector.java b/engine/src/main/java/net/jqwik/engine/execution/reporting/ParameterChangesDetector.java index e30b8797d..7eda43963 100644 --- a/engine/src/main/java/net/jqwik/engine/execution/reporting/ParameterChangesDetector.java +++ b/engine/src/main/java/net/jqwik/engine/execution/reporting/ParameterChangesDetector.java @@ -5,13 +5,15 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + class ParameterChangesDetector { - static boolean haveParametersChanged(List before, List after) { + static boolean haveParametersChanged(List before, List after) { return atLeastOneParameterHasChanged(before, after); } - private static boolean atLeastOneParameterHasChanged(List before, List after) { + private static boolean atLeastOneParameterHasChanged(List before, List after) { if (before.size() != after.size()) { return true; } @@ -25,11 +27,11 @@ private static boolean atLeastOneParameterHasChanged(List before, List ActionChainArbitrary startWith(Supplier initialSupplier) { + public ActionChainArbitrary startWith(Supplier initialSupplier) { return new DefaultActionChainArbitrary<>(initialSupplier); } } diff --git a/engine/src/main/java/net/jqwik/engine/facades/ArbitrariesFacadeImpl.java b/engine/src/main/java/net/jqwik/engine/facades/ArbitrariesFacadeImpl.java index f4a318285..4083b2ab2 100644 --- a/engine/src/main/java/net/jqwik/engine/facades/ArbitrariesFacadeImpl.java +++ b/engine/src/main/java/net/jqwik/engine/facades/ArbitrariesFacadeImpl.java @@ -41,7 +41,7 @@ public ActionSequenceArbitrary sequences(Arbitrary> a } @Override - public Arbitrary frequencyOf(List>> frequencies) { + public Arbitrary frequencyOf(List>> frequencies) { List>> aboveZeroFrequencies = frequencies.stream().filter(f -> f.get1() > 0).collect(Collectors.toList()); @@ -107,12 +107,12 @@ public CharacterArbitrary chars() { } @Override - public Arbitrary lazy(Supplier> arbitrarySupplier) { + public Arbitrary lazy(Supplier> arbitrarySupplier) { return new LazyArbitrary<>(arbitrarySupplier); } @Override - public Arbitrary lazyOf(List>> suppliers) { + public Arbitrary lazyOf(List>> suppliers) { int hashIdentifier = calculateIdentifier(suppliers.size()); return LazyOfArbitrary.of(hashIdentifier, suppliers); } @@ -128,28 +128,28 @@ public Arbitrary of(char[] chars) { } @Override - public Arbitrary of(Collection values) { + public Arbitrary of(Collection values) { List valueList = values instanceof List ? (List) values : new ArrayList<>(values); return new ChooseValueArbitrary<>(valueList); } @Override - public Arbitrary create(Supplier supplier) { + public Arbitrary create(Supplier supplier) { return new CreateArbitrary<>(supplier); } @Override - public Arbitrary> shuffle(List values) { + public Arbitrary> shuffle(List values) { return new ShuffleArbitrary<>(values); } @Override - public Arbitrary fromGenerator(IntFunction> generatorSupplier) { + public Arbitrary fromGenerator(IntFunction> generatorSupplier) { return new FromGeneratorWithSizeArbitrary<>(generatorSupplier); } @Override - public Arbitrary frequency(List> frequencies) { + public Arbitrary frequency(List> frequencies) { List> frequenciesAbove0 = frequencies.stream() .filter(f -> f.get1() > 0) .collect(Collectors.toList()); @@ -199,10 +199,10 @@ public Arbitrary defaultFor(Class type, Class[] typeParameters) { @SuppressWarnings("unchecked") @Override - public Arbitrary defaultFor(TypeUsage typeUsage, Function> noDefaultResolver) { + public Arbitrary defaultFor(TypeUsage typeUsage, Function> noDefaultResolver) { Set> arbitraries = allDefaultsFor(typeUsage, noDefaultResolver); if (arbitraries.isEmpty()) { - return (Arbitrary) noDefaultResolver.apply(typeUsage); + return noDefaultResolver.apply(typeUsage); } List> arbitrariesList = new ArrayList<>(); @@ -216,18 +216,18 @@ public TypeArbitrary forType(Class targetType) { } @Override - public MapArbitrary maps(Arbitrary keysArbitrary, Arbitrary valuesArbitrary) { + public MapArbitrary maps(Arbitrary keysArbitrary, Arbitrary valuesArbitrary) { // The map cannot be larger than the max number of possible keys return new DefaultMapArbitrary<>(keysArbitrary, valuesArbitrary) .ofMaxSize(maxNumberOfElements(keysArbitrary, RandomGenerators.DEFAULT_COLLECTION_SIZE)); } @Override - public Arbitrary> entries(Arbitrary keysArbitrary, Arbitrary valuesArbitrary) { + public Arbitrary> entries(Arbitrary keysArbitrary, Arbitrary valuesArbitrary) { return Combinators.combine(keysArbitrary, valuesArbitrary).as(AbstractMap.SimpleEntry::new); } - private static Set> allDefaultsFor(TypeUsage typeUsage, Function> noDefaultResolver) { + private static Set> allDefaultsFor(TypeUsage typeUsage, Function> noDefaultResolver) { DomainContext domainContext = CurrentDomainContext.get(); Set> unconfiguredArbitraries = createDefaultArbitraries(typeUsage, noDefaultResolver, domainContext); return configureDefaultArbitraries(typeUsage, domainContext, unconfiguredArbitraries); @@ -246,7 +246,7 @@ private static Set> configureDefaultArbitraries( private static Set> createDefaultArbitraries( TypeUsage typeUsage, - Function> noDefaultResolver, + Function> noDefaultResolver, DomainContext domainContext ) { RegisteredArbitraryResolver defaultArbitraryResolver = new RegisteredArbitraryResolver(domainContext.getArbitraryProviders()); @@ -286,7 +286,7 @@ private static Set> createDefaultArbitraries( } } - private Arbitrary recursive( + private Arbitrary recursive( Supplier> base, Function, ? extends Arbitrary> recur, int depth diff --git a/engine/src/main/java/net/jqwik/engine/facades/ArbitraryFacadeImpl.java b/engine/src/main/java/net/jqwik/engine/facades/ArbitraryFacadeImpl.java index 5bf580f7d..5e563b00f 100644 --- a/engine/src/main/java/net/jqwik/engine/facades/ArbitraryFacadeImpl.java +++ b/engine/src/main/java/net/jqwik/engine/facades/ArbitraryFacadeImpl.java @@ -10,6 +10,8 @@ import net.jqwik.engine.properties.arbitraries.*; import net.jqwik.engine.properties.arbitraries.randomized.*; +import org.jspecify.annotations.*; + import static net.jqwik.engine.properties.arbitraries.ArbitrariesSupport.*; /** @@ -18,54 +20,54 @@ public class ArbitraryFacadeImpl extends Arbitrary.ArbitraryFacade { @Override - public ListArbitrary list(Arbitrary elementArbitrary) { + public ListArbitrary list(Arbitrary elementArbitrary) { return new DefaultListArbitrary<>(elementArbitrary); } @Override - public SetArbitrary set(Arbitrary elementArbitrary) { + public SetArbitrary set(Arbitrary elementArbitrary) { // The set can never be larger than the max number of possible elements return new DefaultSetArbitrary<>(elementArbitrary) .ofMaxSize(maxNumberOfElements(elementArbitrary, RandomGenerators.DEFAULT_COLLECTION_SIZE)); } @Override - public StreamArbitrary stream(Arbitrary elementArbitrary) { + public StreamArbitrary stream(Arbitrary elementArbitrary) { return new DefaultStreamArbitrary<>(elementArbitrary); } @Override - public IteratorArbitrary iterator(Arbitrary elementArbitrary) { + public IteratorArbitrary iterator(Arbitrary elementArbitrary) { return new DefaultIteratorArbitrary<>(elementArbitrary); } @Override - public ArrayArbitrary array(Arbitrary elementArbitrary, Class arrayClass) { + public ArrayArbitrary array(Arbitrary elementArbitrary, Class arrayClass) { return DefaultArrayArbitrary.forArrayType(elementArbitrary, arrayClass); } @Override - public Arbitrary filter(Arbitrary self, Predicate filterPredicate, int maxMisses) { + public Arbitrary filter(Arbitrary self, Predicate filterPredicate, int maxMisses) { return new ArbitraryFilter<>(self, filterPredicate, maxMisses); } @Override - public Arbitrary map(Arbitrary self, Function mapper) { + public Arbitrary map(Arbitrary self, Function mapper) { return new ArbitraryMap<>(self, mapper); } @Override - public Arbitrary flatMap(Arbitrary self, Function> mapper) { + public Arbitrary flatMap(Arbitrary self, Function> mapper) { return new ArbitraryFlatMap<>(self, mapper); } @Override - public Stream sampleStream(Arbitrary arbitrary) { + public Stream sampleStream(Arbitrary arbitrary) { return new SampleStreamFacade().sampleStream(arbitrary); } @Override - public Arbitrary injectNull(Arbitrary self, double nullProbability) { + public Arbitrary<@Nullable T> injectNull(Arbitrary self, double nullProbability) { int frequencyNull = (int) Math.round(nullProbability * 1000); int frequencyNotNull = 1000 - frequencyNull; if (frequencyNull <= 0) { @@ -81,7 +83,7 @@ public Arbitrary injectNull(Arbitrary self, double nullProbability) { } @Override - public Arbitrary ignoreExceptions(Arbitrary self, int maxThrows, Class[] exceptionTypes) { + public Arbitrary ignoreExceptions(Arbitrary self, int maxThrows, Class[] exceptionTypes) { if (exceptionTypes.length == 0) { return self; } @@ -110,7 +112,7 @@ public EdgeCases edgeCases(int maxEdgeCases) { } @Override - public Arbitrary dontShrink(Arbitrary self) { + public Arbitrary dontShrink(Arbitrary self) { return new ArbitraryDelegator(self) { @Override public RandomGenerator generator(int genSize) { @@ -130,7 +132,7 @@ public EdgeCases edgeCases(int maxEdgeCases) { } @Override - public Arbitrary configureEdgeCases(Arbitrary self, Consumer> configurator) { + public Arbitrary configureEdgeCases(Arbitrary self, Consumer> configurator) { return new ArbitraryDelegator(self) { @Override public EdgeCases edgeCases(int maxEdgeCases) { @@ -141,7 +143,7 @@ public EdgeCases edgeCases(int maxEdgeCases) { } @Override - public Arbitrary withoutEdgeCases(Arbitrary self) { + public Arbitrary withoutEdgeCases(Arbitrary self) { return new ArbitraryDelegator(self) { @Override public RandomGenerator generator(int genSize, boolean withEdgeCases) { @@ -161,7 +163,7 @@ public RandomGenerator generatorWithEmbeddedEdgeCases(int genSize) { } @Override - public Arbitrary fixGenSize(Arbitrary self, int genSize) { + public Arbitrary fixGenSize(Arbitrary self, int genSize) { return new ArbitraryDelegator(self) { @Override public RandomGenerator generator(int ignoredGenSize) { @@ -176,16 +178,16 @@ public RandomGenerator generatorWithEmbeddedEdgeCases(int ignoredGenSize) { } @Override - public Arbitrary> collect(Arbitrary self, Predicate> until) { + public Arbitrary> collect(Arbitrary self, Predicate> until) { return new ArbitraryCollect<>(self, until); } @Override - public RandomGenerator memoizedGenerator(Arbitrary self, int genSize, boolean withEdgeCases) { + public RandomGenerator memoizedGenerator(Arbitrary self, int genSize, boolean withEdgeCases) { return Memoize.memoizedGenerator(self, genSize, withEdgeCases, () -> generator(self, genSize, withEdgeCases)); } - private RandomGenerator generator(Arbitrary arbitrary, int genSize, boolean withEdgeCases) { + private RandomGenerator generator(Arbitrary arbitrary, int genSize, boolean withEdgeCases) { if (withEdgeCases) { int maxEdgeCases = Math.max(genSize, 10); return arbitrary.generatorWithEmbeddedEdgeCases(genSize).withEdgeCases(genSize, arbitrary.edgeCases(maxEdgeCases)); diff --git a/engine/src/main/java/net/jqwik/engine/facades/ChainFacadeImpl.java b/engine/src/main/java/net/jqwik/engine/facades/ChainFacadeImpl.java index e9d5ccbae..28e4d72f0 100644 --- a/engine/src/main/java/net/jqwik/engine/facades/ChainFacadeImpl.java +++ b/engine/src/main/java/net/jqwik/engine/facades/ChainFacadeImpl.java @@ -7,13 +7,15 @@ import net.jqwik.api.state.*; import net.jqwik.engine.properties.state.*; +import org.jspecify.annotations.*; + /** * Is loaded through reflection in api module */ public class ChainFacadeImpl extends Chain.ChainFacade { @Override - public ChainArbitrary startWith(Supplier initialSupplier) { + public ChainArbitrary startWith(Supplier initialSupplier) { return new DefaultChainArbitrary<>(initialSupplier); } diff --git a/engine/src/main/java/net/jqwik/engine/facades/CombinatorsFacadeImpl.java b/engine/src/main/java/net/jqwik/engine/facades/CombinatorsFacadeImpl.java index 27b8dfaa0..54acea4dc 100644 --- a/engine/src/main/java/net/jqwik/engine/facades/CombinatorsFacadeImpl.java +++ b/engine/src/main/java/net/jqwik/engine/facades/CombinatorsFacadeImpl.java @@ -5,6 +5,8 @@ import net.jqwik.api.*; import net.jqwik.engine.properties.arbitraries.combinations.*; +import org.jspecify.annotations.*; + /** * Is loaded through reflection in api module */ @@ -81,7 +83,7 @@ public Combinators.Combinator8 Combinators.ListCombinator combineList(List> listOfArbitraries) { + public Combinators.ListCombinator combineList(List> listOfArbitraries) { return new DefaultListCombinator<>(listOfArbitraries); } diff --git a/engine/src/main/java/net/jqwik/engine/facades/EdgeCasesFacadeImpl.java b/engine/src/main/java/net/jqwik/engine/facades/EdgeCasesFacadeImpl.java index b4b2519c4..4b1b8d96d 100644 --- a/engine/src/main/java/net/jqwik/engine/facades/EdgeCasesFacadeImpl.java +++ b/engine/src/main/java/net/jqwik/engine/facades/EdgeCasesFacadeImpl.java @@ -6,13 +6,15 @@ import net.jqwik.api.*; import net.jqwik.engine.properties.arbitraries.*; +import org.jspecify.annotations.*; + /** * Is loaded through reflection in api module */ public class EdgeCasesFacadeImpl extends EdgeCases.EdgeCasesFacade { @Override - public EdgeCases fromSuppliers(final List>> suppliers) { + public EdgeCases fromSuppliers(final List>> suppliers) { return EdgeCasesSupport.fromSuppliers(suppliers); } diff --git a/engine/src/main/java/net/jqwik/engine/facades/ExhaustiveGeneratorFacadeImpl.java b/engine/src/main/java/net/jqwik/engine/facades/ExhaustiveGeneratorFacadeImpl.java index ef1ae38c4..40ebf0d31 100644 --- a/engine/src/main/java/net/jqwik/engine/facades/ExhaustiveGeneratorFacadeImpl.java +++ b/engine/src/main/java/net/jqwik/engine/facades/ExhaustiveGeneratorFacadeImpl.java @@ -5,27 +5,29 @@ import net.jqwik.api.*; import net.jqwik.engine.properties.arbitraries.exhaustive.*; +import org.jspecify.annotations.*; + /** * Is loaded through reflection in api module */ public class ExhaustiveGeneratorFacadeImpl extends ExhaustiveGenerator.ExhaustiveGeneratorFacade { @Override - public ExhaustiveGenerator map(ExhaustiveGenerator self, Function mapper) { + public ExhaustiveGenerator map(ExhaustiveGenerator self, Function mapper) { return new MappedExhaustiveGenerator<>(self, mapper); } @Override - public ExhaustiveGenerator filter(ExhaustiveGenerator self, Predicate filterPredicate, int maxMisses) { + public ExhaustiveGenerator filter(ExhaustiveGenerator self, Predicate filterPredicate, int maxMisses) { return new FilteredExhaustiveGenerator<>(self, filterPredicate, maxMisses); } @Override - public ExhaustiveGenerator injectNull(ExhaustiveGenerator self) { + public ExhaustiveGenerator<@Nullable T> injectNull(ExhaustiveGenerator self) { return new WithNullExhaustiveGenerator<>(self); } @Override - public ExhaustiveGenerator ignoreExceptions( + public ExhaustiveGenerator ignoreExceptions( final ExhaustiveGenerator self, final Class[] exceptionTypes, int maxThrows diff --git a/engine/src/main/java/net/jqwik/engine/facades/FunctionsFacadeImpl.java b/engine/src/main/java/net/jqwik/engine/facades/FunctionsFacadeImpl.java index a3f9c79ba..0ec7fc9e3 100644 --- a/engine/src/main/java/net/jqwik/engine/facades/FunctionsFacadeImpl.java +++ b/engine/src/main/java/net/jqwik/engine/facades/FunctionsFacadeImpl.java @@ -4,6 +4,8 @@ import net.jqwik.api.arbitraries.*; import net.jqwik.engine.properties.arbitraries.*; +import org.jspecify.annotations.*; + import static net.jqwik.engine.support.JqwikReflectionSupport.*; /** @@ -20,7 +22,7 @@ public void ensureFunctionalType(Class functionalType) { @SuppressWarnings("unchecked") @Override - public FunctionArbitrary function(Class functionalType, Arbitrary resultArbitrary) { + public FunctionArbitrary function(Class functionalType, Arbitrary resultArbitrary) { return (FunctionArbitrary) new DefaultFunctionArbitrary<>(functionalType, resultArbitrary); } } diff --git a/engine/src/main/java/net/jqwik/engine/facades/Memoize.java b/engine/src/main/java/net/jqwik/engine/facades/Memoize.java index 75b273461..1dc63af1b 100644 --- a/engine/src/main/java/net/jqwik/engine/facades/Memoize.java +++ b/engine/src/main/java/net/jqwik/engine/facades/Memoize.java @@ -8,6 +8,8 @@ import net.jqwik.api.lifecycle.*; import net.jqwik.engine.support.*; +import org.jspecify.annotations.*; + public class Memoize { private static Store, Integer, Boolean>, RandomGenerator>> generatorStore() { @@ -15,11 +17,11 @@ private static Store, Integer, Boolean>, RandomGenerator } @SuppressWarnings("unchecked") - public static RandomGenerator memoizedGenerator( + public static RandomGenerator memoizedGenerator( Arbitrary arbitrary, int genSize, boolean withEdgeCases, - Supplier> generatorSupplier + Supplier> generatorSupplier ) { if (!arbitrary.isGeneratorMemoizable()){ return (RandomGenerator) generatorSupplier.get(); @@ -36,7 +38,7 @@ public static RandomGenerator memoizedGenerator( // Had to roll my on computeIfAbsent because HashMap.computeIfAbsent() // does not allow modifications of the map within the mapping function - private static V computeIfAbsent( + private static V computeIfAbsent( Map cache, K key, Function mappingFunction diff --git a/engine/src/main/java/net/jqwik/engine/facades/RandomGeneratorFacadeImpl.java b/engine/src/main/java/net/jqwik/engine/facades/RandomGeneratorFacadeImpl.java index c91ff7589..3ce6507cc 100644 --- a/engine/src/main/java/net/jqwik/engine/facades/RandomGeneratorFacadeImpl.java +++ b/engine/src/main/java/net/jqwik/engine/facades/RandomGeneratorFacadeImpl.java @@ -7,19 +7,21 @@ import net.jqwik.engine.properties.arbitraries.randomized.*; import net.jqwik.engine.properties.shrinking.*; +import org.jspecify.annotations.*; + /** * Is loaded through reflection in api module */ public class RandomGeneratorFacadeImpl extends RandomGenerator.RandomGeneratorFacade { @Override - public Shrinkable flatMap(Shrinkable self, Function> mapper, long nextLong) { + public Shrinkable flatMap(Shrinkable self, Function> mapper, long nextLong) { return new FlatMappedShrinkable<>(self, mapper, nextLong); } @Override - public Shrinkable flatMap( + public Shrinkable flatMap( Shrinkable self, - Function> mapper, + Function> mapper, int genSize, long nextLong, boolean withEmbeddedEdgeCases @@ -28,27 +30,27 @@ public Shrinkable flatMap( } @Override - public RandomGenerator filter(RandomGenerator self, Predicate filterPredicate, int maxMisses) { + public RandomGenerator filter(RandomGenerator self, Predicate filterPredicate, int maxMisses) { return new FilteredGenerator<>(self, filterPredicate, maxMisses); } @Override - public RandomGenerator withEdgeCases(RandomGenerator self, int genSize, EdgeCases edgeCases) { + public RandomGenerator withEdgeCases(RandomGenerator self, int genSize, EdgeCases edgeCases) { return RandomGenerators.withEdgeCases(self, genSize, edgeCases); } @Override - public RandomGenerator> collect(RandomGenerator self, Predicate> until) { + public RandomGenerator> collect(RandomGenerator self, Predicate> until) { return new CollectGenerator<>(self, until); } @Override - public RandomGenerator injectDuplicates(RandomGenerator self, double duplicateProbability) { + public RandomGenerator injectDuplicates(RandomGenerator self, double duplicateProbability) { return new InjectDuplicatesGenerator<>(self, duplicateProbability); } @Override - public RandomGenerator ignoreExceptions(RandomGenerator self, Class[] exceptionTypes, int maxThrows) { + public RandomGenerator ignoreExceptions(RandomGenerator self, Class[] exceptionTypes, int maxThrows) { return new IgnoreExceptionGenerator<>(self, exceptionTypes, maxThrows); } } diff --git a/engine/src/main/java/net/jqwik/engine/facades/SampleStreamFacade.java b/engine/src/main/java/net/jqwik/engine/facades/SampleStreamFacade.java index f2c4156bf..8d30de0b2 100644 --- a/engine/src/main/java/net/jqwik/engine/facades/SampleStreamFacade.java +++ b/engine/src/main/java/net/jqwik/engine/facades/SampleStreamFacade.java @@ -4,6 +4,7 @@ import java.util.function.*; import java.util.stream.*; +import org.jspecify.annotations.*; import org.junit.platform.engine.*; import org.junit.platform.engine.support.descriptor.*; @@ -29,7 +30,7 @@ public Type getType() { private static final Map, RandomGenerator> generators = new LruCache<>(500); @SuppressWarnings("unchecked") - private static RandomGenerator getGeneratorForSampling(Arbitrary arbitrary) { + private static RandomGenerator getGeneratorForSampling(Arbitrary arbitrary) { return runInDescriptor(() -> getGenerator((Arbitrary) arbitrary)); } @@ -51,11 +52,11 @@ private static RandomGenerator getGenerator(Arbitrary arbitrary) // ); } - private static Supplier wrapInDescriptor(Supplier code) { + private static Supplier wrapInDescriptor(Supplier code) { return () -> runInDescriptor(code); } - private static T runInDescriptor(Supplier code) { + private static T runInDescriptor(Supplier code) { if (CurrentTestDescriptor.isEmpty()) { return CurrentTestDescriptor.runWithDescriptor(SAMPLE_STREAM_DESCRIPTOR, code); } else { @@ -63,7 +64,7 @@ private static T runInDescriptor(Supplier code) { } } - Stream sampleStream(Arbitrary arbitrary) { + Stream sampleStream(Arbitrary arbitrary) { RandomGenerator generator = getGeneratorForSampling(arbitrary); return Stream.generate(wrapInDescriptor(() -> generator.next(SourceOfRandomness.current()))) .map(shrinkable -> runInDescriptor(shrinkable::value)); diff --git a/engine/src/main/java/net/jqwik/engine/facades/ShrinkableFacadeImpl.java b/engine/src/main/java/net/jqwik/engine/facades/ShrinkableFacadeImpl.java index 0d6ce28a4..6c7942281 100644 --- a/engine/src/main/java/net/jqwik/engine/facades/ShrinkableFacadeImpl.java +++ b/engine/src/main/java/net/jqwik/engine/facades/ShrinkableFacadeImpl.java @@ -5,27 +5,29 @@ import net.jqwik.api.*; import net.jqwik.engine.properties.shrinking.*; +import org.jspecify.annotations.*; + /** * Is loaded through reflection in api module */ public class ShrinkableFacadeImpl extends Shrinkable.ShrinkableFacade { @Override - public Shrinkable unshrinkable(Supplier valueSupplier, ShrinkingDistance distance) { + public Shrinkable unshrinkable(Supplier valueSupplier, ShrinkingDistance distance) { return new Unshrinkable<>(valueSupplier, distance); } @Override - public Shrinkable map(Shrinkable self, Function mapper) { + public Shrinkable map(Shrinkable self, Function mapper) { return new MappedShrinkable<>(self, mapper); } @Override - public Shrinkable filter(Shrinkable self, Predicate filter) { + public Shrinkable filter(Shrinkable self, Predicate filter) { return new FilteredShrinkable<>(self, filter); } @Override - public Shrinkable flatMap(Shrinkable self, Function> flatMapper, int tries, long randomSeed) { + public Shrinkable flatMap(Shrinkable self, Function> flatMapper, int tries, long randomSeed) { return new FlatMappedShrinkable<>(self, flatMapper, tries, randomSeed, false); } } diff --git a/engine/src/main/java/net/jqwik/engine/facades/ShrinkingSupportFacadeImpl.java b/engine/src/main/java/net/jqwik/engine/facades/ShrinkingSupportFacadeImpl.java index 4e0027fa1..0b2dbe81c 100644 --- a/engine/src/main/java/net/jqwik/engine/facades/ShrinkingSupportFacadeImpl.java +++ b/engine/src/main/java/net/jqwik/engine/facades/ShrinkingSupportFacadeImpl.java @@ -10,22 +10,24 @@ import net.jqwik.engine.properties.*; import net.jqwik.engine.properties.shrinking.*; +import org.jspecify.annotations.*; + public class ShrinkingSupportFacadeImpl extends ShrinkingSupportFacade { private final TestingSupportFacadeImpl testingSupportFacade = new TestingSupportFacadeImpl(); @Override - public T falsifyThenShrink(Arbitrary arbitrary, Random random, Falsifier falsifier) { + public T falsifyThenShrink(Arbitrary arbitrary, Random random, Falsifier falsifier) { RandomGenerator generator = arbitrary.generator(10, true); return falsifyThenShrink(generator, random, falsifier); } @Override @SuppressWarnings("unchecked") - public T falsifyThenShrink( + public T falsifyThenShrink( RandomGenerator generator, Random random, - Falsifier falsifier + Falsifier falsifier ) { Throwable[] originalError = new Throwable[1]; Shrinkable falsifiedShrinkable = @@ -42,9 +44,9 @@ public T falsifyThenShrink( @Override @SuppressWarnings("unchecked") - public T shrink( + public T shrink( Shrinkable falsifiedShrinkable, - Falsifier falsifier, + Falsifier falsifier, Throwable originalError ) { ShrunkFalsifiedSample sample = shrinkToSample(falsifiedShrinkable, falsifier, originalError); @@ -52,10 +54,10 @@ public T shrink( } @Override - public ShrunkFalsifiedSample shrinkToSample( - Shrinkable falsifiedShrinkable, - Falsifier falsifier, - Throwable originalError + public ShrunkFalsifiedSample shrinkToSample( + Shrinkable falsifiedShrinkable, + Falsifier falsifier, + Throwable originalError ) { FalsifiedSample sample = toFalsifiedSample(falsifiedShrinkable, originalError); Consumer parametersReporter = ignore -> {}; @@ -65,8 +67,10 @@ public ShrunkFalsifiedSample shrinkToSample( } @SuppressWarnings("unchecked") - private static Falsifier> toParamFalsifier(Falsifier tFalsifier) { + private static Falsifier> toParamFalsifier(Falsifier tFalsifier) { return params -> { + // At best PropertyShrinker should be parameterized, however, currently it is not + // Even though PropertyShrinker passes List, the elements are of type T T t = (T) params.get(0); return tFalsifier.execute(t); }; diff --git a/engine/src/main/java/net/jqwik/engine/facades/StoreFacadeImpl.java b/engine/src/main/java/net/jqwik/engine/facades/StoreFacadeImpl.java index 099c978c3..734b3fd90 100644 --- a/engine/src/main/java/net/jqwik/engine/facades/StoreFacadeImpl.java +++ b/engine/src/main/java/net/jqwik/engine/facades/StoreFacadeImpl.java @@ -3,6 +3,7 @@ import java.util.*; import java.util.function.*; +import org.jspecify.annotations.*; import org.junit.platform.engine.*; import net.jqwik.api.lifecycle.*; @@ -14,20 +15,20 @@ public class StoreFacadeImpl extends Store.StoreFacade { @Override - public Store create(Object identifier, Lifespan lifespan, Supplier initialValueSupplier) { + public Store create(Object identifier, Lifespan lifespan, Supplier initialValueSupplier) { TestDescriptor scope = CurrentTestDescriptor.get(); return StoreRepository.getCurrent().create(scope, identifier, lifespan, initialValueSupplier); } @Override - public Store get(Object identifier) { + public Store get(Object identifier) { TestDescriptor retriever = CurrentTestDescriptor.get(); Optional> store = StoreRepository.getCurrent().get(retriever, identifier); return store.orElseThrow(() -> new CannotFindStoreException(identifier, retriever.getUniqueId().toString())); } @Override - public Store free(Supplier initialValueSupplier) { + public Store free(Supplier initialValueSupplier) { return new Store() { T t = initialValueSupplier.get(); diff --git a/engine/src/main/java/net/jqwik/engine/facades/TestingSupportFacadeImpl.java b/engine/src/main/java/net/jqwik/engine/facades/TestingSupportFacadeImpl.java index d8bf67277..35c3057e2 100644 --- a/engine/src/main/java/net/jqwik/engine/facades/TestingSupportFacadeImpl.java +++ b/engine/src/main/java/net/jqwik/engine/facades/TestingSupportFacadeImpl.java @@ -7,10 +7,12 @@ import net.jqwik.api.facades.*; import net.jqwik.engine.execution.reporting.*; +import org.jspecify.annotations.*; + public class TestingSupportFacadeImpl extends TestingSupportFacade { @Override - public Shrinkable generateUntil(RandomGenerator generator, Random random, Function condition) { + public Shrinkable generateUntil(RandomGenerator generator, Random random, Function condition) { long maxTries = 1000; return generator .stream(random) diff --git a/engine/src/main/java/net/jqwik/engine/facades/package-info.java b/engine/src/main/java/net/jqwik/engine/facades/package-info.java new file mode 100644 index 000000000..4e7a8bc3c --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/facades/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine.facades; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/main/java/net/jqwik/engine/hooks/lifecycle/package-info.java b/engine/src/main/java/net/jqwik/engine/hooks/lifecycle/package-info.java new file mode 100644 index 000000000..3929dd572 --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/hooks/lifecycle/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine.hooks.lifecycle; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/main/java/net/jqwik/engine/hooks/package-info.java b/engine/src/main/java/net/jqwik/engine/hooks/package-info.java new file mode 100644 index 000000000..f8cdd6b3a --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/hooks/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine.hooks; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/main/java/net/jqwik/engine/hooks/statistics/StatisticsCollectorImpl.java b/engine/src/main/java/net/jqwik/engine/hooks/statistics/StatisticsCollectorImpl.java index cee4275a6..c4ce8c51e 100644 --- a/engine/src/main/java/net/jqwik/engine/hooks/statistics/StatisticsCollectorImpl.java +++ b/engine/src/main/java/net/jqwik/engine/hooks/statistics/StatisticsCollectorImpl.java @@ -226,7 +226,7 @@ public CoverageCheckerImpl(String label, StatisticsEntry entry, int countAll) { } @Override - public void count(Predicate countChecker) { + public void count(Predicate countChecker) { if (!countChecker.test(entry.count())) { String condition = String.format("Count of %s", entry.count()); failCondition(condition); @@ -234,7 +234,7 @@ public void count(Predicate countChecker) { } @Override - public void count(BiPredicate countChecker) { + public void count(BiPredicate countChecker) { if (!countChecker.test(entry.count(), countAll)) { String condition = String.format("Count of (%s, %s)", entry.count(), countAll); failCondition(condition); @@ -242,7 +242,7 @@ public void count(BiPredicate countChecker) { } @Override - public void count(Consumer countChecker) { + public void count(Consumer countChecker) { count(c -> { countChecker.accept(c); return true; @@ -250,7 +250,7 @@ public void count(Consumer countChecker) { } @Override - public void count(BiConsumer countChecker) { + public void count(BiConsumer countChecker) { count((c, a) -> { countChecker.accept(c, a); return true; @@ -258,7 +258,7 @@ public void count(BiConsumer countChecker) { } @Override - public void percentage(Predicate percentageChecker) { + public void percentage(Predicate percentageChecker) { if (!percentageChecker.test(entry.percentage())) { String condition = String.format("Percentage of %s", entry.percentage()); failCondition(condition); @@ -266,7 +266,7 @@ public void percentage(Predicate percentageChecker) { } @Override - public void percentage(Consumer percentageChecker) { + public void percentage(Consumer percentageChecker) { percentage(p -> { percentageChecker.accept(p); return true; diff --git a/engine/src/main/java/net/jqwik/engine/hooks/statistics/package-info.java b/engine/src/main/java/net/jqwik/engine/hooks/statistics/package-info.java new file mode 100644 index 000000000..6e526e264 --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/hooks/statistics/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine.hooks.statistics; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/main/java/net/jqwik/engine/package-info.java b/engine/src/main/java/net/jqwik/engine/package-info.java new file mode 100644 index 000000000..a58a6316e --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/main/java/net/jqwik/engine/properties/FeatureExtractor.java b/engine/src/main/java/net/jqwik/engine/properties/FeatureExtractor.java index 7f05a8a90..1a50d444e 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/FeatureExtractor.java +++ b/engine/src/main/java/net/jqwik/engine/properties/FeatureExtractor.java @@ -1,12 +1,14 @@ package net.jqwik.engine.properties; +import org.jspecify.annotations.*; + import java.util.*; import java.util.function.*; @FunctionalInterface -public interface FeatureExtractor extends Function { +public interface FeatureExtractor extends Function { - static FeatureExtractor identity() { + static FeatureExtractor identity() { return t -> t; } @@ -18,7 +20,7 @@ default Object applySafe(T t) { } } - default boolean isUniqueIn(T value, Collection elements) { + default boolean isUniqueIn(T value, Collection elements) { if (this == identity()) { return !elements.contains(value); } @@ -28,7 +30,7 @@ default boolean isUniqueIn(T value, Collection elements) { .noneMatch(x -> Objects.equals(x, feature)); } - default boolean areUnique(Collection elements) { + default boolean areUnique(Collection elements) { Set set = new HashSet<>(); for (T x : elements) { if (!set.add(applySafe(x))) { diff --git a/engine/src/main/java/net/jqwik/engine/properties/PropertyCheckResult.java b/engine/src/main/java/net/jqwik/engine/properties/PropertyCheckResult.java index 0d2a071d0..7e911c8c5 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/PropertyCheckResult.java +++ b/engine/src/main/java/net/jqwik/engine/properties/PropertyCheckResult.java @@ -2,6 +2,7 @@ import java.util.*; +import org.jspecify.annotations.*; import org.opentest4j.*; import net.jqwik.api.*; @@ -56,9 +57,9 @@ public static PropertyCheckResult failed( EdgeCasesMode edgeCasesMode, int edgeCasesTotal, int edgeCasesTried, - FalsifiedSample originalSample, - ShrunkFalsifiedSample shrunkSample, - Throwable throwable + @Nullable FalsifiedSample originalSample, + @Nullable ShrunkFalsifiedSample shrunkSample, + @Nullable Throwable throwable ) { // If no shrinking was possible, report only original sample if (shrunkSample != null && areEquivalent(originalSample, shrunkSample)) { @@ -151,9 +152,9 @@ public static PropertyCheckResult exhausted( private final EdgeCasesMode edgeCasesMode; private final int edgeCasesTotal; private final int edgeCasesTried; - private final FalsifiedSample originalSample; - private final ShrunkFalsifiedSample shrunkSample; - private final Throwable throwable; + private final @Nullable FalsifiedSample originalSample; + private final @Nullable ShrunkFalsifiedSample shrunkSample; + private final @Nullable Throwable throwable; private PropertyCheckResult( CheckStatus status, String stereotype, @@ -165,9 +166,9 @@ private PropertyCheckResult( EdgeCasesMode edgeCasesMode, int edgeCasesTotal, int edgeCasesTried, - FalsifiedSample originalSample, - ShrunkFalsifiedSample shrunkSample, - Throwable throwable + @Nullable FalsifiedSample originalSample, + @Nullable ShrunkFalsifiedSample shrunkSample, + @Nullable Throwable throwable ) { this.stereotype = stereotype; this.status = status; @@ -184,7 +185,7 @@ private PropertyCheckResult( this.throwable = determineThrowable(status, throwable); } - private Throwable determineThrowable(CheckStatus status, Throwable throwable) { + private @Nullable Throwable determineThrowable(CheckStatus status, @Nullable Throwable throwable) { if (status == CheckStatus.SUCCESSFUL) { return null; } else { @@ -218,7 +219,7 @@ public Optional throwable() { } @Override - public PropertyExecutionResult mapTo(Status newStatus, Throwable throwable) { + public PropertyExecutionResult mapTo(Status newStatus, @Nullable Throwable throwable) { switch (newStatus) { case ABORTED: return PlainExecutionResult.aborted(throwable, generationInfo); diff --git a/engine/src/main/java/net/jqwik/engine/properties/RandomizedShrinkablesGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/RandomizedShrinkablesGenerator.java index 956e6597f..17956ddd4 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/RandomizedShrinkablesGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/RandomizedShrinkablesGenerator.java @@ -102,7 +102,7 @@ private static List> listOfEdgeCases( return listOfEdgeCases; } - private static int calculateNextParamMaxEdgeCases(int maxEdgeCases, int baseCasesSize) { + private static int calculateNextParamMaxEdgeCases(int maxEdgeCases, int baseCasesSize) { int maxDerivedEdgeCases = Math.max(1, maxEdgeCases / baseCasesSize); // When in doubt generate a few more edge cases if (maxEdgeCases % baseCasesSize > 0) { diff --git a/engine/src/main/java/net/jqwik/engine/properties/UniquenessChecker.java b/engine/src/main/java/net/jqwik/engine/properties/UniquenessChecker.java index 8296be649..84d3685ea 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/UniquenessChecker.java +++ b/engine/src/main/java/net/jqwik/engine/properties/UniquenessChecker.java @@ -5,9 +5,11 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + public class UniquenessChecker { - public static boolean checkShrinkableUniqueIn(Collection> extractors, Shrinkable shrinkable, List> shrinkables) { + public static boolean checkShrinkableUniqueIn(Collection> extractors, Shrinkable shrinkable, List> shrinkables) { if (extractors.isEmpty()) { return true; } @@ -16,7 +18,7 @@ public static boolean checkShrinkableUniqueIn(Collection return checkValueUniqueIn(extractors, value, elements); } - public static boolean checkValueUniqueIn(Collection> extractors, T value, Collection elements) { + public static boolean checkValueUniqueIn(Collection> extractors, T value, Collection elements) { for (FeatureExtractor extractor : extractors) { if (!extractor.isUniqueIn(value, elements)) { return false; @@ -25,7 +27,7 @@ public static boolean checkValueUniqueIn(Collection> ext return true; } - public static boolean checkUniquenessOfShrinkables(Collection> extractors, List> shrinkables) { + public static boolean checkUniquenessOfShrinkables(Collection> extractors, List> shrinkables) { if (extractors.isEmpty()) { return true; } @@ -33,7 +35,7 @@ public static boolean checkUniquenessOfShrinkables(Collection boolean checkUniquenessOfValues(Collection> extractors, Collection elements) { + public static boolean checkUniquenessOfValues(Collection> extractors, Collection elements) { for (FeatureExtractor extractor : extractors) { if (!extractor.areUnique(elements)) { return false; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ArbitraryCollect.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ArbitraryCollect.java index 248d961a8..517c47a74 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ArbitraryCollect.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ArbitraryCollect.java @@ -9,9 +9,9 @@ public class ArbitraryCollect implements Arbitrary> { private final Arbitrary elementArbitrary; - private final Predicate> until; + private final Predicate> until; - public ArbitraryCollect(Arbitrary elementArbitrary, Predicate> until) { + public ArbitraryCollect(Arbitrary elementArbitrary, Predicate> until) { this.elementArbitrary = elementArbitrary; this.until = until; } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ArbitraryFilter.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ArbitraryFilter.java index 278d41d96..4128cbf96 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ArbitraryFilter.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ArbitraryFilter.java @@ -8,10 +8,10 @@ import net.jqwik.engine.*; public class ArbitraryFilter extends ArbitraryDelegator { - private final Predicate filterPredicate; + private final Predicate filterPredicate; private final int maxMisses; - public ArbitraryFilter(Arbitrary self, Predicate filterPredicate, int maxMisses) { + public ArbitraryFilter(Arbitrary self, Predicate filterPredicate, int maxMisses) { super(self); this.filterPredicate = filterPredicate; this.maxMisses = maxMisses; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ArbitraryFlatMap.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ArbitraryFlatMap.java index 0cac5d474..c89dd09a3 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ArbitraryFlatMap.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ArbitraryFlatMap.java @@ -9,9 +9,9 @@ public class ArbitraryFlatMap implements Arbitrary { private final Arbitrary self; - private final Function> mapper; + private final Function> mapper; - public ArbitraryFlatMap(Arbitrary self, Function> mapper) { + public ArbitraryFlatMap(Arbitrary self, Function> mapper) { this.self = self; this.mapper = mapper; } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ArbitraryMap.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ArbitraryMap.java index 5ae026401..18f62bbdd 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ArbitraryMap.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ArbitraryMap.java @@ -6,11 +6,13 @@ import net.jqwik.api.*; import net.jqwik.api.support.*; -public class ArbitraryMap implements Arbitrary { +import org.jspecify.annotations.*; + +public class ArbitraryMap implements Arbitrary { private final Arbitrary self; - private final Function mapper; + private final Function mapper; - public ArbitraryMap(Arbitrary self, Function mapper) { + public ArbitraryMap(Arbitrary self, Function mapper) { this.self = self; this.mapper = mapper; } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/CreateArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/CreateArbitrary.java index 2596a98e2..3feadc7fe 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/CreateArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/CreateArbitrary.java @@ -6,7 +6,9 @@ import net.jqwik.api.support.*; import net.jqwik.engine.properties.arbitraries.exhaustive.*; -public class CreateArbitrary extends UseGeneratorsArbitrary { +import org.jspecify.annotations.*; + +public class CreateArbitrary extends UseGeneratorsArbitrary { private final Supplier supplier; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultArrayArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultArrayArbitrary.java index 4b7fadece..6b535a5e1 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultArrayArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultArrayArbitrary.java @@ -10,6 +10,8 @@ import net.jqwik.engine.properties.arbitraries.exhaustive.*; import net.jqwik.engine.properties.shrinking.*; +import org.jspecify.annotations.*; + public class DefaultArrayArbitrary extends MultivalueArbitraryBase implements ArrayArbitrary { public static ArrayArbitrary forArrayType(Arbitrary elementArbitrary, Class arrayClass) { @@ -20,7 +22,7 @@ public static ArrayArbitrary forArrayType(Arbitrary elementArbit return new DefaultArrayArbitrary<>(elementArbitrary, arrayClass.getComponentType()); } - public static ArrayArbitrary forComponentType(Arbitrary elementArbitrary, Class componentType) { + public static ArrayArbitrary forComponentType(Arbitrary elementArbitrary, Class componentType) { return new DefaultArrayArbitrary<>(elementArbitrary, componentType); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultListArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultListArbitrary.java index 389031013..895b28dd0 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultListArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultListArbitrary.java @@ -60,7 +60,7 @@ public ListArbitrary withSizeDistribution(RandomDistribution distribution) { // TODO: Remove duplication with DefaultSetArbitrary.mapEach() @Override - public Arbitrary> mapEach(BiFunction, T, U> mapper) { + public Arbitrary> mapEach(BiFunction, ? super T, ? extends U> mapper) { return this.map(elements -> elements.stream() .map(e -> mapper.apply(elements, e)) .collect(Collectors.toList())); @@ -68,7 +68,7 @@ public Arbitrary> mapEach(BiFunction, T, U> mapper) { // TODO: Remove duplication with DefaultSetArbitrary.flatMapEach() @Override - public Arbitrary> flatMapEach(BiFunction, ? super T, ? extends Arbitrary> flatMapper) { + public Arbitrary> flatMapEach(BiFunction, ? super T, ? extends Arbitrary> flatMapper) { return this.flatMap(elements -> { List> arbitraries = elements.stream() diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultSetArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultSetArbitrary.java index 5ede6e77f..b9138641f 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultSetArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultSetArbitrary.java @@ -69,7 +69,7 @@ public SetArbitrary withSizeDistribution(RandomDistribution distribution) { // TODO: Remove duplication with DefaultListArbitrary.mapEach() @Override - public Arbitrary> mapEach(BiFunction, T, U> mapper) { + public Arbitrary> mapEach(BiFunction, ? super T, ? extends U> mapper) { return this.map(elements -> elements.stream() .map(e -> mapper.apply(elements, e)) .collect(CollectorsSupport.toLinkedHashSet())); @@ -77,7 +77,7 @@ public Arbitrary> mapEach(BiFunction, T, U> mapper) { // TODO: Remove duplication with DefaultListArbitrary.flatMapEach() @Override - public Arbitrary> flatMapEach(BiFunction, T, Arbitrary> flatMapper) { + public Arbitrary> flatMapEach(BiFunction, ? super T, ? extends Arbitrary> flatMapper) { return this.flatMap(elements -> { List> arbitraries = elements.stream() diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultTypeArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultTypeArbitrary.java index bb5da44ce..490966a8d 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultTypeArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultTypeArbitrary.java @@ -17,7 +17,7 @@ public class DefaultTypeArbitrary extends ArbitraryDecorator implements Ty private final Class targetType; private final Set explicitCreators = new LinkedHashSet<>(); private final Set>> constructorFilters = new LinkedHashSet<>(); - private final Set> factoryMethodFilters = new LinkedHashSet<>(); + private final Set> factoryMethodFilters = new LinkedHashSet<>(); private boolean defaultsSet = true; private TraverseArbitrary traverseArbitrary; @@ -81,13 +81,13 @@ private void addAllConstructors() { } @Override - public TypeArbitrary useFactoryMethods(Predicate filter) { + public TypeArbitrary useFactoryMethods(Predicate filter) { DefaultTypeArbitrary clone = cloneWithoutDefaultsSet(); clone.addFactoryMethods(filter); return clone; } - private void addFactoryMethods(Predicate filter) { + private void addFactoryMethods(Predicate filter) { factoryMethodFilters.add(filter); } @@ -134,7 +134,7 @@ public Set findCreators(TypeUsage target) { if (target.isOfType(targetType)) { creators.addAll(explicitCreators); } - for (Predicate filter : factoryMethodFilters) { + for (Predicate filter : factoryMethodFilters) { appendFactoryMethods(creators, target, filter); } for (Predicate> filter : constructorFilters) { @@ -153,7 +153,7 @@ private void appendConstructors(Set creators, TypeUsage target, Pred } - private void appendFactoryMethods(Set creators, TypeUsage target, Predicate filter) { + private void appendFactoryMethods(Set creators, TypeUsage target, Predicate filter) { Arrays.stream(target.getRawType().getDeclaredMethods()) .filter(ModifierSupport::isStatic) .filter(creator -> hasFittingReturnType(creator, target)) diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/EdgeCasesSupport.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/EdgeCasesSupport.java index 1f0ad50c9..907509440 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/EdgeCasesSupport.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/EdgeCasesSupport.java @@ -9,11 +9,13 @@ import net.jqwik.engine.properties.shrinking.*; import net.jqwik.engine.support.*; +import org.jspecify.annotations.*; + import static net.jqwik.engine.support.JqwikExceptionSupport.*; public class EdgeCasesSupport { - public static EdgeCases fromSuppliers(final List>> suppliers) { + public static EdgeCases fromSuppliers(final List>> suppliers) { return new EdgeCases() { @Override public List>> suppliers() { @@ -34,7 +36,7 @@ public String toString() { }; } - public static EdgeCases choose(final List values, int maxEdgeCases) { + public static EdgeCases choose(final List values, int maxEdgeCases) { List> shrinkables = new ArrayList<>(); if (values.size() > 0) { shrinkables.add(new ChooseValueShrinkable<>(values.get(0), values)); @@ -52,7 +54,7 @@ public static EdgeCases choose(final List values, int maxEdgeCases) { return EdgeCasesSupport.fromShrinkables(shrinkables); } - public static EdgeCases concatFrom(final List> arbitraries, int maxEdgeCases) { + public static EdgeCases concatFrom(final List> arbitraries, int maxEdgeCases) { List>> shrinkables = new ArrayList<>(); for (Arbitrary arbitrary : arbitraries) { shrinkables.add(new ChooseValueShrinkable<>(arbitrary, arbitraries)); @@ -60,7 +62,7 @@ public static EdgeCases concatFrom(final List> arb return flatMapArbitrary(fromShrinkables(shrinkables), Function.identity(), maxEdgeCases); } - public static EdgeCases concat(List> edgeCases, int maxEdgeCases) { + public static EdgeCases concat(List> edgeCases, int maxEdgeCases) { if (edgeCases.isEmpty() || maxEdgeCases <= 0) { return EdgeCases.none(); } @@ -84,18 +86,18 @@ public static EdgeCases concat(List> edgeCases, int maxEdgeC return EdgeCasesSupport.fromSuppliers(concatenatedSuppliers); } - public static EdgeCases fromShrinkables(List> shrinkables) { + public static EdgeCases fromShrinkables(List> shrinkables) { return () -> shrinkables .stream() .map(shrinkable -> (Supplier>) () -> shrinkable) .collect(Collectors.toList()); } - public static EdgeCases map(EdgeCases self, Function mapper) { + public static EdgeCases map(EdgeCases self, Function mapper) { return mapShrinkable(self, tShrinkable -> tShrinkable.map(mapper)); } - public static EdgeCases mapShrinkable(EdgeCases self, Function, Shrinkable> mapper) { + public static EdgeCases mapShrinkable(EdgeCases self, Function, ? extends Shrinkable> mapper) { List>> mappedSuppliers = self.suppliers().stream() .map(tSupplier -> mapper.apply(tSupplier.get())) @@ -105,7 +107,7 @@ public static EdgeCases mapShrinkable(EdgeCases self, Function EdgeCases filter(EdgeCases self, Predicate filterPredicate) { + public static EdgeCases filter(EdgeCases self, Predicate filterPredicate) { List>> filteredSuppliers = self.suppliers().stream() .filter(supplier -> filterPredicate.test(supplier.get().value())) @@ -114,7 +116,7 @@ public static EdgeCases filter(EdgeCases self, Predicate filterPred return EdgeCases.fromSuppliers(filteredSuppliers); } - public static EdgeCases ignoreExceptions(final EdgeCases self, final Class[] exceptionTypes) { + public static EdgeCases ignoreExceptions(final EdgeCases self, final Class[] exceptionTypes) { List>> filteredSuppliers = self.suppliers().stream() .filter(supplier -> { @@ -136,16 +138,16 @@ public static EdgeCases ignoreExceptions(final EdgeCases self, final C return EdgeCases.fromSuppliers(filteredSuppliers); } - public static EdgeCases dontShrink(EdgeCases self) { + public static EdgeCases dontShrink(EdgeCases self) { return () -> self.suppliers() .stream() .map(supplier -> (Supplier>) () -> supplier.get().makeUnshrinkable()) .collect(Collectors.toList()); } - public static EdgeCases flatMapArbitrary( + public static EdgeCases flatMapArbitrary( EdgeCases self, - Function> mapper, + Function> mapper, int maxEdgeCases ) { List>> flatMappedSuppliers = @@ -170,9 +172,9 @@ public static EdgeCases flatMapArbitrary( return EdgeCases.fromSuppliers(flatMappedSuppliers); } - public static EdgeCases combine( + public static EdgeCases combine( final List> arbitraries, - final Function, T> combineFunction, + final Function, ? extends T> combineFunction, int maxEdgeCases ) { if (arbitraries.isEmpty() || maxEdgeCases <= 0) { diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FrequencyArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FrequencyArbitrary.java index eca9c70ea..4bdff7637 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FrequencyArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FrequencyArbitrary.java @@ -7,7 +7,9 @@ import net.jqwik.engine.properties.arbitraries.exhaustive.*; import net.jqwik.engine.properties.arbitraries.randomized.*; -public class FrequencyArbitrary extends UseGeneratorsArbitrary { +import org.jspecify.annotations.*; + +public class FrequencyArbitrary extends UseGeneratorsArbitrary { private final List> frequencies; public FrequencyArbitrary(List> frequencies) { @@ -19,7 +21,7 @@ public FrequencyArbitrary(List> frequencies) { this.frequencies = frequencies; } - private static List valuesOf(List> frequencies) { + private static List valuesOf(List> frequencies) { return frequencies.stream().map(Tuple.Tuple2::get2).collect(Collectors.toList()); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FrequencyOfArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FrequencyOfArbitrary.java index 2fb69bcc5..31d19e281 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FrequencyOfArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FrequencyOfArbitrary.java @@ -11,7 +11,9 @@ import net.jqwik.engine.properties.arbitraries.exhaustive.*; import net.jqwik.engine.properties.arbitraries.randomized.*; -public class FrequencyOfArbitrary implements Arbitrary, SelfConfiguringArbitrary { +import org.jspecify.annotations.*; + +public class FrequencyOfArbitrary implements Arbitrary, SelfConfiguringArbitrary { private final List>> frequencies; private final boolean isGeneratorMemoizable; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/GenericEdgeCasesConfiguration.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/GenericEdgeCasesConfiguration.java index 333d3eee8..8a9aa2acd 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/GenericEdgeCasesConfiguration.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/GenericEdgeCasesConfiguration.java @@ -8,7 +8,7 @@ public class GenericEdgeCasesConfiguration implements EdgeCases.Config { private boolean none; - private final List> filters = new ArrayList<>(); + private final List> filters = new ArrayList<>(); private final List additionalEdgeCases = new ArrayList<>(); @Override @@ -18,7 +18,7 @@ public EdgeCases.Config none() { } @Override - public EdgeCases.Config filter(Predicate filter) { + public EdgeCases.Config filter(Predicate filter) { filters.add(filter); return this; } @@ -44,7 +44,7 @@ public final EdgeCases.Config includeOnly(T... includedValues) { return filter(values::contains); } - public EdgeCases configure(Consumer> configurator, Function> edgeCasesCreator, int maxEdgeCases) { + public EdgeCases configure(Consumer> configurator, Function> edgeCasesCreator, int maxEdgeCases) { configurator.accept(this); EdgeCases configuredEdgeCases; @@ -57,7 +57,7 @@ public EdgeCases configure(Consumer> configurator, Functi } List>> suppliers = configuredEdgeCases.suppliers(); - for (Predicate filter : new ArrayList<>(filters)) { + for (Predicate filter : new ArrayList<>(filters)) { suppliers = suppliers.stream().filter(s -> filter.test(s.get().value())).collect(Collectors.toList()); } for (T additionalEdgeCase : additionalEdgeCases) { diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/IntegralGeneratingArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/IntegralGeneratingArbitrary.java index a1af33b79..549b5259f 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/IntegralGeneratingArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/IntegralGeneratingArbitrary.java @@ -21,7 +21,7 @@ class IntegralGeneratingArbitrary extends TypedCloneable implements Arbitrary> edgeCasesConfigurator = EdgeCases.Config.noConfig(); + private Consumer> edgeCasesConfigurator = EdgeCases.Config.noConfig(); IntegralGeneratingArbitrary(BigInteger defaultMin, BigInteger defaultMax) { this.min = defaultMin; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/JustArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/JustArbitrary.java index 71e86ff3d..ce9c3b793 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/JustArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/JustArbitrary.java @@ -6,6 +6,8 @@ import net.jqwik.api.*; import net.jqwik.engine.properties.arbitraries.exhaustive.*; +import org.jspecify.annotations.*; + public class JustArbitrary implements Arbitrary { private final T value; @@ -15,13 +17,13 @@ public JustArbitrary(T value) { } @Override - public Arbitrary flatMap(Function> mapper) { + public Arbitrary flatMap(Function> mapper) { // Optimization: just(value).flatMap(mapper) -> mapper(value) return mapper.apply(value); } @Override - public Arbitrary map(Function mapper) { + public Arbitrary map(Function mapper) { // Optimization: just(value).map(mapper) -> just(mapper(value)) return new JustArbitrary<>(mapper.apply(value)); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyOfArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyOfArbitrary.java index 9afd129f8..74878c7e9 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyOfArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyOfArbitrary.java @@ -12,6 +12,8 @@ import net.jqwik.engine.properties.shrinking.*; import net.jqwik.engine.support.*; +import org.jspecify.annotations.*; + public class LazyOfArbitrary implements Arbitrary { // Cached arbitraries only have to survive one property @@ -24,7 +26,7 @@ private static Store>> arbitrariesStore() { } @SuppressWarnings("unchecked") - public static Arbitrary of(int hashIdentifier, List>> suppliers) { + public static Arbitrary of(int hashIdentifier, List>> suppliers) { // It's important for good shrinking to work that the same arbitrary usage is handled by the same arbitrary instance LazyOfArbitrary arbitrary = arbitrariesStore().get().computeIfAbsent(hashIdentifier, ignore -> new LazyOfArbitrary<>(suppliers)); return (Arbitrary) arbitrary; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/MappedEdgeCasesConsumer.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/MappedEdgeCasesConsumer.java index e8899750b..7c7b3afd7 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/MappedEdgeCasesConsumer.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/MappedEdgeCasesConsumer.java @@ -31,7 +31,7 @@ public EdgeCases.Config none() { } @Override - public EdgeCases.Config filter(Predicate filter) { + public EdgeCases.Config filter(Predicate filter) { uConfig.filter(u -> filter.test(utMapper.apply(u))); return this; } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/MultivalueArbitraryBase.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/MultivalueArbitraryBase.java index 0058b7752..46fa0c7e0 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/MultivalueArbitraryBase.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/MultivalueArbitraryBase.java @@ -10,6 +10,8 @@ import net.jqwik.engine.properties.*; import net.jqwik.engine.properties.arbitraries.randomized.*; +import org.jspecify.annotations.*; + import static java.util.Arrays.*; import static net.jqwik.engine.properties.UniquenessChecker.*; @@ -68,7 +70,7 @@ public StreamableArbitrary withSizeDistribution(RandomDistribution distrib } @Override - public Arbitrary reduce(R initial, BiFunction accumulator) { + public Arbitrary reduce(R initial, BiFunction accumulator) { return this.map(streamable -> { // Couldn't find a way to use Stream.reduce since it requires a combinator @SuppressWarnings("unchecked") diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ReportableStream.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ReportableStream.java index bf1234fe3..ebc5c3795 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ReportableStream.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ReportableStream.java @@ -6,6 +6,8 @@ import net.jqwik.engine.support.*; +import org.jspecify.annotations.*; + public class ReportableStream implements Stream { private final List values; @@ -31,7 +33,7 @@ public Stream filter(final Predicate predicate) { } @Override - public Stream map(final Function mapper) { + public Stream map(final Function mapper) { return stream.map(mapper); } @@ -51,7 +53,7 @@ public DoubleStream mapToDouble(final ToDoubleFunction mapper) { } @Override - public Stream flatMap(final Function> mapper) { + public Stream flatMap(final Function> mapper) { return stream.flatMap(mapper); } @@ -136,7 +138,7 @@ public U reduce(final U identity, final BiFunction accumula } @Override - public R collect(final Supplier supplier, final BiConsumer accumulator, final BiConsumer combiner) { + public R collect(final Supplier supplier, final BiConsumer accumulator, final BiConsumer combiner) { return stream.collect(supplier, accumulator, combiner); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/UseGeneratorsArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/UseGeneratorsArbitrary.java index c5a2eb3fa..2b8090b2b 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/UseGeneratorsArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/UseGeneratorsArbitrary.java @@ -5,7 +5,9 @@ import net.jqwik.api.*; -abstract class UseGeneratorsArbitrary implements Arbitrary { +import org.jspecify.annotations.*; + +abstract class UseGeneratorsArbitrary implements Arbitrary { private final RandomGenerator randomGenerator; private final Function>> exhaustiveGeneratorFunction; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/CombineArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/CombineArbitrary.java index 7f97751f4..b6e052766 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/CombineArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/CombineArbitrary.java @@ -12,11 +12,11 @@ public class CombineArbitrary implements Arbitrary { - private final Function, R> combinator; + private final Function, ? extends R> combinator; private final List> arbitraries; @SuppressWarnings("unchecked") - public CombineArbitrary(Function, R> combinator, Arbitrary... arbitraries) { + public CombineArbitrary(Function, ? extends R> combinator, Arbitrary... arbitraries) { this.combinator = combinator; this.arbitraries = Arrays.asList((Arbitrary[]) arbitraries); } @@ -75,7 +75,7 @@ private boolean isCombinedGeneratorMemoizable(List> arbitrarie private RandomGenerator combineGenerator( int genSize, - Function, R> combineFunction, + Function, ? extends R> combineFunction, List> arbitraries ) { List> generators = arbitraries.stream() @@ -89,7 +89,7 @@ private RandomGenerator combineGenerator( private RandomGenerator combineGeneratorWithEmbeddedEdgeCases( int genSize, - Function, R> combineFunction, + Function, ? extends R> combineFunction, List> arbitraries ) { List> generators = @@ -111,14 +111,14 @@ private List> generateShrinkables(List combineShrinkables( - List> shrinkables, Function, R> combineFunction + List> shrinkables, Function, ? extends R> combineFunction ) { return new CombinedShrinkable<>(shrinkables, combineFunction); } private Optional> combineExhaustive( List> arbitraries, - Function, R> combineFunction, + Function, ? extends R> combineFunction, long maxNumberOfSamples ) { return ExhaustiveGenerators.combine(arbitraries, combineFunction, maxNumberOfSamples); @@ -126,7 +126,7 @@ private Optional> combineExhaustive( private EdgeCases combineEdgeCases( final List> arbitraries, - final Function, R> combineFunction, + final Function, ? extends R> combineFunction, int maxEdgeCases ) { return EdgeCasesSupport.combine(arbitraries, combineFunction, maxEdgeCases); diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator2.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator2.java index 9dfd77994..1a399a750 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator2.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator2.java @@ -7,7 +7,7 @@ import net.jqwik.api.*; -public class DefaultCombinator2 implements Combinators.Combinator2 { +public class DefaultCombinator2 implements Combinators.Combinator2 { protected final Arbitrary a2; protected final Arbitrary a1; @@ -17,43 +17,43 @@ public DefaultCombinator2(Arbitrary a1, Arbitrary a2) { } @Override - public Arbitrary as(Combinators.F2 combinator) { + public Arbitrary as(Combinators.F2 combinator) { return new CombineArbitrary<>(combineFunction(combinator), a1, a2); } @Override - public Combinators.Combinator2 filter(Combinators.F2 filter) { + public Combinators.Combinator2 filter(Combinators.F2 filter) { return new Filtered<>(a1, a2, filter); } @SuppressWarnings("unchecked") - protected Function, R> combineFunction(Combinators.F2 combinator2) { + protected Function, ? extends R> combineFunction(Combinators.F2 combinator2) { return params -> combinator2.apply((T1) params.get(0), (T2) params.get(1)); } - private static class Filtered extends DefaultCombinator2 { - private final Combinators.F2 filter; + private static class Filtered extends DefaultCombinator2 { + private final Combinators.F2 filter; - private Filtered(Arbitrary a1, Arbitrary a2, Combinators.F2 filter) { + private Filtered(Arbitrary a1, Arbitrary a2, Combinators.F2 filter) { super(a1, a2); this.filter = filter; } @Override - public Arbitrary as(Combinators.F2 combinator) { + public Arbitrary as(Combinators.F2 combinator) { return new CombineArbitrary<>(Function.identity(), a1, a2) .filter(combineFunction(filter)::apply) .map(combineFunction(combinator)); } @Override - public Combinators.Combinator2 filter(Combinators.F2 filter) { + public Combinators.Combinator2 filter(Combinators.F2 filter) { return new Filtered<>(a1, a2, combineFilters(this.filter, filter)); } private Combinators.F2 combineFilters( - Combinators.F2 first, - Combinators.F2 second + Combinators.F2 first, + Combinators.F2 second ) { return (t1, t2) -> first.apply(t1, t2) && second.apply(t1, t2); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator3.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator3.java index 53b148a96..bc858e38a 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator3.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator3.java @@ -7,7 +7,7 @@ import net.jqwik.api.*; -public class DefaultCombinator3 +public class DefaultCombinator3 extends DefaultCombinator2 implements Combinators.Combinator3 { protected final Arbitrary a3; @@ -18,44 +18,44 @@ public DefaultCombinator3(Arbitrary a1, Arbitrary a2, Arbitrary a3) } @Override - public Arbitrary as(Combinators.F3 combinator) { + public Arbitrary as(Combinators.F3 combinator) { return new CombineArbitrary<>(combineFunction(combinator), a1, a2, a3); } @Override - public Combinators.Combinator3 filter(Combinators.F3 filter) { + public Combinators.Combinator3 filter(Combinators.F3 filter) { return new Filtered<>(a1, a2, a3, filter); } @SuppressWarnings("unchecked") - protected Function, R> combineFunction(Combinators.F3 combinator) { + protected Function, R> combineFunction(Combinators.F3 combinator) { return params -> combinator.apply((T1) params.get(0), (T2) params.get(1), (T3) params.get(2)); } private static class Filtered extends DefaultCombinator3 { - private final Combinators.F3 filter; + private final Combinators.F3 filter; - private Filtered(Arbitrary a1, Arbitrary a2, Arbitrary a3, Combinators.F3 filter) { + private Filtered(Arbitrary a1, Arbitrary a2, Arbitrary a3, Combinators.F3 filter) { super(a1, a2, a3); this.filter = filter; } @Override - public Arbitrary as(Combinators.F3 combinator) { + public Arbitrary as(Combinators.F3 combinator) { return new CombineArbitrary<>(Function.identity(), a1, a2, a3) .filter(combineFunction(filter)::apply) .map(combineFunction(combinator)); } @Override - public Combinators.Combinator3 filter(Combinators.F3 filter) { + public Combinators.Combinator3 filter(Combinators.F3 filter) { return new Filtered<>(a1, a2, a3, combineFilters(this.filter, filter)); } @SuppressWarnings("unchecked") private Combinators.F3 combineFilters( - Combinators.F3 filter1, - Combinators.F3 filter2 + Combinators.F3 filter1, + Combinators.F3 filter2 ) { return (t1, t2, t3) -> filter1.apply(t1, t2, t3) && filter2.apply(t1, t2, t3); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator4.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator4.java index 0de2945b7..67c7697f9 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator4.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator4.java @@ -5,7 +5,9 @@ import net.jqwik.api.*; -public class DefaultCombinator4 +import org.jspecify.annotations.*; + +public class DefaultCombinator4 extends DefaultCombinator3 implements Combinators.Combinator4 { @@ -17,49 +19,49 @@ public DefaultCombinator4(Arbitrary a1, Arbitrary a2, Arbitrary a3, } @Override - public Arbitrary as(Combinators.F4 combinator) { + public Arbitrary as(Combinators.F4 combinator) { return new CombineArbitrary<>(combineFunction(combinator), a1, a2, a3, a4); } @Override - public Combinators.Combinator4 filter(Combinators.F4 filter) { + public Combinators.Combinator4 filter(Combinators.F4 filter) { return new Filtered<>(a1, a2, a3, a4, filter); } @SuppressWarnings("unchecked") - protected Function, R> combineFunction(Combinators.F4 combinator) { + protected Function, R> combineFunction(Combinators.F4 combinator) { return params -> combinator.apply((T1) params.get(0), (T2) params.get(1), (T3) params.get(2), (T4) params.get(3)); } private static class Filtered extends DefaultCombinator4 { - private final Combinators.F4 filter; + private final Combinators.F4 filter; private Filtered( Arbitrary a1, Arbitrary a2, Arbitrary a3, Arbitrary a4, - Combinators.F4 filter + Combinators.F4 filter ) { super(a1, a2, a3, a4); this.filter = filter; } @Override - public Arbitrary as(Combinators.F4 combinator) { + public Arbitrary as(Combinators.F4 combinator) { return new CombineArbitrary<>(Function.identity(), a1, a2, a3, a4) .filter(combineFunction(filter)::apply) .map(combineFunction(combinator)); } @Override - public Combinators.Combinator4 filter(Combinators.F4 filter) { + public Combinators.Combinator4 filter(Combinators.F4 filter) { return super.filter(combineFilters(this.filter, filter)); } private Combinators.F4 combineFilters( - Combinators.F4 first, - Combinators.F4 second + Combinators.F4 first, + Combinators.F4 second ) { return (p1, p2, p3, p4) -> first.apply(p1, p2, p3, p4) && second.apply(p1, p2, p3, p4); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator5.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator5.java index 8eee660fc..2ba358525 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator5.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator5.java @@ -5,7 +5,9 @@ import net.jqwik.api.*; -public class DefaultCombinator5 +import org.jspecify.annotations.*; + +public class DefaultCombinator5 extends DefaultCombinator4 implements Combinators.Combinator5 { @@ -17,17 +19,17 @@ public DefaultCombinator5(Arbitrary a1, Arbitrary a2, Arbitrary a3, } @Override - public Arbitrary as(Combinators.F5 combinator) { + public Arbitrary as(Combinators.F5 combinator) { return new CombineArbitrary<>(combineFunction(combinator), a1, a2, a3, a4, a5); } @Override - public Combinators.Combinator5 filter(Combinators.F5 filter) { + public Combinators.Combinator5 filter(Combinators.F5 filter) { return new Filtered<>(a1, a2, a3, a4, a5, filter); } @SuppressWarnings("unchecked") - protected Function, R> combineFunction(Combinators.F5 combinator) { + protected Function, R> combineFunction(Combinators.F5 combinator) { return params -> combinator.apply( (T1) params.get(0), (T2) params.get(1), (T3) params.get(2), (T4) params.get(3), @@ -36,7 +38,7 @@ protected Function, R> combineFunction(Combinators.F5 extends DefaultCombinator5 { - private final Combinators.F5 filter; + private final Combinators.F5 filter; private Filtered( Arbitrary a1, @@ -44,27 +46,27 @@ private Filtered( Arbitrary a3, Arbitrary a4, Arbitrary a5, - Combinators.F5 filter + Combinators.F5 filter ) { super(a1, a2, a3, a4, a5); this.filter = filter; } @Override - public Arbitrary as(Combinators.F5 combinator) { + public Arbitrary as(Combinators.F5 combinator) { return new CombineArbitrary<>(Function.identity(), a1, a2, a3, a4, a5) .filter(combineFunction(filter)::apply) .map(combineFunction(combinator)); } @Override - public Combinators.Combinator5 filter(Combinators.F5 filter) { + public Combinators.Combinator5 filter(Combinators.F5 filter) { return super.filter(combineFilters(this.filter, filter)); } private Combinators.F5 combineFilters( - Combinators.F5 first, - Combinators.F5 second + Combinators.F5 first, + Combinators.F5 second ) { return (p1, p2, p3, p4, p5) -> first.apply(p1, p2, p3, p4, p5) && second.apply(p1, p2, p3, p4, p5); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator6.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator6.java index 308877959..bf4184e95 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator6.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator6.java @@ -5,7 +5,9 @@ import net.jqwik.api.*; -public class DefaultCombinator6 +import org.jspecify.annotations.*; + +public class DefaultCombinator6 extends DefaultCombinator5 implements Combinators.Combinator6 { @@ -17,17 +19,17 @@ public DefaultCombinator6(Arbitrary a1, Arbitrary a2, Arbitrary a3, } @Override - public Arbitrary as(Combinators.F6 combinator) { + public Arbitrary as(Combinators.F6 combinator) { return new CombineArbitrary<>(combineFunction(combinator), a1, a2, a3, a4, a5, a6); } @Override - public Combinators.Combinator6 filter(Combinators.F6 filter) { + public Combinators.Combinator6 filter(Combinators.F6 filter) { return new Filtered<>(a1, a2, a3, a4, a5, a6, filter); } @SuppressWarnings("unchecked") - protected Function, R> combineFunction(Combinators.F6 combinator) { + protected Function, R> combineFunction(Combinators.F6 combinator) { return params -> combinator.apply( (T1) params.get(0), (T2) params.get(1), (T3) params.get(2), (T4) params.get(3), @@ -36,7 +38,7 @@ protected Function, R> combineFunction(Combinators.F6 extends DefaultCombinator6 { - private final Combinators.F6 filter; + private final Combinators.F6 filter; private Filtered( Arbitrary a1, @@ -45,27 +47,27 @@ private Filtered( Arbitrary a4, Arbitrary a5, Arbitrary a6, - Combinators.F6 filter + Combinators.F6 filter ) { super(a1, a2, a3, a4, a5, a6); this.filter = filter; } @Override - public Arbitrary as(Combinators.F6 combinator) { + public Arbitrary as(Combinators.F6 combinator) { return new CombineArbitrary<>(Function.identity(), a1, a2, a3, a4, a5, a6) .filter(combineFunction(filter)::apply) .map(combineFunction(combinator)); } @Override - public Combinators.Combinator6 filter(Combinators.F6 filter) { + public Combinators.Combinator6 filter(Combinators.F6 filter) { return super.filter(combineFilters(this.filter, filter)); } private Combinators.F6 combineFilters( - Combinators.F6 first, - Combinators.F6 second + Combinators.F6 first, + Combinators.F6 second ) { return (p1, p2, p3, p4, p5, p6) -> first.apply(p1, p2, p3, p4, p5, p6) && second.apply(p1, p2, p3, p4, p5, p6); diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator7.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator7.java index bcb649513..c6c51e85c 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator7.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator7.java @@ -5,7 +5,9 @@ import net.jqwik.api.*; -public class DefaultCombinator7 +import org.jspecify.annotations.*; + +public class DefaultCombinator7 extends DefaultCombinator6 implements Combinators.Combinator7 { @@ -19,17 +21,17 @@ public DefaultCombinator7( } @Override - public Arbitrary as(Combinators.F7 combinator) { + public Arbitrary as(Combinators.F7 combinator) { return new CombineArbitrary<>(combineFunction(combinator), a1, a2, a3, a4, a5, a6, a7); } @Override - public Combinators.Combinator7 filter(Combinators.F7 filter) { + public Combinators.Combinator7 filter(Combinators.F7 filter) { return new Filtered<>(a1, a2, a3, a4, a5, a6, a7, filter); } @SuppressWarnings("unchecked") - protected Function, R> combineFunction(Combinators.F7 combinator) { + protected Function, R> combineFunction(Combinators.F7 combinator) { return params -> combinator.apply( (T1) params.get(0), (T2) params.get(1), (T3) params.get(2), (T4) params.get(3), @@ -39,7 +41,7 @@ protected Function, R> combineFunction(Combinators.F7 extends DefaultCombinator7 { - private final Combinators.F7 filter; + private final Combinators.F7 filter; private Filtered( Arbitrary a1, @@ -49,27 +51,27 @@ private Filtered( Arbitrary a5, Arbitrary a6, Arbitrary a7, - Combinators.F7 filter + Combinators.F7 filter ) { super(a1, a2, a3, a4, a5, a6, a7); this.filter = filter; } @Override - public Arbitrary as(Combinators.F7 combinator) { + public Arbitrary as(Combinators.F7 combinator) { return new CombineArbitrary<>(Function.identity(), a1, a2, a3, a4, a5, a6, a7) .filter(combineFunction(filter)::apply) .map(combineFunction(combinator)); } @Override - public Combinators.Combinator7 filter(Combinators.F7 filter) { + public Combinators.Combinator7 filter(Combinators.F7 filter) { return super.filter(combineFilters(this.filter, filter)); } private Combinators.F7 combineFilters( - Combinators.F7 first, - Combinators.F7 second + Combinators.F7 first, + Combinators.F7 second ) { return (p1, p2, p3, p4, p5, p6, p7) -> first.apply(p1, p2, p3, p4, p5, p6, p7) && second.apply(p1, p2, p3, p4, p5, p6, p7); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator8.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator8.java index 1cd2761f1..ec6ad98ac 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator8.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultCombinator8.java @@ -5,7 +5,9 @@ import net.jqwik.api.*; -public class DefaultCombinator8 +import org.jspecify.annotations.*; + +public class DefaultCombinator8 extends DefaultCombinator7 implements Combinators.Combinator8 { @@ -20,17 +22,17 @@ public DefaultCombinator8( } @Override - public Arbitrary as(Combinators.F8 combinator) { + public Arbitrary as(Combinators.F8 combinator) { return new CombineArbitrary<>(combineFunction(combinator), a1, a2, a3, a4, a5, a6, a7, a8); } @Override - public Combinators.Combinator8 filter(Combinators.F8 filter) { + public Combinators.Combinator8 filter(Combinators.F8 filter) { return new Filtered<>(a1, a2, a3, a4, a5, a6, a7, a8, filter); } @SuppressWarnings("unchecked") - protected Function, R> combineFunction(Combinators.F8 combinator) { + protected Function, R> combineFunction(Combinators.F8 combinator) { return params -> combinator.apply( (T1) params.get(0), (T2) params.get(1), (T3) params.get(2), (T4) params.get(3), @@ -40,7 +42,7 @@ protected Function, R> combineFunction(Combinators.F8 extends DefaultCombinator8 { - private final Combinators.F8 filter; + private final Combinators.F8 filter; private Filtered( Arbitrary a1, @@ -51,27 +53,27 @@ private Filtered( Arbitrary a6, Arbitrary a7, Arbitrary a8, - Combinators.F8 filter + Combinators.F8 filter ) { super(a1, a2, a3, a4, a5, a6, a7, a8); this.filter = filter; } @Override - public Arbitrary as(Combinators.F8 combinator) { + public Arbitrary as(Combinators.F8 combinator) { return new CombineArbitrary<>(Function.identity(), a1, a2, a3, a4, a5, a6, a7, a8) .filter(combineFunction(filter)::apply) .map(combineFunction(combinator)); } @Override - public Combinators.Combinator8 filter(Combinators.F8 filter) { + public Combinators.Combinator8 filter(Combinators.F8 filter) { return super.filter(combineFilters(this.filter, filter)); } private Combinators.F8 combineFilters( - Combinators.F8 first, - Combinators.F8 second + Combinators.F8 first, + Combinators.F8 second ) { return (p1, p2, p3, p4, p5, p6, p7, p8) -> first.apply(p1, p2, p3, p4, p5, p6, p7, p8) && second.apply(p1, p2, p3, p4, p5, p6, p7, p8); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultListCombinator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultListCombinator.java index 5c661c4f7..5594cf0d7 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultListCombinator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultListCombinator.java @@ -24,44 +24,44 @@ private DefaultListCombinator(Arbitrary[] arbitraries) { } @Override - public Arbitrary as(Function, @NonNull R> combinator) { + public Arbitrary as(Function, ? extends R> combinator) { return new CombineArbitrary<>(combineFunction(combinator), arbitraries); } @API(status = EXPERIMENTAL, since = "1.7.1") - public Combinators.ListCombinator filter(Predicate> filter) { + public Combinators.ListCombinator filter(Predicate> filter) { return new Filtered<>(arbitraries, filter); } @SuppressWarnings("unchecked") - protected Function, R> combineFunction(Function, R> combinator) { + protected Function, R> combineFunction(Function, ? extends R> combinator) { return params -> combinator.apply((List) params); } private static class Filtered extends DefaultListCombinator { - private final Predicate> filter; + private final Predicate> filter; - private Filtered(Arbitrary[] arbitraries, Predicate> filter) { + private Filtered(Arbitrary[] arbitraries, Predicate> filter) { super(arbitraries); this.filter = filter; } @SuppressWarnings("unchecked") @Override - public Arbitrary as(Function, @NonNull R> combinator) { - Predicate> filterPredicate = params -> filter.test((List) params); + public Arbitrary as(Function, ? extends R> combinator) { + Predicate> filterPredicate = params -> filter.test((List) params); return new CombineArbitrary<>(Function.identity(), arbitraries) .filter(filterPredicate) .map(combineFunction(combinator)); } @Override - public Combinators.ListCombinator filter(Predicate> filter) { + public Combinators.ListCombinator filter(Predicate> filter) { return super.filter(combineFilters(this.filter, filter)); } - private Predicate> combineFilters(Predicate> first, Predicate> second) { - return first.and(second); + private Predicate> combineFilters(Predicate> first, Predicate> second) { + return it -> first.test(it) && second.test(it); } } } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/package-info.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/package-info.java new file mode 100644 index 000000000..ac173e93e --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine.properties.arbitraries.combinations; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/CombinedExhaustiveGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/CombinedExhaustiveGenerator.java index c60eacfc9..8701d9226 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/CombinedExhaustiveGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/CombinedExhaustiveGenerator.java @@ -10,7 +10,7 @@ class CombinedExhaustiveGenerator implements ExhaustiveGenerator { private final Long maxCount; private final List> arbitraries; - private final Function, R> combinator; + private final Function, ? extends R> combinator; static Optional calculateMaxCount(List> arbitraries, long maxNumberOfSamples) { long product = 1; @@ -27,7 +27,7 @@ static Optional calculateMaxCount(List> arbitraries, lon return Optional.of(product); } - CombinedExhaustiveGenerator(Long maxCount, List> arbitraries, Function, R> combinator) { + CombinedExhaustiveGenerator(Long maxCount, List> arbitraries, Function, ? extends R> combinator) { this.maxCount = maxCount; this.arbitraries = arbitraries; this.combinator = combinator; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/ExhaustiveGenerators.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/ExhaustiveGenerators.java index 2c8b50ca7..da0e60611 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/ExhaustiveGenerators.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/ExhaustiveGenerators.java @@ -7,15 +7,17 @@ import net.jqwik.api.*; import net.jqwik.engine.properties.*; +import org.jspecify.annotations.*; + import static net.jqwik.engine.properties.UniquenessChecker.*; public class ExhaustiveGenerators { - public static Optional> create(Supplier supplier, long maxNumberOfSamples) { + public static Optional> create(Supplier supplier, long maxNumberOfSamples) { return fromIterable(() -> new SupplierIterator<>(supplier), 1, maxNumberOfSamples); } - public static Optional> choose(List values, long maxNumberOfSamples) { + public static Optional> choose(List values, long maxNumberOfSamples) { return fromIterable(values, values.size(), maxNumberOfSamples); } @@ -27,17 +29,17 @@ public static Optional> choose(char[] characters, return choose(validCharacters, maxNumberOfSamples); } - public static Optional> fromIterable(Iterable iterator, long maxCount, long maxNumberOfSamples) { + public static Optional> fromIterable(Iterable iterator, long maxCount, long maxNumberOfSamples) { if (maxCount > maxNumberOfSamples) { return Optional.empty(); } return Optional.of(new IterableBasedExhaustiveGenerator<>(iterator, maxCount)); } - public static Optional>> list( + public static Optional>> list( Arbitrary elementArbitrary, int minSize, int maxSize, - Collection> uniquenessExtractors, + Collection> uniquenessExtractors, long maxNumberOfSamples ) { Optional optionalMaxCount = ListExhaustiveGenerator.calculateMaxCount(elementArbitrary, minSize, maxSize, maxNumberOfSamples); @@ -66,7 +68,7 @@ public static Optional> strings( )); } - public static Optional>> set( + public static Optional>> set( Arbitrary elementArbitrary, int minSize, int maxSize, Collection> featureExtractors, @@ -79,23 +81,23 @@ public static Optional>> set( ); } - public static Optional> combine( + public static Optional> combine( List> arbitraries, - Function, R> combinator, + Function, ? extends R> combinator, long maxNumberOfSamples ) { Optional optionalMaxCount = CombinedExhaustiveGenerator.calculateMaxCount(arbitraries, maxNumberOfSamples); return optionalMaxCount.map(maxCount -> new CombinedExhaustiveGenerator<>(maxCount, arbitraries, combinator)); } - public static Optional>> shuffle(List values, long maxNumberOfSamples) { + public static Optional>> shuffle(List values, long maxNumberOfSamples) { Optional optionalMaxCount = PermutationExhaustiveGenerator.calculateMaxCount(values, maxNumberOfSamples); return optionalMaxCount.map( maxCount -> new PermutationExhaustiveGenerator<>(values, maxCount) ); } - public static Optional> flatMap( + public static Optional> flatMap( ExhaustiveGenerator base, Function> mapper, long maxNumberOfSamples diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/FilteredExhaustiveGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/FilteredExhaustiveGenerator.java index d95caed54..11442b458 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/FilteredExhaustiveGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/FilteredExhaustiveGenerator.java @@ -7,10 +7,10 @@ public class FilteredExhaustiveGenerator implements ExhaustiveGenerator { private final ExhaustiveGenerator toFilter; - private final Predicate filter; + private final Predicate filter; private int maxMisses; - public FilteredExhaustiveGenerator(ExhaustiveGenerator toFilter, Predicate filter, int maxMisses) { + public FilteredExhaustiveGenerator(ExhaustiveGenerator toFilter, Predicate filter, int maxMisses) { this.toFilter = toFilter; this.filter = filter; this.maxMisses = maxMisses; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/FlatMappedExhaustiveGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/FlatMappedExhaustiveGenerator.java index 3db50eaa9..8f6f14ba4 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/FlatMappedExhaustiveGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/FlatMappedExhaustiveGenerator.java @@ -7,7 +7,9 @@ import net.jqwik.api.*; import net.jqwik.engine.support.*; -public class FlatMappedExhaustiveGenerator implements ExhaustiveGenerator { +import org.jspecify.annotations.*; + +public class FlatMappedExhaustiveGenerator implements ExhaustiveGenerator { private final ExhaustiveGenerator baseGenerator; private final long maxCount; private final Function> mapper; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/IgnoreExceptionExhaustiveGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/IgnoreExceptionExhaustiveGenerator.java index 2f201ff51..b63317ead 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/IgnoreExceptionExhaustiveGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/IgnoreExceptionExhaustiveGenerator.java @@ -4,9 +4,11 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + import static net.jqwik.engine.support.JqwikExceptionSupport.*; -public class IgnoreExceptionExhaustiveGenerator implements ExhaustiveGenerator { +public class IgnoreExceptionExhaustiveGenerator implements ExhaustiveGenerator { private final ExhaustiveGenerator toFilter; private final Class[] exceptionTypes; private final int maxThrows; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/IterableBasedExhaustiveGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/IterableBasedExhaustiveGenerator.java index b16cf872a..475561735 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/IterableBasedExhaustiveGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/IterableBasedExhaustiveGenerator.java @@ -4,7 +4,9 @@ import net.jqwik.api.*; -class IterableBasedExhaustiveGenerator implements ExhaustiveGenerator { +import org.jspecify.annotations.*; + +class IterableBasedExhaustiveGenerator implements ExhaustiveGenerator { final private Iterable iterable; final private long maxCount; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/ListExhaustiveGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/ListExhaustiveGenerator.java index af032d800..bcd3e2ad9 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/ListExhaustiveGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/ListExhaustiveGenerator.java @@ -5,7 +5,9 @@ import net.jqwik.api.*; import net.jqwik.engine.support.*; -class ListExhaustiveGenerator implements ExhaustiveGenerator> { +import org.jspecify.annotations.*; + +class ListExhaustiveGenerator implements ExhaustiveGenerator> { private final Arbitrary elementArbitrary; private final Long maxCount; private final int minSize; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/MappedExhaustiveGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/MappedExhaustiveGenerator.java index b6d839fe2..600dfbc42 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/MappedExhaustiveGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/MappedExhaustiveGenerator.java @@ -5,11 +5,13 @@ import net.jqwik.api.*; -public class MappedExhaustiveGenerator implements ExhaustiveGenerator { +import org.jspecify.annotations.*; + +public class MappedExhaustiveGenerator implements ExhaustiveGenerator { private final ExhaustiveGenerator toMap; - private final Function mapper; + private final Function mapper; - public MappedExhaustiveGenerator(ExhaustiveGenerator toMap, Function mapper) {this.toMap = toMap; + public MappedExhaustiveGenerator(ExhaustiveGenerator toMap, Function mapper) {this.toMap = toMap; this.mapper = mapper; } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/PermutationExhaustiveGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/PermutationExhaustiveGenerator.java index 08abaed66..49735895c 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/PermutationExhaustiveGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/PermutationExhaustiveGenerator.java @@ -5,9 +5,11 @@ import net.jqwik.api.*; import net.jqwik.engine.support.*; +import org.jspecify.annotations.*; + import static net.jqwik.engine.support.MathSupport.*; -class PermutationExhaustiveGenerator implements ExhaustiveGenerator> { +class PermutationExhaustiveGenerator implements ExhaustiveGenerator> { private final List values; private final Long maxCount; @@ -16,7 +18,7 @@ public PermutationExhaustiveGenerator(List values, Long maxCount) { this.maxCount = maxCount; } - static Optional calculateMaxCount(List values, long maxNumberOfSamples) { + static Optional calculateMaxCount(List values, long maxNumberOfSamples) { try { long choices = factorial(values.size()); if (choices > maxNumberOfSamples || choices < 0) { diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/SetExhaustiveGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/SetExhaustiveGenerator.java index d8bd74c19..8475b4c8a 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/SetExhaustiveGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/SetExhaustiveGenerator.java @@ -5,7 +5,9 @@ import net.jqwik.api.*; import net.jqwik.engine.support.*; -class SetExhaustiveGenerator implements ExhaustiveGenerator> { +import org.jspecify.annotations.*; + +class SetExhaustiveGenerator implements ExhaustiveGenerator> { private final Arbitrary elementArbitrary; private final long maxCount; private final int minSize; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/WithNullExhaustiveGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/WithNullExhaustiveGenerator.java index 40b15a12b..dc786d124 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/WithNullExhaustiveGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/WithNullExhaustiveGenerator.java @@ -4,7 +4,9 @@ import net.jqwik.api.*; -public class WithNullExhaustiveGenerator implements ExhaustiveGenerator { +import org.jspecify.annotations.*; + +public class WithNullExhaustiveGenerator implements ExhaustiveGenerator { private final ExhaustiveGenerator base; public WithNullExhaustiveGenerator(ExhaustiveGenerator base) { diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/package-info.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/package-info.java new file mode 100644 index 000000000..a3a6194df --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine.properties.arbitraries.exhaustive; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/package-info.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/package-info.java new file mode 100644 index 000000000..f556b14f3 --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine.properties.arbitraries; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/CollectGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/CollectGenerator.java index c0364015b..7122e33c5 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/CollectGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/CollectGenerator.java @@ -8,9 +8,9 @@ public class CollectGenerator implements RandomGenerator> { private final RandomGenerator elementGenerator; - private final Predicate> until; + private final Predicate> until; - public CollectGenerator(RandomGenerator elementGenerator, Predicate> until) { + public CollectGenerator(RandomGenerator elementGenerator, Predicate> until) { this.elementGenerator = elementGenerator; this.until = until; } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/ContainerGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/ContainerGenerator.java index 1b142dffd..1ab410f8d 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/ContainerGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/ContainerGenerator.java @@ -10,10 +10,10 @@ class ContainerGenerator implements RandomGenerator { private final RandomGenerator elementGenerator; - private final Function>, Shrinkable> createShrinkable; + private final Function>, ? extends Shrinkable> createShrinkable; private final int minSize; private final long maxUniqueElements; - private final Collection> uniquenessExtractors; + private final Collection> uniquenessExtractors; private final Function sizeGenerator; private final long maxAttempts; @@ -28,13 +28,13 @@ private static Function sizeGenerator( ContainerGenerator( RandomGenerator elementGenerator, - Function>, Shrinkable> createShrinkable, + Function>, ? extends Shrinkable> createShrinkable, int minSize, int maxSize, long maxUniqueElements, int genSize, RandomDistribution sizeDistribution, - Collection> uniquenessExtractors + Collection> uniquenessExtractors ) { this.elementGenerator = elementGenerator; this.createShrinkable = createShrinkable; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FilteredGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FilteredGenerator.java index 07f42e86a..a5f3c8c14 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FilteredGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FilteredGenerator.java @@ -8,10 +8,10 @@ public class FilteredGenerator implements RandomGenerator { private final RandomGenerator toFilter; - private final Predicate filterPredicate; + private final Predicate filterPredicate; private int maxMisses; - public FilteredGenerator(RandomGenerator toFilter, Predicate filterPredicate, int maxMisses) { + public FilteredGenerator(RandomGenerator toFilter, Predicate filterPredicate, int maxMisses) { this.toFilter = toFilter; this.filterPredicate = filterPredicate; this.maxMisses = maxMisses; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/RandomGenerators.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/RandomGenerators.java index 5e6fb3a1e..02bbfeeca 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/RandomGenerators.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/RandomGenerators.java @@ -10,6 +10,8 @@ import net.jqwik.engine.properties.*; import net.jqwik.engine.properties.shrinking.*; +import org.jspecify.annotations.*; + import static java.lang.Math.*; public class RandomGenerators { @@ -24,8 +26,8 @@ public static int collectionMaxSize(int minSize, Integer maxSize) { return max(RandomGenerators.DEFAULT_COLLECTION_SIZE, doubleMinSize); } - public static RandomGenerator choose(List values) { - if (values.size() == 0) { + public static RandomGenerator choose(List values) { + if (values.isEmpty()) { return fail("empty set of values"); } return random -> { @@ -34,12 +36,12 @@ public static RandomGenerator choose(List values) { }; } - public static U chooseValue(List values, Random random) { + public static U chooseValue(List values, Random random) { int index = random.nextInt(values.size()); return values.get(index); } - public static RandomGenerator choose(U[] values) { + public static RandomGenerator choose(U[] values) { return choose(Arrays.asList(values)); } @@ -84,11 +86,11 @@ public static RandomGenerator bigDecimals( return RandomDecimalGenerators.bigDecimals(1000, range, scale, distribution, shrinkingTarget); } - public static RandomGenerator oneOf(List> all) { + public static RandomGenerator oneOf(List> all) { return choose(all).flatMap(Function.identity()); } - public static RandomGenerator> shuffle(List values) { + public static RandomGenerator> shuffle(List values) { return random -> { List clone = new ArrayList<>(values); Collections.shuffle(clone, random); @@ -103,17 +105,17 @@ public static RandomGenerator strings( Arbitrary characterArbitrary, boolean uniqueChars ) { - Function>, Shrinkable> createShrinkable = elements -> new ShrinkableString(elements, minLength, maxLength, characterArbitrary, uniqueChars); + Function>, Shrinkable> createShrinkable = elements -> new ShrinkableString(elements, minLength, maxLength, characterArbitrary, uniqueChars); Set> featureExtractors = uniqueChars ? ShrinkableString.UNIQUE_CHARS_EXTRACTOR : Collections.emptySet(); return container(elementGenerator, createShrinkable, minLength, maxLength, maxUniqueChars, genSize, lengthDistribution, featureExtractors); } - private static RandomGenerator container( + private static RandomGenerator container( RandomGenerator elementGenerator, - Function>, Shrinkable> createShrinkable, + Function>, ? extends Shrinkable> createShrinkable, int minSize, int maxSize, long maxUniqueElements, int genSize, RandomDistribution sizeDistribution, - Set> uniquenessExtractors + Set> uniquenessExtractors ) { if (minSize > maxSize) { String message = String.format("minSize <%s> must not be larger than maxSize <%s>.", minSize, maxSize); @@ -127,19 +129,19 @@ private static RandomGenerator container( ); } - public static RandomGenerator> list( + public static RandomGenerator> list( RandomGenerator elementGenerator, int minSize, int maxSize, long maxUniqueElements, int genSize, RandomDistribution sizeDistribution, - Set> uniquenessExtractors, + Set> uniquenessExtractors, Arbitrary elementArbitrary ) { - Function>, Shrinkable>> createShrinkable = + Function>, Shrinkable>> createShrinkable = elements -> new ShrinkableList<>(elements, minSize, maxSize, uniquenessExtractors, elementArbitrary); return container(elementGenerator, createShrinkable, minSize, maxSize, maxUniqueElements, genSize, sizeDistribution, uniquenessExtractors); } - public static RandomGenerator> set( + public static RandomGenerator> set( RandomGenerator elementGenerator, int minSize, int maxSize, int genSize, Arbitrary elementArbitrary @@ -147,20 +149,20 @@ public static RandomGenerator> set( return set(elementGenerator, minSize, maxSize, genSize, null, Collections.emptySet(), elementArbitrary); } - public static RandomGenerator> set( + public static RandomGenerator> set( RandomGenerator elementGenerator, int minSize, int maxSize, int genSize, RandomDistribution sizeDistribution, - Set> uniquenessExtractors, + Set> uniquenessExtractors, Arbitrary elementArbitrary ) { Set> extractors = new LinkedHashSet<>(uniquenessExtractors); extractors.add(FeatureExtractor.identity()); - Function>, Shrinkable>> createShrinkable = + Function>, ? extends Shrinkable>> createShrinkable = elements -> new ShrinkableSet(elements, minSize, maxSize, uniquenessExtractors, elementArbitrary); return container(elementGenerator, createShrinkable, minSize, maxSize, maxSize, genSize, sizeDistribution, extractors); } - public static RandomGenerator samplesFromShrinkables(List> samples) { + public static RandomGenerator samplesFromShrinkables(List> samples) { AtomicInteger tryCount = new AtomicInteger(0); return ignored -> { if (tryCount.get() >= samples.size()) @@ -169,16 +171,16 @@ public static RandomGenerator samplesFromShrinkables(List> }; } - public static RandomGenerator samples(T[] samples) { + public static RandomGenerator samples(T[] samples) { List> shrinkables = SampleShrinkable.listOf(samples); return samplesFromShrinkables(shrinkables); } - public static RandomGenerator frequency(List> frequencies) { + public static RandomGenerator frequency(List> frequencies) { return new FrequencyGenerator<>(frequencies); } - public static RandomGenerator frequencyOf( + public static RandomGenerator frequencyOf( List>> frequencies, int genSize, boolean withEmbeddedEdgeCases @@ -186,14 +188,14 @@ public static RandomGenerator frequencyOf( return frequency(frequencies).flatMap(Function.identity(), genSize, withEmbeddedEdgeCases); } - public static RandomGenerator withEdgeCases(RandomGenerator self, int genSize, EdgeCases edgeCases) { + public static RandomGenerator withEdgeCases(RandomGenerator self, int genSize, EdgeCases edgeCases) { if (edgeCases.isEmpty()) { return self; } return new WithEdgeCasesGenerator<>(self, edgeCases, genSize); } - public static RandomGenerator fail(String message) { + public static RandomGenerator fail(String message) { return ignored -> { throw new JqwikException(message); }; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/WithEdgeCasesGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/WithEdgeCasesGenerator.java index b961dd5ed..6f20ad0a6 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/WithEdgeCasesGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/WithEdgeCasesGenerator.java @@ -6,6 +6,8 @@ import net.jqwik.api.*; import net.jqwik.engine.properties.*; +import org.jspecify.annotations.*; + class WithEdgeCasesGenerator implements RandomGenerator { private final RandomGenerator base; @@ -27,7 +29,7 @@ public Shrinkable next(final Random random) { } } - private static RandomGenerator chooseEdgeCase(EdgeCases edgeCases) { + private static RandomGenerator chooseEdgeCase(EdgeCases edgeCases) { final List>> suppliers = edgeCases.suppliers(); return random -> RandomGenerators.chooseValue(suppliers, random).get(); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/package-info.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/package-info.java new file mode 100644 index 000000000..ac018d97f --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine.properties.arbitraries.randomized; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/main/java/net/jqwik/engine/properties/configurators/UniqueElementsConfigurator.java b/engine/src/main/java/net/jqwik/engine/properties/configurators/UniqueElementsConfigurator.java index 72b3e32b0..fedc890ad 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/configurators/UniqueElementsConfigurator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/configurators/UniqueElementsConfigurator.java @@ -12,12 +12,14 @@ import net.jqwik.api.providers.*; import net.jqwik.engine.support.*; +import org.jspecify.annotations.*; + @SuppressWarnings("unchecked") public class UniqueElementsConfigurator implements ArbitraryConfigurator { @SuppressWarnings("OverlyComplexMethod") @Override - public Arbitrary configure(Arbitrary arbitrary, TypeUsage targetType) { + public Arbitrary configure(Arbitrary arbitrary, TypeUsage targetType) { return targetType.findAnnotation(UniqueElements.class).map(uniqueness -> { if (arbitrary instanceof SetArbitrary) { // Handle SetArbitrary explicitly for optimization @@ -36,7 +38,7 @@ public Arbitrary configure(Arbitrary arbitrary, TypeUsage targetType) } if (targetType.isArray()) { Arbitrary arrayArbitrary = (Arbitrary) arbitrary; - Predicate> predicate = isUnique(uniqueness); + Predicate> predicate = isUnique(uniqueness); return (Arbitrary) arrayArbitrary.filter(array -> predicate.test(Arrays.asList(array))); } if (targetType.isAssignableFrom(Stream.class)) { @@ -56,7 +58,7 @@ public Arbitrary configure(Arbitrary arbitrary, TypeUsage targetType) }).orElse(arbitrary); } - private List toList(Iterator i) { + private List toList(Iterator i) { List list = new ArrayList<>(); while (i.hasNext()) { list.add(i.next()); @@ -64,7 +66,7 @@ private List toList(Iterator i) { return list; } - private static > Predicate isUnique(UniqueElements uniqueness) { + private static > Predicate isUnique(UniqueElements uniqueness) { Class> extractorClass = uniqueness.by(); if (extractorClass.equals(UniqueElements.NOT_SET.class)) { return items -> { @@ -98,7 +100,7 @@ private static > Predicate isUnique(Un }; } - private Arbitrary configureStreamableArbitrary(StreamableArbitrary arbitrary, UniqueElements uniqueness) { + private Arbitrary configureStreamableArbitrary(StreamableArbitrary arbitrary, UniqueElements uniqueness) { Class> extractorClass = uniqueness.by(); if (extractorClass.equals(UniqueElements.NOT_SET.class)) { return arbitrary.uniqueElements(); @@ -107,7 +109,7 @@ private Arbitrary configureStreamableArbitrary(StreamableArbitrary return arbitrary.uniqueElements(extractor); } - private Arbitrary configureSetArbitrary(SetArbitrary arbitrary, UniqueElements uniqueness) { + private Arbitrary configureSetArbitrary(SetArbitrary arbitrary, UniqueElements uniqueness) { Class> extractorClass = uniqueness.by(); if (extractorClass.equals(UniqueElements.NOT_SET.class)) { return arbitrary; @@ -116,7 +118,7 @@ private Arbitrary configureSetArbitrary(SetArbitrary arbitrary, Unique return arbitrary.uniqueElements(extractor); } - private static Function extractor(Class> extractorClass) { + private static Function extractor(Class> extractorClass) { return (Function) ( extractorClass.equals(UniqueElements.NOT_SET.class) ? Function.identity() diff --git a/engine/src/main/java/net/jqwik/engine/properties/configurators/package-info.java b/engine/src/main/java/net/jqwik/engine/properties/configurators/package-info.java new file mode 100644 index 000000000..be011f43f --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/properties/configurators/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine.properties.configurators; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/main/java/net/jqwik/engine/properties/package-info.java b/engine/src/main/java/net/jqwik/engine/properties/package-info.java new file mode 100644 index 000000000..821b5a4dd --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/properties/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine.properties; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/AggressiveSizeOfListShrinker.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/AggressiveSizeOfListShrinker.java index d3d5b38f8..e3a296a9e 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/AggressiveSizeOfListShrinker.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/AggressiveSizeOfListShrinker.java @@ -13,7 +13,7 @@ public AggressiveSizeOfListShrinker(int minSize) { this.minSize = minSize; } - public Stream> shrink(List toShrink) { + public Stream> shrink(List toShrink) { if (toShrink.size() <= minSize) { return Stream.empty(); } @@ -24,14 +24,14 @@ public Stream> shrink(List toShrink) { ).filter(l -> l.size() >= minSize); } - public Stream> cutsToMinsize(List toShrink) { + public Stream> cutsToMinsize(List toShrink) { Set> lists = new LinkedHashSet<>(); appendLeftCut(toShrink, lists, minSize); appendRightCut(toShrink, lists, minSize); return lists.stream(); } - public Stream> cutsToMinsizePlus1(List toShrink) { + public Stream> cutsToMinsizePlus1(List toShrink) { if (toShrink.size() <= minSize + 1) { return Stream.empty(); } @@ -41,7 +41,7 @@ public Stream> cutsToMinsizePlus1(List toShrink) { return lists.stream(); } - public Stream> cutInHalves(List toShrink) { + public Stream> cutInHalves(List toShrink) { int halfSize = toShrink.size() / 2; if (halfSize < minSize) { return Stream.empty(); @@ -52,12 +52,12 @@ public Stream> cutInHalves(List toShrink) { return lists.stream(); } - private void appendLeftCut(List toShrink, Set> lists, int elementsToKeep) { + private void appendLeftCut(List toShrink, Set> lists, int elementsToKeep) { List cut = new ArrayList<>(toShrink); lists.add(cut.subList(0, elementsToKeep)); } - private void appendRightCut(List toShrink, Set> lists, int elementsToKeep) { + private void appendRightCut(List toShrink, Set> lists, int elementsToKeep) { List cut = new ArrayList<>(toShrink); int elementsToCut = toShrink.size() - elementsToKeep; lists.add(cut.subList(elementsToCut, toShrink.size())); diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/CollectShrinkable.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/CollectShrinkable.java index c5d275a26..5268a4263 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/CollectShrinkable.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/CollectShrinkable.java @@ -8,10 +8,10 @@ import net.jqwik.engine.support.*; public class CollectShrinkable implements Shrinkable> { - private final List> elements; - private final Predicate> until; + private final List> elements; + private final Predicate> until; - public CollectShrinkable(List> elements, Predicate> until) { + public CollectShrinkable(List> elements, Predicate> until) { this.elements = elements; this.until = until; } @@ -21,7 +21,7 @@ public List value() { return createValue(elements); } - private List createValue(List> elements) { + private List createValue(List> elements) { return elements .stream() .map(Shrinkable::value) @@ -53,10 +53,10 @@ private Stream>> shrinkElementsOneAfterTheOther() { } private Stream>> sortElements() { - return ShrinkingCommons.sortElements(elements, this::createShrinkable); + return ShrinkingCommons.sortElements(elements, (ShrinkingCommons.ContainerCreator, T>) this::createShrinkable); } - private CollectShrinkable createShrinkable(List> pairSwap) { + private CollectShrinkable createShrinkable(List> pairSwap) { return new CollectShrinkable<>(pairSwap, until); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/CombinedShrinkable.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/CombinedShrinkable.java index d2c35a489..ab539f030 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/CombinedShrinkable.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/CombinedShrinkable.java @@ -9,9 +9,9 @@ public class CombinedShrinkable implements Shrinkable { private final List> parts; - private final Function, T> combinator; + private final Function, ? extends T> combinator; - public CombinedShrinkable(List> parts, Function, T> combinator) { + public CombinedShrinkable(List> parts, Function, ? extends T> combinator) { this.parts = parts; this.combinator = combinator; } diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/FilteredShrinkable.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/FilteredShrinkable.java index ced0aa877..0815b42a7 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/FilteredShrinkable.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/FilteredShrinkable.java @@ -14,9 +14,9 @@ public class FilteredShrinkable implements Shrinkable { private final AtomicInteger countBaseShrinks = new AtomicInteger(0); private final Shrinkable toFilter; - private final Predicate filter; + private final Predicate filter; - public FilteredShrinkable(Shrinkable toFilter, Predicate filter) { + public FilteredShrinkable(Shrinkable toFilter, Predicate filter) { this.toFilter = toFilter; this.filter = filter; } diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/FixedValueFlatMappedShrinkable.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/FixedValueFlatMappedShrinkable.java index 9d6eb5545..f67c9fc2e 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/FixedValueFlatMappedShrinkable.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/FixedValueFlatMappedShrinkable.java @@ -4,14 +4,16 @@ import net.jqwik.api.*; -public class FixedValueFlatMappedShrinkable extends FlatMappedShrinkable { +import org.jspecify.annotations.*; - private final Supplier> shrinkableSupplier; +public class FixedValueFlatMappedShrinkable extends FlatMappedShrinkable { + + private final Supplier> shrinkableSupplier; public FixedValueFlatMappedShrinkable( Shrinkable toMap, - Function> mapper, - Supplier> shrinkableSupplier + Function> mapper, + Supplier> shrinkableSupplier ) { super(toMap, mapper); this.shrinkableSupplier = shrinkableSupplier; diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/FlatMappedShrinkable.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/FlatMappedShrinkable.java index 4cdb6f3b0..546376f7b 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/FlatMappedShrinkable.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/FlatMappedShrinkable.java @@ -9,14 +9,16 @@ import net.jqwik.engine.*; import net.jqwik.engine.support.*; -public class FlatMappedShrinkable implements Shrinkable { +import org.jspecify.annotations.*; + +public class FlatMappedShrinkable implements Shrinkable { private final Shrinkable toMap; - private final Function> mapper; + private final Function> mapper; public FlatMappedShrinkable( Shrinkable toMap, - Function> toArbitraryMapper, + Function> toArbitraryMapper, int genSize, long randomSeed, boolean withEmbeddedEdgeCases @@ -27,11 +29,11 @@ public FlatMappedShrinkable( }, randomSeed); } - public FlatMappedShrinkable(Shrinkable toMap, Function> toGeneratorMapper, long randomSeed) { + public FlatMappedShrinkable(Shrinkable toMap, Function> toGeneratorMapper, long randomSeed) { this(toMap, t -> toGeneratorMapper.apply(t).next(SourceOfRandomness.newRandom(randomSeed))); } - protected FlatMappedShrinkable(Shrinkable toMap, Function> mapper) { + protected FlatMappedShrinkable(Shrinkable toMap, Function> mapper) { this.toMap = toMap; this.mapper = mapper; } diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/MappedShrinkable.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/MappedShrinkable.java index c0799dbfd..c29814454 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/MappedShrinkable.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/MappedShrinkable.java @@ -9,9 +9,9 @@ public class MappedShrinkable implements Shrinkable { private final Shrinkable toMap; - private final Function mapper; + private final Function mapper; - public MappedShrinkable(Shrinkable toMap, Function mapper) { + public MappedShrinkable(Shrinkable toMap, Function mapper) { this.toMap = toMap; this.mapper = mapper; } diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/OneAfterTheOtherParameterShrinker.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/OneAfterTheOtherParameterShrinker.java index ce5a560a6..23095bc36 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/OneAfterTheOtherParameterShrinker.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/OneAfterTheOtherParameterShrinker.java @@ -7,6 +7,8 @@ import net.jqwik.api.*; import net.jqwik.api.lifecycle.*; +import org.jspecify.annotations.*; + class OneAfterTheOtherParameterShrinker extends AbstractSampleShrinker { public OneAfterTheOtherParameterShrinker(Map, TryExecutionResult> falsificationCache) { @@ -49,7 +51,7 @@ private FalsifiedSample shrinkSingleParameter( ); } - private List replaceIn(T object, int index, List old) { + private List replaceIn(T object, int index, List old) { List newList = new ArrayList<>(old); newList.set(index, object); return newList; diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/PropertyShrinker.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/PropertyShrinker.java index 2e8d7bcd5..9647b3516 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/PropertyShrinker.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/PropertyShrinker.java @@ -46,7 +46,7 @@ public PropertyShrinker( this.targetMethod = targetMethod; } - public ShrunkFalsifiedSample shrink(Falsifier> forAllFalsifier) { + public ShrunkFalsifiedSample shrink(Falsifier> forAllFalsifier) { if (shrinkingMode == ShrinkingMode.OFF) { return unshrunkOriginalSample(); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkableContainer.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkableContainer.java index 725f46e63..d22280917 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkableContainer.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkableContainer.java @@ -13,18 +13,17 @@ import static net.jqwik.engine.properties.UniquenessChecker.*; abstract class ShrinkableContainer implements Shrinkable { - protected final List> elements; + protected final List> elements; protected final int minSize; protected final int maxSize; - protected final Collection> uniquenessExtractors; + protected final Collection> uniquenessExtractors; - @Nullable - protected final Arbitrary elementArbitrary; + protected final @Nullable Arbitrary elementArbitrary; ShrinkableContainer( - List> elements, + List> elements, int minSize, int maxSize, - Collection> uniquenessExtractors, + Collection> uniquenessExtractors, @Nullable Arbitrary elementArbitrary ) { this.elements = elements; @@ -34,7 +33,7 @@ abstract class ShrinkableContainer implements Shrinkable { this.elementArbitrary = elementArbitrary; } - abstract C createValue(List> shrinkables); + abstract C createValue(List> shrinkables); @Override public C value() { @@ -159,7 +158,7 @@ protected Stream> shrinkPairsOfElements() { } protected Stream> sortElements() { - return ShrinkingCommons.sortElements(elements, this::createShrinkable); + return ShrinkingCommons.sortElements(elements, (ShrinkingCommons.ContainerCreator) this::createShrinkable); } @Override @@ -190,6 +189,6 @@ public String toString() { ); } - abstract Shrinkable createShrinkable(List> shrunkElements); + abstract Shrinkable createShrinkable(List> shrunkElements); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkableList.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkableList.java index 26a51f7cf..b2bbacb74 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkableList.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkableList.java @@ -17,16 +17,16 @@ public class ShrinkableList extends ShrinkableContainer, E> { } public ShrinkableList( - List> elements, + List> elements, int minSize, int maxSize, - Collection> uniquenessExtractors, + Collection> uniquenessExtractors, Arbitrary elementArbitrary ) { super(elements, minSize, maxSize, uniquenessExtractors, elementArbitrary); } @Override - List createValue(List> shrinkables) { + List createValue(List> shrinkables) { // Using loop instead of stream to make stack traces more readable List values = new ArrayList<>(shrinkables.size()); for (Shrinkable shrinkable : shrinkables) { @@ -36,7 +36,7 @@ List createValue(List> shrinkables) { } @Override - Shrinkable> createShrinkable(List> shrunkElements) { + Shrinkable> createShrinkable(List> shrunkElements) { return new ShrinkableList<>(shrunkElements, minSize, maxSize, uniquenessExtractors, elementArbitrary); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkableSet.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkableSet.java index c45adbe10..aaacd69b8 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkableSet.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkableSet.java @@ -11,18 +11,18 @@ public class ShrinkableSet extends ShrinkableContainer, E> { public ShrinkableSet( - Collection> elements, + Collection> elements, int minSize, int maxSize, - Collection> uniquenessExtractors, + Collection> uniquenessExtractors, @Nullable Arbitrary elementArbitrary ) { this(new ArrayList<>(elements), minSize, maxSize, uniquenessExtractors, elementArbitrary); } private ShrinkableSet( - List> elements, + List> elements, int minSize, int maxSize, - Collection> uniquenessExtractors, + Collection> uniquenessExtractors, @Nullable Arbitrary elementArbitrary ) { super(elements, minSize, maxSize, uniquenessExtractors, elementArbitrary); @@ -39,7 +39,7 @@ protected boolean hasReallyGrown(Shrinkable> grownShrinkable) { } @Override - Set createValue(List> shrinkables) { + Set createValue(List> shrinkables) { // See https://richardstartin.github.io/posts/5-java-mundane-performance-tricks#size-hashmaps-whenever-possible // for how to compute initial capacity of hash maps int capacityWithLoadFactor = shrinkables.size() * 4 / 3; @@ -53,7 +53,7 @@ Set createValue(List> shrinkables) { } @Override - Shrinkable> createShrinkable(List> shrunkElements) { + Shrinkable> createShrinkable(List> shrunkElements) { return new ShrinkableSet<>(shrunkElements, minSize, maxSize, uniquenessExtractors, elementArbitrary); } } diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkableString.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkableString.java index ea9a67a54..0b31d58c4 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkableString.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkableString.java @@ -1,7 +1,6 @@ package net.jqwik.engine.properties.shrinking; import java.util.*; -import java.util.function.*; import java.util.stream.*; import net.jqwik.api.*; @@ -13,7 +12,7 @@ public class ShrinkableString extends ShrinkableContainer { public static final Set> UNIQUE_CHARS_EXTRACTOR = Collections.singleton(FeatureExtractor.identity()); public ShrinkableString( - List> elements, int minSize, int maxSize, + List> elements, int minSize, int maxSize, Arbitrary characterArbitrary, boolean uniqueChars ) { @@ -21,8 +20,8 @@ public ShrinkableString( } private ShrinkableString( - List> elements, int minSize, int maxSize, - Collection> uniquenessExtractors, + List> elements, int minSize, int maxSize, + Collection> uniquenessExtractors, Arbitrary characterArbitrary ) { super(elements, minSize, maxSize, uniquenessExtractors, characterArbitrary); @@ -33,7 +32,7 @@ private static Collection> uniquenessExtractors(bool } @Override - String createValue(List> shrinkables) { + String createValue(List> shrinkables) { // Using loop instead of stream to make stack traces more readable StringBuilder builder = new StringBuilder(shrinkables.size()); for (Shrinkable shrinkable : shrinkables) { @@ -43,7 +42,7 @@ String createValue(List> shrinkables) { } @Override - Shrinkable createShrinkable(List> shrunkElements) { + Shrinkable createShrinkable(List> shrunkElements) { return new ShrinkableString(shrunkElements, minSize, maxSize, uniquenessExtractors, elementArbitrary); } diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkingCommons.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkingCommons.java index b1791d423..e2137009b 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkingCommons.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkingCommons.java @@ -7,12 +7,14 @@ import net.jqwik.api.*; import net.jqwik.engine.support.*; +import org.jspecify.annotations.*; + import static net.jqwik.engine.properties.UniquenessChecker.*; class ShrinkingCommons { @FunctionalInterface - interface ContainerCreator extends Function>, Shrinkable> {} + interface ContainerCreator extends Function>, Shrinkable> {} /** * Shrink elements of a container pairwise @@ -23,7 +25,7 @@ interface ContainerCreator extends Function>, Shrinkabl * @param type of elements * @return stream of shrunk containers */ - static Stream> shrinkPairsOfElements(List> elements, ContainerCreator createContainer) { + static Stream> shrinkPairsOfElements(List> elements, ContainerCreator createContainer) { return Combinatorics .distinctPairs(elements.size()) .flatMap(pair -> JqwikStreamSupport.zip( @@ -47,7 +49,7 @@ static Stream> shrinkPairsOfElements(List> e * @param type of elements * @return stream of shrunk containers */ - static Stream> sortElements(List> elements, ContainerCreator createContainer) { + static Stream> sortElements(List> elements, ContainerCreator createContainer) { List> sortedElements = new ArrayList<>(elements); sortedElements.sort(Comparator.comparing(Shrinkable::distance)); if (elements.equals(sortedElements)) { @@ -59,11 +61,11 @@ static Stream> sortElements(List> elements, C ); } - private static Stream> fullSort(List> sortedElements, ContainerCreator createContainer) { + private static Stream> fullSort(List> sortedElements, ContainerCreator createContainer) { return Stream.of(createContainer.apply(sortedElements)); } - private static Stream> pairwiseSort(List> elements, ContainerCreator createContainer) { + private static Stream> pairwiseSort(List> elements, ContainerCreator createContainer) { return Combinatorics.distinctPairs(elements.size()) .map(pair -> { int firstIndex = Math.min(pair.get1(), pair.get2()); diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/SizeOfListShrinker.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/SizeOfListShrinker.java index 7628fa8c2..d819a2850 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/SizeOfListShrinker.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/SizeOfListShrinker.java @@ -5,7 +5,9 @@ import net.jqwik.engine.support.*; -public class SizeOfListShrinker { +import org.jspecify.annotations.*; + +public class SizeOfListShrinker { private final int minSize; @@ -13,7 +15,7 @@ public SizeOfListShrinker(int minSize) { this.minSize = minSize; } - public Stream> shrink(List toShrink) { + public Stream> shrink(List toShrink) { if (toShrink.size() <= minSize) return Stream.empty(); return JqwikStreamSupport.concat( @@ -30,14 +32,14 @@ private Stream> emptyList() { } } - public Stream> cuts(List toShrink) { + public Stream> cuts(List toShrink) { Set> lists = new LinkedHashSet<>(); appendRightCuts(toShrink, lists); appendLeftCuts(toShrink, lists); return lists.stream(); } - private void appendLeftCuts(List toShrink, Set> lists) { + private void appendLeftCuts(List toShrink, Set> lists) { int elementsToCut = calculateElementsToCut(toShrink.size()); appendLeftCut(toShrink, lists, elementsToCut); if (elementsToCut != 1) { @@ -45,11 +47,11 @@ private void appendLeftCuts(List toShrink, Set> lists) { } } - private void appendLeftCut(List toShrink, Set> lists, int elementsToCut) { + private void appendLeftCut(List toShrink, Set> lists, int elementsToCut) { lists.add(new ArrayList<>(cutFromLeft(toShrink, elementsToCut))); } - private List cutFromLeft(List toShrink, int elementsToCut) { + private List cutFromLeft(List toShrink, int elementsToCut) { return toShrink.subList(elementsToCut, toShrink.size()); } @@ -68,7 +70,7 @@ private int rawElementsToCut(int listSize) { return listSize / 2; } - private void appendRightCuts(List toShrink, Set> lists) { + private void appendRightCuts(List toShrink, Set> lists) { int elementsToCut = calculateElementsToCut(toShrink.size()); appendRightCut(toShrink, lists, elementsToCut); if (elementsToCut != 1) { @@ -76,11 +78,11 @@ private void appendRightCuts(List toShrink, Set> lists) { } } - private void appendRightCut(List toShrink, Set> lists, int elementsToCut) { + private void appendRightCut(List toShrink, Set> lists, int elementsToCut) { lists.add(new ArrayList<>(cutFromRight(toShrink, elementsToCut))); } - private List cutFromRight(List toShrink, int elementsToCut) { + private List cutFromRight(List toShrink, int elementsToCut) { return toShrink.subList(0, toShrink.size() - elementsToCut); } } diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/Unshrinkable.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/Unshrinkable.java index 71de04812..fb8644003 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/Unshrinkable.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/Unshrinkable.java @@ -9,9 +9,9 @@ public class Unshrinkable implements Shrinkable { private final ShrinkingDistance distance; - private final Supplier valueSupplier; + private final Supplier valueSupplier; - public Unshrinkable(Supplier valueSupplier, ShrinkingDistance distance) { + public Unshrinkable(Supplier valueSupplier, ShrinkingDistance distance) { this.valueSupplier = valueSupplier; this.distance = distance; } diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/package-info.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/package-info.java new file mode 100644 index 000000000..697e10f54 --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine.properties.shrinking; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/main/java/net/jqwik/engine/properties/state/DefaultChainArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/state/DefaultChainArbitrary.java index 18d6d8cca..5c15ae319 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/state/DefaultChainArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/state/DefaultChainArbitrary.java @@ -11,7 +11,7 @@ public class DefaultChainArbitrary extends TypedCloneable implements ChainArbitrary { private int maxTransformations = Integer.MIN_VALUE; - private Supplier> changeDetectorSupplier = ChangeDetector::alwaysTrue; + private Supplier> changeDetectorSupplier = ChangeDetector::alwaysTrue; private List>> weightedTransformations = new ArrayList<>(); private final Supplier initialSupplier; @@ -24,7 +24,7 @@ public RandomGenerator> generator(int genSize) { final int effectiveMaxTransformations = this.maxTransformations != Integer.MIN_VALUE ? this.maxTransformations : (int) Math.max(Math.round(Math.sqrt(genSize)), 10); Function> transformationGenerator = new ChooseRandomlyByFrequency<>(weightedTransformations); - return random -> new ShrinkableChain<>( + return random -> new ShrinkableChain( random.nextLong(), initialSupplier, transformationGenerator, @@ -54,7 +54,7 @@ public ChainArbitrary withMaxTransformations(int maxTransformations) { } @Override - public ChainArbitrary improveShrinkingWith(Supplier> changeDetectorSupplier) { + public ChainArbitrary improveShrinkingWith(Supplier> changeDetectorSupplier) { DefaultChainArbitrary clone = typedClone(); clone.changeDetectorSupplier = changeDetectorSupplier; return clone; diff --git a/engine/src/main/java/net/jqwik/engine/properties/state/SequentialActionChain.java b/engine/src/main/java/net/jqwik/engine/properties/state/SequentialActionChain.java index 9934456a8..340f6be3c 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/state/SequentialActionChain.java +++ b/engine/src/main/java/net/jqwik/engine/properties/state/SequentialActionChain.java @@ -12,12 +12,12 @@ import net.jqwik.api.support.*; import net.jqwik.engine.support.*; -public class SequentialActionChain implements ActionChain { +public class SequentialActionChain implements ActionChain { private final Chain chain; private volatile T currentValue = null; private volatile RunningState currentRunning = RunningState.NOT_RUN; - private final List> peekers = new ArrayList<>(); + private final List> peekers = new ArrayList<>(); private final List>> invariants = new ArrayList<>(); public SequentialActionChain(Chain chain) { @@ -25,7 +25,6 @@ public SequentialActionChain(Chain chain) { } @Override - @NonNull public List transformations() { return chain.transformations(); } @@ -36,7 +35,6 @@ public List> transformers() { } @Override - @NonNull public synchronized T run() { currentRunning = RunningState.RUNNING; for (Iterator iterator = chain.iterator(); iterator.hasNext(); ) { @@ -66,7 +64,7 @@ private void nextAction(Iterator iterator) { } private void callPeekers() { - for (Consumer peeker : peekers) { + for (Consumer peeker : peekers) { peeker.accept(currentValue); } } @@ -98,7 +96,6 @@ private String createErrorMessage(String name, String causeMessage) { } @Override - @NonNull public ActionChain withInvariant(@Nullable String label, Consumer invariant) { String invariantLabel = label == null ? "Invariant" : String.format("Invariant '%s'", label); invariants.add(Tuple.of(invariantLabel, invariant)); @@ -106,20 +103,17 @@ public ActionChain withInvariant(@Nullable String label, Consumer invarian } @Override - @NonNull public synchronized Optional finalState() { return Optional.ofNullable(currentValue); } @Override - // @NonNull // TODO: Why does this not work? public ActionChain.RunningState running() { return currentRunning; } @Override - @NonNull - public synchronized ActionChain peek(@NonNull Consumer peeker) { + public synchronized ActionChain peek(Consumer peeker) { peekers.add(peeker); return this; } diff --git a/engine/src/main/java/net/jqwik/engine/properties/state/ShrinkableChain.java b/engine/src/main/java/net/jqwik/engine/properties/state/ShrinkableChain.java index a1efc4c53..3103e257a 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/state/ShrinkableChain.java +++ b/engine/src/main/java/net/jqwik/engine/properties/state/ShrinkableChain.java @@ -20,17 +20,17 @@ public class ShrinkableChain implements Shrinkable> { public static final int MAX_TRANSFORMER_TRIES = 1000; private final long randomSeed; private final Supplier initialSupplier; - private final Function> transformationGenerator; + private final Function> transformationGenerator; private final int maxTransformations; private final int genSize; private final List> iterations; - private final Supplier> changeDetectorSupplier; + private final Supplier> changeDetectorSupplier; public ShrinkableChain( long randomSeed, Supplier initialSupplier, - Function> transformationGenerator, - Supplier> changeDetectorSupplier, + Function> transformationGenerator, + Supplier> changeDetectorSupplier, int maxTransformations, int genSize ) { @@ -39,8 +39,8 @@ public ShrinkableChain( private ShrinkableChain( long randomSeed, Supplier initialSupplier, - Function> transformationGenerator, - Supplier> changeDetectorSupplier, + Function> transformationGenerator, + Supplier> changeDetectorSupplier, int maxTransformations, int genSize, List> iterations @@ -55,13 +55,11 @@ private ShrinkableChain( } @Override - @NonNull public Chain value() { return new ChainInstance(); } @Override - @NonNull public Stream>> shrink() { return new ShrinkableChainShrinker<>(this, iterations, maxTransformations).shrink(); } @@ -79,7 +77,6 @@ ShrinkableChain cloneWith(List> shrunkIterations, } @Override - @NonNull public ShrinkingDistance distance() { List>> shrinkablesForDistance = new ArrayList<>(); for (int i = 0; i < maxTransformations; i++) { @@ -100,7 +97,6 @@ public String toString() { private class ChainInstance implements Chain { @Override - @NonNull public Iterator start() { return new ChainIterator(initialSupplier.get()); } @@ -111,13 +107,11 @@ public int maxTransformations() { } @Override - @NonNull public List transformations() { return iterations.stream().map(i -> i.transformation()).collect(Collectors.toList()); } @Override - @NonNull public List> transformers() { return iterations.stream().map(i -> i.transformer()).collect(Collectors.toList()); } @@ -187,7 +181,7 @@ private Transformer nextTransformer() { } private T transformState(Transformer transformer, T before) { - ChangeDetector changeDetector = changeDetectorSupplier.get(); + ChangeDetector changeDetector = changeDetectorSupplier.get(); changeDetector.before(before); try { T after = transformer.apply(before); diff --git a/engine/src/main/java/net/jqwik/engine/properties/state/ShrinkableChainIteration.java b/engine/src/main/java/net/jqwik/engine/properties/state/ShrinkableChainIteration.java index be11ffdb0..c20d5f055 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/state/ShrinkableChainIteration.java +++ b/engine/src/main/java/net/jqwik/engine/properties/state/ShrinkableChainIteration.java @@ -6,16 +6,18 @@ import net.jqwik.api.*; import net.jqwik.api.state.*; +import org.jspecify.annotations.*; + class ShrinkableChainIteration { final Shrinkable> shrinkable; final boolean accessState; final boolean changeState; - private final Predicate precondition; - private final Transformer cachedTransformer; + private final @Nullable Predicate precondition; + private final @Nullable Transformer cachedTransformer; ShrinkableChainIteration( - Predicate precondition, + @Nullable Predicate precondition, boolean accessState, Shrinkable> shrinkable ) { @@ -24,7 +26,7 @@ class ShrinkableChainIteration { } private ShrinkableChainIteration( - Predicate precondition, + @Nullable Predicate precondition, boolean accessState, boolean changeState, Shrinkable> shrinkable diff --git a/engine/src/main/java/net/jqwik/engine/properties/state/package-info.java b/engine/src/main/java/net/jqwik/engine/properties/state/package-info.java new file mode 100644 index 000000000..1f8a77b63 --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/properties/state/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine.properties.state; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/main/java/net/jqwik/engine/properties/stateful/ActionGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/stateful/ActionGenerator.java index 9b0b89830..2e3d2f330 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/stateful/ActionGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/stateful/ActionGenerator.java @@ -5,7 +5,9 @@ import net.jqwik.api.*; import net.jqwik.api.stateful.*; -interface ActionGenerator { +import org.jspecify.annotations.*; + +interface ActionGenerator { Action next(M model); diff --git a/engine/src/main/java/net/jqwik/engine/properties/stateful/RandomActionGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/stateful/RandomActionGenerator.java index dba103baa..1ef178a43 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/stateful/RandomActionGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/stateful/RandomActionGenerator.java @@ -5,7 +5,9 @@ import net.jqwik.api.*; import net.jqwik.api.stateful.*; -class RandomActionGenerator implements ActionGenerator { +import org.jspecify.annotations.*; + +class RandomActionGenerator implements ActionGenerator { private static final int MAX_TRIES = 1000; diff --git a/engine/src/main/java/net/jqwik/engine/properties/stateful/ShrinkablesActionGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/stateful/ShrinkablesActionGenerator.java index fed75bbc2..5e6baf059 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/stateful/ShrinkablesActionGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/stateful/ShrinkablesActionGenerator.java @@ -5,7 +5,9 @@ import net.jqwik.api.*; import net.jqwik.api.stateful.*; -class ShrinkablesActionGenerator implements ActionGenerator { +import org.jspecify.annotations.*; + +class ShrinkablesActionGenerator implements ActionGenerator { private Iterator>> iterator; private List>> shrinkables = new ArrayList<>(); diff --git a/engine/src/main/java/net/jqwik/engine/properties/stateful/package-info.java b/engine/src/main/java/net/jqwik/engine/properties/stateful/package-info.java new file mode 100644 index 000000000..181c00e4d --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/properties/stateful/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine.properties.stateful; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/main/java/net/jqwik/engine/providers/package-info.java b/engine/src/main/java/net/jqwik/engine/providers/package-info.java new file mode 100644 index 000000000..13b56dff6 --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/providers/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine.providers; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/main/java/net/jqwik/engine/recording/package-info.java b/engine/src/main/java/net/jqwik/engine/recording/package-info.java new file mode 100644 index 000000000..2f557efc7 --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/recording/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine.recording; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/main/java/net/jqwik/engine/support/Combinatorics.java b/engine/src/main/java/net/jqwik/engine/support/Combinatorics.java index 19a55c413..348b5f7ac 100644 --- a/engine/src/main/java/net/jqwik/engine/support/Combinatorics.java +++ b/engine/src/main/java/net/jqwik/engine/support/Combinatorics.java @@ -9,11 +9,13 @@ import net.jqwik.api.Tuple.*; import net.jqwik.engine.support.combinatorics.*; +import org.jspecify.annotations.*; + import static java.util.Arrays.*; public class Combinatorics { - public static Iterator> combine(List> listOfIterables) { + public static Iterator> combine(List> listOfIterables) { if (listOfIterables.isEmpty()) { return emptyListSingleton(); } @@ -21,16 +23,16 @@ public static Iterator> combine(List> listOfIterables) { } @SuppressWarnings("unchecked") - private static Iterator> emptyListSingleton() { + private static Iterator> emptyListSingleton() { return asList((List) new ArrayList<>()).iterator(); } @SuppressWarnings("unchecked") - private static Iterator> emptySetSingleton() { + private static Iterator> emptySetSingleton() { return asList((Set) new LinkedHashSet<>()).iterator(); } - public static Iterator> listCombinations(Iterable elementIterable, int minSize, int maxSize) { + public static Iterator> listCombinations(Iterable elementIterable, int minSize, int maxSize) { List>> iterators = new ArrayList<>(); for(int listSize = minSize; listSize <= maxSize; listSize++) { iterators.add(listIterator(elementIterable, listSize)); @@ -38,15 +40,15 @@ public static Iterator> listCombinations(Iterable elementIterable return concatIterators(iterators); } - private static Iterator> listIterator(Iterable elementIterable, int listSize) { - List> listOfIterables = new ArrayList<>(); + private static Iterator> listIterator(Iterable elementIterable, int listSize) { + List> listOfIterables = new ArrayList<>(); for (int i = 0; i < listSize; i++) { listOfIterables.add(elementIterable); } return combine(listOfIterables); } - public static Iterator> setCombinations(Iterable elementIterable, int minSize, int maxSize) { + public static Iterator> setCombinations(Iterable elementIterable, int minSize, int maxSize) { List>> iterators = new ArrayList<>(); for(int setSize = minSize; setSize <= maxSize; setSize++) { Iterator> setIterator = setIterator(elementIterable, setSize); @@ -55,26 +57,26 @@ public static Iterator> setCombinations(Iterable elementIterable, return concatIterators(iterators); } - private static Iterator> setIterator(Iterable elementIterable, int setSize) { + private static Iterator> setIterator(Iterable elementIterable, int setSize) { if (setSize == 0) { return emptySetSingleton(); } return new SetIterator<>(elementIterable, setSize); } - public static Iterator> listPermutations(List values) { + public static Iterator> listPermutations(List values) { if (values.isEmpty()) { return emptyListSingleton(); } return new PermutationIterator<>(values); } - public static Iterator concat(List> iterables) { - List> iterators = iterables.stream().map(Iterable::iterator).collect(Collectors.toList()); + public static Iterator concat(List> iterables) { + List> iterators = iterables.stream().map(Iterable::iterator).collect(Collectors.toList()); return new ConcatIterator<>(iterators); } - private static Iterator concatIterators(List> iterators) { + private static Iterator concatIterators(List> iterators) { return new ConcatIterator<>(iterators); } diff --git a/engine/src/main/java/net/jqwik/engine/support/JqwikStreamSupport.java b/engine/src/main/java/net/jqwik/engine/support/JqwikStreamSupport.java index f6a7f0a14..7bd50350d 100644 --- a/engine/src/main/java/net/jqwik/engine/support/JqwikStreamSupport.java +++ b/engine/src/main/java/net/jqwik/engine/support/JqwikStreamSupport.java @@ -1,5 +1,7 @@ package net.jqwik.engine.support; +import org.jspecify.annotations.*; + import java.util.*; import java.util.concurrent.atomic.*; import java.util.function.*; @@ -40,13 +42,13 @@ public boolean tryAdvance(Consumer action) { } @SafeVarargs - public static Stream concat(Stream... streams) { + public static Stream concat(Stream... streams) { // See discussion in https://github.com/jqwik-team/jqwik/issues/526 why StreamConcatenation is used return StreamConcatenation.concat(streams); } @SuppressWarnings("unchecked") - public static Stream concat(List> streams) { + public static Stream concat(List> streams) { return concat(streams.toArray(new Stream[0])); } @@ -61,7 +63,7 @@ public static Stream concat(List> streams) { * @param a type * @return a stream */ - public static Stream takeWhile(Stream stream, Predicate p) { + public static Stream takeWhile(Stream stream, Predicate p) { class Taking extends Spliterators.AbstractSpliterator implements Consumer { private static final int CANCEL_CHECK_COUNT = 63; private final Spliterator s; @@ -114,7 +116,7 @@ public Spliterator trySplit() { return StreamSupport.stream(new Taking(stream.spliterator()), stream.isParallel()).onClose(stream::close); } - public static Stream toStream(Optional optional) { + public static Stream toStream(Optional optional) { return optional.map(Stream::of).orElse(Stream.empty()); } } diff --git a/engine/src/main/java/net/jqwik/engine/support/StreamConcatenation.java b/engine/src/main/java/net/jqwik/engine/support/StreamConcatenation.java index 1e7350f57..64e861b51 100644 --- a/engine/src/main/java/net/jqwik/engine/support/StreamConcatenation.java +++ b/engine/src/main/java/net/jqwik/engine/support/StreamConcatenation.java @@ -1,5 +1,7 @@ package net.jqwik.engine.support; +import org.jspecify.annotations.*; + import java.util.*; import java.util.function.*; import java.util.stream.*; @@ -48,7 +50,7 @@ private StreamConcatenation() { */ @SafeVarargs @SuppressWarnings({"unchecked", "varargs"}) // TODO: Explain why this is ok. - public static Stream concat(Stream... streams) { + public static Stream concat(Stream... streams) { return concatInternal( (Stream[]) streams, size -> (Spliterator[]) new Spliterator[size], diff --git a/engine/src/main/java/net/jqwik/engine/support/combinatorics/CombinedIterator.java b/engine/src/main/java/net/jqwik/engine/support/combinatorics/CombinedIterator.java index b2cc4c8d9..a621463ef 100644 --- a/engine/src/main/java/net/jqwik/engine/support/combinatorics/CombinedIterator.java +++ b/engine/src/main/java/net/jqwik/engine/support/combinatorics/CombinedIterator.java @@ -4,13 +4,13 @@ import java.util.stream.*; public class CombinedIterator implements Iterator> { - private final List> iterables; - private final List> iterators; + private final List> iterables; + private final List> iterators; private final List elements; private final boolean isEmpty; private int position = -1; - public CombinedIterator(List> iterables) { + public CombinedIterator(List> iterables) { this.iterables = iterables; elements = new ArrayList<>(Collections.nCopies(iterables.size(), null)); iterators = iterables.stream().map(Iterable::iterator).collect(Collectors.toCollection(ArrayList::new)); @@ -34,7 +34,7 @@ public List next() { // The first initialization of the values resetValuesFrom(0); } else { - Iterator it = iterators.get(position); + Iterator it = iterators.get(position); if (it.hasNext()) { // Just advance the current iterator elements.set(position, it.next()); @@ -53,14 +53,14 @@ public List next() { } private void resetValuesFrom(int startPosition) { - List> iterators = this.iterators; - List> iterables = this.iterables; + List> iterators = this.iterators; + List> iterables = this.iterables; List elements = this.elements; // In the initial reset, we can reuse the existing iterators // It might slightly optimize the behavior, and it supports Stream#iterator which can't be executed twice boolean initialReset = position == -1; for (int i = startPosition; i < iterables.size(); i++) { - Iterator newIt = initialReset ? iterators.get(i) : iterables.get(i).iterator(); + Iterator newIt = initialReset ? iterators.get(i) : iterables.get(i).iterator(); iterators.set(i, newIt); elements.set(i, newIt.next()); } @@ -68,7 +68,7 @@ private void resetValuesFrom(int startPosition) { } private int nextAvailablePosition() { - List> iterators = this.iterators; + List> iterators = this.iterators; for (int i = position; i >= 0; i--) { if (iterators.get(i).hasNext()) { return i; diff --git a/engine/src/main/java/net/jqwik/engine/support/combinatorics/ConcatIterator.java b/engine/src/main/java/net/jqwik/engine/support/combinatorics/ConcatIterator.java index 506c2f540..b7d742fa1 100644 --- a/engine/src/main/java/net/jqwik/engine/support/combinatorics/ConcatIterator.java +++ b/engine/src/main/java/net/jqwik/engine/support/combinatorics/ConcatIterator.java @@ -5,11 +5,11 @@ public class ConcatIterator implements Iterator { - private final List> iterators; + private final List> iterators; private final AtomicInteger position; - private Iterator next; + private Iterator next; - public ConcatIterator(List> iterators) { + public ConcatIterator(List> iterators) { this.iterators = iterators; position = new AtomicInteger(0); if (!iterators.isEmpty()) { @@ -17,7 +17,7 @@ public ConcatIterator(List> iterators) { } } - private Iterator findNext() { + private Iterator findNext() { while (!iterators.get(position.get()).hasNext()) { if (position.get() >= iterators.size() -1) return null; diff --git a/engine/src/main/java/net/jqwik/engine/support/combinatorics/PermutationIterator.java b/engine/src/main/java/net/jqwik/engine/support/combinatorics/PermutationIterator.java index e11739aa9..560979c3b 100644 --- a/engine/src/main/java/net/jqwik/engine/support/combinatorics/PermutationIterator.java +++ b/engine/src/main/java/net/jqwik/engine/support/combinatorics/PermutationIterator.java @@ -8,7 +8,7 @@ public class PermutationIterator implements Iterator> { private List next; private int[] indices; - public PermutationIterator(List values) { + public PermutationIterator(List values) { this.values.addAll(values); initializeIndices(values); @@ -19,7 +19,7 @@ public PermutationIterator(List values) { } } - private void initializeIndices(List values) { + private void initializeIndices(List values) { this.indices = new int[values.size()]; for (int i = 0; i < indices.length; ++i) { indices[i] = i; diff --git a/engine/src/main/java/net/jqwik/engine/support/combinatorics/SetIterator.java b/engine/src/main/java/net/jqwik/engine/support/combinatorics/SetIterator.java index 7e6c9112d..3779206e4 100644 --- a/engine/src/main/java/net/jqwik/engine/support/combinatorics/SetIterator.java +++ b/engine/src/main/java/net/jqwik/engine/support/combinatorics/SetIterator.java @@ -9,9 +9,9 @@ public class SetIterator implements Iterator> { private final int setSize; private Set next; - public SetIterator(Iterable elementIterable, int setSize) { + public SetIterator(Iterable elementIterable, int setSize) { this.setSize = setSize; - List> iterables = new ArrayList<>(); + List> iterables = new ArrayList<>(); for (int i = 0; i < setSize; i++) { iterables.add(elementIterable); } diff --git a/engine/src/main/java/net/jqwik/engine/support/combinatorics/package-info.java b/engine/src/main/java/net/jqwik/engine/support/combinatorics/package-info.java new file mode 100644 index 000000000..2d14d3084 --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/support/combinatorics/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine.support.combinatorics; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/main/java/net/jqwik/engine/support/package-info.java b/engine/src/main/java/net/jqwik/engine/support/package-info.java new file mode 100644 index 000000000..cebd7e05e --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/support/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine.support; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/main/java/net/jqwik/engine/support/types/package-info.java b/engine/src/main/java/net/jqwik/engine/support/types/package-info.java new file mode 100644 index 000000000..9d8a0060a --- /dev/null +++ b/engine/src/main/java/net/jqwik/engine/support/types/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package net.jqwik.engine.support.types; + +import org.jspecify.annotations.*; \ No newline at end of file diff --git a/engine/src/test/java/net/jqwik/api/ArbitraryTestHelper.java b/engine/src/test/java/net/jqwik/api/ArbitraryTestHelper.java index a081639a2..471f19140 100644 --- a/engine/src/test/java/net/jqwik/api/ArbitraryTestHelper.java +++ b/engine/src/test/java/net/jqwik/api/ArbitraryTestHelper.java @@ -5,9 +5,11 @@ import net.jqwik.engine.*; import net.jqwik.testing.*; +import org.jspecify.annotations.*; + public class ArbitraryTestHelper { - public static void assertAllGenerated(RandomGenerator generator, Consumer assertions) { + public static void assertAllGenerated(RandomGenerator generator, Consumer assertions) { Predicate checker = value -> { try { assertions.accept(value); diff --git a/engine/src/test/java/net/jqwik/api/ArbitraryTests.java b/engine/src/test/java/net/jqwik/api/ArbitraryTests.java index 369a07d35..631b07752 100644 --- a/engine/src/test/java/net/jqwik/api/ArbitraryTests.java +++ b/engine/src/test/java/net/jqwik/api/ArbitraryTests.java @@ -233,7 +233,7 @@ public MyString(String string) { } } - private static int sum(List list) { + private static int sum(List list) { return list.stream().mapToInt(i -> i).sum(); } diff --git a/engine/src/test/java/net/jqwik/api/ListArbitraryTests.java b/engine/src/test/java/net/jqwik/api/ListArbitraryTests.java index 539d25ccf..38c28ea3b 100644 --- a/engine/src/test/java/net/jqwik/api/ListArbitraryTests.java +++ b/engine/src/test/java/net/jqwik/api/ListArbitraryTests.java @@ -279,10 +279,11 @@ private boolean isUniqueModulo(List list, int modulo) { @Example void mapEach(@ForAll Random random) { Arbitrary integerArbitrary = Arbitraries.integers().between(1, 10); + @SuppressWarnings("unchecked") Arbitrary>>> setArbitrary = integerArbitrary .list().ofSize(5) - .mapEach((all, each) -> Tuple.of(each, all)); + .mapEach((all, each) -> Tuple.of(each, (List) all)); RandomGenerator>>> generator = setArbitrary.generator(1, true); diff --git a/engine/src/test/java/net/jqwik/api/SetArbitraryTests.java b/engine/src/test/java/net/jqwik/api/SetArbitraryTests.java index f617d7553..73f601524 100644 --- a/engine/src/test/java/net/jqwik/api/SetArbitraryTests.java +++ b/engine/src/test/java/net/jqwik/api/SetArbitraryTests.java @@ -54,10 +54,11 @@ void setWithLessElementsThanMaxSize(@ForAll Random random) { @Example void mapEach(@ForAll Random random) { Arbitrary integerArbitrary = Arbitraries.integers().between(1, 10); + @SuppressWarnings("unchecked") Arbitrary>>> setArbitrary = integerArbitrary .set().ofSize(5) - .mapEach((all, each) -> Tuple.of(each, all)); + .mapEach((all, each) -> Tuple.of(each, (Set) all)); RandomGenerator>>> generator = setArbitrary.generator(1, true); diff --git a/engine/src/test/java/net/jqwik/api/constraints/UniqueElementsProperties.java b/engine/src/test/java/net/jqwik/api/constraints/UniqueElementsProperties.java index b8e23ee22..7361363de 100644 --- a/engine/src/test/java/net/jqwik/api/constraints/UniqueElementsProperties.java +++ b/engine/src/test/java/net/jqwik/api/constraints/UniqueElementsProperties.java @@ -6,6 +6,8 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + import static java.util.Arrays.*; @PropertyDefaults(tries = 100) @@ -207,7 +209,7 @@ public Object apply(String string) { } } - private boolean hasNoDuplicates(Collection collection, Function by) { + private boolean hasNoDuplicates(Collection collection, Function by) { Set set = collection.stream().map(by).collect(Collectors.toSet()); return set.size() == collection.size(); } diff --git a/engine/src/test/java/net/jqwik/api/domains/ContextIsArbitraryConfigurator.java b/engine/src/test/java/net/jqwik/api/domains/ContextIsArbitraryConfigurator.java index 185b7d581..b4947119e 100644 --- a/engine/src/test/java/net/jqwik/api/domains/ContextIsArbitraryConfigurator.java +++ b/engine/src/test/java/net/jqwik/api/domains/ContextIsArbitraryConfigurator.java @@ -4,11 +4,13 @@ import net.jqwik.api.configurators.*; import net.jqwik.api.providers.*; +import org.jspecify.annotations.*; + class ContextIsArbitraryConfigurator extends DomainContextBase implements ArbitraryConfigurator { @SuppressWarnings("unchecked") @Override - public Arbitrary configure(Arbitrary arbitrary, TypeUsage targetType) { + public Arbitrary configure(Arbitrary arbitrary, TypeUsage targetType) { if (targetType.isOfType(String.class) && targetType.isAnnotated(Doubled.class)) { Arbitrary stringArbitrary = (Arbitrary) arbitrary; return (Arbitrary) stringArbitrary.map(s -> s + s); diff --git a/engine/src/test/java/net/jqwik/engine/properties/shrinking/ArbitraryShrinkingTests.java b/engine/src/test/java/net/jqwik/engine/properties/shrinking/ArbitraryShrinkingTests.java index 2d24ef7c8..d76714572 100644 --- a/engine/src/test/java/net/jqwik/engine/properties/shrinking/ArbitraryShrinkingTests.java +++ b/engine/src/test/java/net/jqwik/engine/properties/shrinking/ArbitraryShrinkingTests.java @@ -78,7 +78,7 @@ void collectedListShrinksElementsAndSize(@ForAll Random random) { assertThat(shrunkValue).containsExactly(3, 3, 3, 3); } - private int sum(List list) { + private int sum(List list) { return list.stream().mapToInt(i -> i).sum(); } diff --git a/engine/src/test/java/net/jqwik/engine/properties/shrinking/CollectShrinkableTests.java b/engine/src/test/java/net/jqwik/engine/properties/shrinking/CollectShrinkableTests.java index bb27cef5d..2c073bd8d 100644 --- a/engine/src/test/java/net/jqwik/engine/properties/shrinking/CollectShrinkableTests.java +++ b/engine/src/test/java/net/jqwik/engine/properties/shrinking/CollectShrinkableTests.java @@ -26,7 +26,7 @@ void creation() { List> shrinkables = asList(shrinkable3, shrinkable2, shrinkable1); - Predicate> untilIsIgnoredHere = l -> true; + Predicate> untilIsIgnoredHere = l -> true; CollectShrinkable shrinkable = new CollectShrinkable<>(shrinkables, untilIsIgnoredHere); assertThat(shrinkable.distance()).isEqualTo(ShrinkingDistance.of(3, 6)); @@ -43,7 +43,7 @@ void shrinkingWithoutSizeReduction() { List> shrinkables = asList(shrinkable4, shrinkable1); - Predicate> untilSizeAtLeast2 = l -> l.size() >= 2; + Predicate> untilSizeAtLeast2 = l -> l.size() >= 2; Shrinkable> shrinkable = new CollectShrinkable<>(shrinkables, untilSizeAtLeast2); List shrunkValue = shrink(shrinkable, alwaysFalsify(), null); @@ -57,7 +57,7 @@ void shrinkingWithFilter() { List> shrinkables = asList(shrinkable4, shrinkable1); - Predicate> untilSizeAtLeast2 = l -> l.size() >= 2; + Predicate> untilSizeAtLeast2 = l -> l.size() >= 2; Shrinkable> shrinkable = new CollectShrinkable<>(shrinkables, untilSizeAtLeast2); Falsifier> falsifier = collection -> { @@ -78,7 +78,7 @@ void shrinkingWithoutSizeReductionButNotAllShrinkingStepsWork() { List> shrinkables = asList(shrinkable4, shrinkable1); - Predicate> untilSizeAtLeast2 = l -> l.size() >= 2; + Predicate> untilSizeAtLeast2 = l -> l.size() >= 2; Shrinkable> shrinkable = new CollectShrinkable<>(shrinkables, untilSizeAtLeast2); TestingFalsifier> sumMustNotBeEven = listOfInts -> { @@ -96,7 +96,7 @@ void shrinkingWithSizeReduction() { List> shrinkables = asList(shrinkable1, shrinkable1, shrinkable1, shrinkable1, shrinkable1, shrinkable1); - Predicate> sumAtLeast6 = l -> { + Predicate> sumAtLeast6 = l -> { int sum = l.stream().mapToInt(i -> i).sum(); return sum >= 6; }; @@ -114,7 +114,7 @@ void shrinkToFullySorted() { List> shrinkables = asList(shrinkable3, shrinkable4, shrinkable2, shrinkable1); - Predicate> sumAtLeast10 = l -> { + Predicate> sumAtLeast10 = l -> { int sum = l.stream().mapToInt(i -> i).sum(); return sum >= 10; }; @@ -132,7 +132,7 @@ void shrinkToPartiallySorted() { List> shrinkables = asList(shrinkable3, shrinkable4, shrinkable2, shrinkable1); - Predicate> sumAtLeast10 = l -> { + Predicate> sumAtLeast10 = l -> { int sum = l.stream().mapToInt(i -> i).sum(); return sum >= 10 && l.get(0) != 1; }; diff --git a/engine/src/test/java/net/jqwik/engine/properties/shrinking/CombinedShrinkableTests.java b/engine/src/test/java/net/jqwik/engine/properties/shrinking/CombinedShrinkableTests.java index 150cbd926..a9575e9cc 100644 --- a/engine/src/test/java/net/jqwik/engine/properties/shrinking/CombinedShrinkableTests.java +++ b/engine/src/test/java/net/jqwik/engine/properties/shrinking/CombinedShrinkableTests.java @@ -22,7 +22,7 @@ class CombinedShrinkableTests { void creation() { Shrinkable three = new OneStepShrinkable(3); Shrinkable hello = Shrinkable.unshrinkable("hello"); - Function, String> combinator = shrinkables -> { + Function, String> combinator = shrinkables -> { int anInt = (int) shrinkables.get(0); String aString = (String) shrinkables.get(1); return aString + anInt; @@ -37,7 +37,7 @@ void creation() { @Example void creationWithEmptyShrinkablesList() { - Function, String> combinator = shrinkables -> { + Function, String> combinator = shrinkables -> { return "constant"; }; @@ -56,7 +56,7 @@ class Shrinking { void shrinkingToBottom() { Shrinkable three = new OneStepShrinkable(3); Shrinkable five = new OneStepShrinkable(5); - Function, Tuple2> combinator = shrinkables -> { + Function, Tuple2> combinator = shrinkables -> { int first = (int) shrinkables.get(0); int second = (int) shrinkables.get(1); return Tuple.of(first, second); @@ -74,7 +74,7 @@ void shrinkingToBottom() { void shrinkToCondition() { Shrinkable three = new OneStepShrinkable(3); Shrinkable five = new OneStepShrinkable(5); - Function, Tuple2> combinator = shrinkables -> { + Function, Tuple2> combinator = shrinkables -> { int first = (int) shrinkables.get(0); int second = (int) shrinkables.get(1); return Tuple.of(first, second); @@ -92,7 +92,7 @@ void shrinkToCondition() { void shrinkingWithFilter() { Shrinkable three = new OneStepShrinkable(3); Shrinkable five = new OneStepShrinkable(5); - Function, Tuple2> combinator = shrinkables -> { + Function, Tuple2> combinator = shrinkables -> { int first = (int) shrinkables.get(0); int second = (int) shrinkables.get(1); return Tuple.of(first, second); diff --git a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/AnyForSubtypeOfDsl.kt b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/AnyForSubtypeOfDsl.kt index c754a58e9..34ca145bf 100644 --- a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/AnyForSubtypeOfDsl.kt +++ b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/AnyForSubtypeOfDsl.kt @@ -17,14 +17,14 @@ val KClass.allSealedSubclasses: List> } @API(status = API.Status.EXPERIMENTAL, since = "1.8.4") -class SubtypeScope { +class SubtypeScope { val customProviders = mutableListOf>() /** * Registers a custom provider for subtype [U], instead of default one created by [anyForSubtypeOf]. */ inline fun provide(noinline customProvider: () -> Arbitrary) where U : T { - customProviders.add(CustomProvider(U::class as KClass, customProvider) as CustomProvider) + customProviders.add(CustomProvider(U::class, customProvider)) } /** @@ -33,8 +33,8 @@ class SubtypeScope { fun getProviderFor(targetType: KClass<*>) = customProviders.firstOrNull { it.targetType == targetType }?.arbitraryFactory?.invoke() - class CustomProvider( - val targetType: KClass, - val arbitraryFactory: () -> Arbitrary + class CustomProvider( + val targetType: KClass, + val arbitraryFactory: () -> Arbitrary ) } \ No newline at end of file diff --git a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/ArbitraryExtensions.kt b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/ArbitraryExtensions.kt index 39d268385..260fe7031 100644 --- a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/ArbitraryExtensions.kt +++ b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/ArbitraryExtensions.kt @@ -58,5 +58,5 @@ fun Arbitrary.triple(): Arbitrary> { */ @API(status = API.Status.EXPERIMENTAL, since = "1.6.0") inline fun Arbitrary.array(): ArrayArbitrary { - return array(A::class.java) as ArrayArbitrary + return array(A::class.java) } diff --git a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/BuildersExtensions.kt b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/BuildersExtensions.kt index b8a2771a8..97cdfc055 100644 --- a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/BuildersExtensions.kt +++ b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/BuildersExtensions.kt @@ -9,7 +9,7 @@ import java.util.function.BiFunction * Convenience function for Kotlin to not use backticked `in` function. */ @API(status = API.Status.EXPERIMENTAL, since = "1.6.0") -fun BuilderCombinator.use(arbitrary: Arbitrary, combinator: (B, T) -> B): BuilderCombinator +fun BuilderCombinator.use(arbitrary: Arbitrary, combinator: (B, T) -> B): BuilderCombinator where B : Any { val toFunction = BiFunction { b, t -> combinator(b, t) } return this.use(arbitrary).`in`(toFunction) diff --git a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/CollectionExtensions.kt b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/CollectionExtensions.kt index eebb91e20..6e15b8d50 100644 --- a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/CollectionExtensions.kt +++ b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/CollectionExtensions.kt @@ -9,10 +9,10 @@ import org.apiguardian.api.API * Convenience function to replace Arbitraries.subsetOf(..) */ @API(status = API.Status.EXPERIMENTAL, since = "1.6.5") -fun Collection.anySubset(): SetArbitrary = Arbitraries.subsetOf(this) as SetArbitrary +fun Collection.anySubset(): SetArbitrary = Arbitraries.subsetOf(this) /** * Convenience function to replace Arbitraries.of(..) */ @API(status = API.Status.EXPERIMENTAL, since = "1.7.1") -fun Collection.anyValue(): Arbitrary = Arbitraries.of(this) as Arbitrary +fun Collection.anyValue(): Arbitrary = Arbitraries.of(this) diff --git a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/JqwikGlobals.kt b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/JqwikGlobals.kt index a375f2ad0..d0b88ae99 100644 --- a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/JqwikGlobals.kt +++ b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/JqwikGlobals.kt @@ -41,8 +41,7 @@ fun anyFunction(kClass: KClass<*>): Functions.FunctionWrapper { * Create a [FunctionArbitrary] for Kotlin function without parameters. */ @API(status = API.Status.EXPERIMENTAL, since = "1.6.0") -fun anyFunction0(returning: Arbitrary): FunctionArbitrary, R> - where R : Any { +fun anyFunction0(returning: Arbitrary): FunctionArbitrary, R> { return anyFunction(Function0::class).returning(returning) } @@ -50,8 +49,7 @@ fun anyFunction0(returning: Arbitrary): FunctionArbitrary, R * Create a [FunctionArbitrary] for Kotlin function with 1 parameter. */ @API(status = API.Status.EXPERIMENTAL, since = "1.6.0") -fun anyFunction1(returning: Arbitrary): FunctionArbitrary, R> - where R : Any { +fun anyFunction1(returning: Arbitrary): FunctionArbitrary, R> { return anyFunction(Function1::class).returning(returning) } @@ -59,8 +57,7 @@ fun anyFunction1(returning: Arbitrary): FunctionArbitrary anyFunction2(returning: Arbitrary): FunctionArbitrary, R> - where R : Any { +fun anyFunction2(returning: Arbitrary): FunctionArbitrary, R> { return anyFunction(Function2::class).returning(returning) } @@ -68,8 +65,7 @@ fun anyFunction2(returning: Arbitrary): FunctionArbitrary anyFunction3(returning: Arbitrary): FunctionArbitrary, R> - where R : Any { +fun anyFunction3(returning: Arbitrary): FunctionArbitrary, R> { return anyFunction(Function3::class).returning(returning) } @@ -77,8 +73,7 @@ fun anyFunction3(returning: Arbitrary): FunctionArbitrary anyFunction4(returning: Arbitrary): FunctionArbitrary, R> - where R : Any { +fun anyFunction4(returning: Arbitrary): FunctionArbitrary, R> { return anyFunction(Function4::class).returning(returning) } @@ -127,14 +122,14 @@ inline fun anyForSubtypeOf( val scope = SubtypeScope().apply(subtypeScope) return Arbitraries.of(T::class.allSealedSubclasses).flatMap { scope.getProviderFor(it) - ?: Arbitraries.forType(it.java as Class).run { + ?: Arbitraries.forType(it.java).run { if (enableArbitraryRecursion) { enableRecursion() } else { this } } - }.map { obj -> obj as T } + }.map { obj -> obj } } /** diff --git a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/SequenceArbitrary.kt b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/SequenceArbitrary.kt index 1b75d2170..31d1abe87 100644 --- a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/SequenceArbitrary.kt +++ b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/SequenceArbitrary.kt @@ -15,7 +15,7 @@ import java.util.function.Function * of type [Sequence] */ @API(status = EXPERIMENTAL, since = "1.6.0") -class SequenceArbitrary(elementArbitrary: Arbitrary) : ArbitraryDecorator>(), +class SequenceArbitrary(elementArbitrary: Arbitrary) : ArbitraryDecorator>(), SizableArbitrary> { private var listArbitrary: ListArbitrary diff --git a/kotlin/src/main/kotlin/net/jqwik/kotlin/internal/KotlinUniqueElementsConfigurator.kt b/kotlin/src/main/kotlin/net/jqwik/kotlin/internal/KotlinUniqueElementsConfigurator.kt index 7dff246ec..91295f9c9 100644 --- a/kotlin/src/main/kotlin/net/jqwik/kotlin/internal/KotlinUniqueElementsConfigurator.kt +++ b/kotlin/src/main/kotlin/net/jqwik/kotlin/internal/KotlinUniqueElementsConfigurator.kt @@ -12,7 +12,7 @@ import java.util.function.Function class KotlinUniqueElementsConfigurator : ArbitraryConfigurator { @Suppress("UNCHECKED_CAST") - override fun configure(arbitrary: Arbitrary, targetType: TypeUsage): Arbitrary { + override fun configure(arbitrary: Arbitrary, targetType: TypeUsage): Arbitrary { return targetType.findAnnotation(UniqueElements::class.java).map { uniqueness -> return@map when { arbitrary is SequenceArbitrary<*> -> configureSequenceArbitrary(arbitrary, uniqueness) diff --git a/testing/src/main/java/net/jqwik/testing/CheckReporting.java b/testing/src/main/java/net/jqwik/testing/CheckReporting.java index 9aae434b8..66a8908f4 100644 --- a/testing/src/main/java/net/jqwik/testing/CheckReporting.java +++ b/testing/src/main/java/net/jqwik/testing/CheckReporting.java @@ -25,5 +25,5 @@ public PropertyExecutionResult aroundProperty(PropertyLifecycleContext context, return result; } - public abstract void check(@NonNull Reporter mockReporter); + public abstract void check(Reporter mockReporter); } diff --git a/testing/src/main/java/net/jqwik/testing/ShrinkingSupport.java b/testing/src/main/java/net/jqwik/testing/ShrinkingSupport.java index 3ae3b2424..6a4d2d3bc 100644 --- a/testing/src/main/java/net/jqwik/testing/ShrinkingSupport.java +++ b/testing/src/main/java/net/jqwik/testing/ShrinkingSupport.java @@ -11,6 +11,8 @@ import net.jqwik.api.facades.*; import net.jqwik.api.lifecycle.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; import static org.assertj.core.api.Assertions.*; @@ -20,35 +22,35 @@ public class ShrinkingSupport { private ShrinkingSupport() { } - public static T falsifyThenShrink(Arbitrary arbitrary, Random random) { + public static T falsifyThenShrink(Arbitrary arbitrary, Random random) { return falsifyThenShrink(arbitrary, random, ignore -> TryExecutionResult.falsified(null)); } - public static T falsifyThenShrink(Arbitrary arbitrary, Random random, Falsifier falsifier) { + public static T falsifyThenShrink(Arbitrary arbitrary, Random random, Falsifier falsifier) { return ShrinkingSupportFacade.implementation.falsifyThenShrink(arbitrary, random, falsifier); } - public static T falsifyThenShrink(RandomGenerator generator, Random random, Falsifier falsifier) { + public static T falsifyThenShrink(RandomGenerator generator, Random random, Falsifier falsifier) { return ShrinkingSupportFacade.implementation.falsifyThenShrink(generator, random, falsifier); } - public static T shrink( + public static T shrink( Shrinkable falsifiedShrinkable, - Falsifier falsifier, + Falsifier falsifier, Throwable originalError ) { return ShrinkingSupportFacade.implementation.shrink(falsifiedShrinkable, falsifier, originalError); } - public static ShrunkFalsifiedSample shrinkToSample( + public static ShrunkFalsifiedSample shrinkToSample( Shrinkable falsifiedShrinkable, - Falsifier falsifier, + Falsifier falsifier, Throwable originalError ) { return ShrinkingSupportFacade.implementation.shrinkToSample(falsifiedShrinkable, falsifier, originalError); } - public static void assertWhileShrinking(Shrinkable shrinkable, Predicate condition) { + public static void assertWhileShrinking(Shrinkable shrinkable, Predicate condition) { while(true) { List> collect = shrinkable.shrink().collect(Collectors.toList()); assertThat(collect).allMatch(s -> condition.test(s.value())); @@ -59,7 +61,7 @@ public static void assertWhileShrinking(Shrinkable shrinkable, Predicate< } } - public static void assertAllValuesAreShrunkTo(Arbitrary arbitrary, Random random, T expectedShrunkValue) { + public static void assertAllValuesAreShrunkTo(Arbitrary arbitrary, Random random, T expectedShrunkValue) { T value = falsifyThenShrink(arbitrary, random); Assertions.assertThat(value).isEqualTo(expectedShrunkValue); } diff --git a/testing/src/main/java/net/jqwik/testing/TestingFalsifier.java b/testing/src/main/java/net/jqwik/testing/TestingFalsifier.java index c9151eae9..3bebdda1a 100644 --- a/testing/src/main/java/net/jqwik/testing/TestingFalsifier.java +++ b/testing/src/main/java/net/jqwik/testing/TestingFalsifier.java @@ -3,6 +3,7 @@ import java.util.function.*; import org.apiguardian.api.*; +import org.jspecify.annotations.*; import org.opentest4j.*; import net.jqwik.api.*; @@ -11,13 +12,13 @@ import static org.apiguardian.api.API.Status.*; @API(status = EXPERIMENTAL, since = "1.4.0") -public interface TestingFalsifier extends Falsifier, Predicate { +public interface TestingFalsifier extends Falsifier, Predicate { - static TestingFalsifier alwaysFalsify() { + static TestingFalsifier alwaysFalsify() { return ignore -> false; } - static TestingFalsifier falsifier(Predicate predicate) { + static TestingFalsifier falsifier(Predicate predicate) { return predicate::test; } diff --git a/testing/src/main/java/net/jqwik/testing/TestingSupport.java b/testing/src/main/java/net/jqwik/testing/TestingSupport.java index 8cee2e708..467ce90a4 100644 --- a/testing/src/main/java/net/jqwik/testing/TestingSupport.java +++ b/testing/src/main/java/net/jqwik/testing/TestingSupport.java @@ -10,6 +10,8 @@ import net.jqwik.api.*; import net.jqwik.api.facades.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; import static org.assertj.core.api.Assertions.*; @@ -19,12 +21,12 @@ public class TestingSupport { private TestingSupport() { } - public static void checkAllGenerated(Arbitrary arbitrary, Random random, Predicate checker) { + public static void checkAllGenerated(Arbitrary arbitrary, Random random, Predicate checker) { checkAllGenerated(arbitrary.generator(1000), random, checker); } - public static void checkAllGenerated(RandomGenerator generator, Random random, Predicate checker) { - Optional> failure = + public static void checkAllGenerated(RandomGenerator generator, Random random, Predicate checker) { + Optional> failure = generator .stream(random) .limit(100) @@ -36,11 +38,11 @@ public static void checkAllGenerated(RandomGenerator generator, }); } - public static void assertAllGenerated(Arbitrary arbitrary, Random random, Consumer assertions) { + public static void assertAllGenerated(Arbitrary arbitrary, Random random, Consumer assertions) { assertAllGenerated(arbitrary.generator(1000), random, assertions); } - public static void assertAllGenerated(RandomGenerator generator, Random random, Consumer assertions) { + public static void assertAllGenerated(RandomGenerator generator, Random random, Consumer assertions) { Predicate checker = value -> { assertions.accept(value); return true; @@ -48,7 +50,7 @@ public static void assertAllGenerated(RandomGenerator generator checkAllGenerated(generator, random, checker); } - public static void assertAllGeneratedEqualTo(RandomGenerator generator, Random random, T expected) { + public static void assertAllGeneratedEqualTo(RandomGenerator generator, Random random, T expected) { assertAllGenerated( generator, random, @@ -56,7 +58,7 @@ public static void assertAllGeneratedEqualTo(RandomGenerator ge ); } - public static void assertAllGeneratedEqualTo(Arbitrary arbitrary, Random random, T expected) { + public static void assertAllGeneratedEqualTo(Arbitrary arbitrary, Random random, T expected) { assertAllGeneratedEqualTo( arbitrary.generator(1000), random, @@ -64,13 +66,13 @@ public static void assertAllGeneratedEqualTo(Arbitrary arbitrar ); } - public static void checkAtLeastOneGenerated( - RandomGenerator generator, + public static void checkAtLeastOneGenerated( + RandomGenerator generator, Random random, - Predicate checker, + Predicate checker, String failureMessage ) { - Optional> success = + Optional> success = generator .stream(random) .limit(5000) @@ -81,15 +83,15 @@ public static void checkAtLeastOneGenerated( } } - public static void checkAtLeastOneGenerated( - RandomGenerator generator, + public static void checkAtLeastOneGenerated( + RandomGenerator generator, Random random, - Predicate checker + Predicate checker ) { checkAtLeastOneGenerated(generator, random, checker, "Failed to generate at least one"); } - public static void checkAtLeastOneGenerated( + public static void checkAtLeastOneGenerated( Arbitrary arbitrary, Random random, Predicate checker @@ -98,18 +100,18 @@ public static void checkAtLeastOneGenerated( } @SafeVarargs - public static void assertAtLeastOneGeneratedOf( + public static void assertAtLeastOneGeneratedOf( RandomGenerator generator, Random random, T... values ) { for (T value : values) { - checkAtLeastOneGenerated(generator, random, value::equals, "Failed to generate " + value); + checkAtLeastOneGenerated(generator, random, x -> Objects.equals(x, value), "Failed to generate " + value); } } @SafeVarargs - public static void assertGeneratedExactly(RandomGenerator generator, Random random, T... expectedValues) { + public static void assertGeneratedExactly(RandomGenerator generator, Random random, T... expectedValues) { List generated = generator .stream(random) .limit(expectedValues.length) @@ -119,7 +121,7 @@ public static void assertGeneratedExactly(RandomGenerator gener assertThat(generated).containsExactly(expectedValues); } - public static Set> collectEdgeCaseShrinkables(EdgeCases edgeCases) { + public static Set> collectEdgeCaseShrinkables(EdgeCases edgeCases) { Set> shrinkables = new HashSet<>(); for (Shrinkable edgeCase : edgeCases) { shrinkables.add(edgeCase); @@ -127,7 +129,7 @@ public static Set> collectEdgeCaseShrinkables(EdgeCases edg return shrinkables; } - public static Set collectEdgeCaseValues(EdgeCases edgeCases) { + public static Set collectEdgeCaseValues(EdgeCases edgeCases) { Set values = new HashSet<>(); for (Shrinkable edgeCase : edgeCases) { values.add(edgeCase.value()); @@ -135,12 +137,12 @@ public static Set collectEdgeCaseValues(EdgeCases edgeCases) { return values; } - public static T generateFirst(Arbitrary arbitrary, Random random) { + public static T generateFirst(Arbitrary arbitrary, Random random) { RandomGenerator generator = arbitrary.generator(1, true); return generator.next(random).value(); } - public static Map count(RandomGenerator generator, int tries, Random random) { + public static Map count(RandomGenerator generator, int tries, Random random) { return generator .stream(random) .limit(tries) @@ -148,7 +150,7 @@ public static Map count(RandomGenerator generator, int tries, Ra .collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); } - public static Shrinkable generateUntil(RandomGenerator generator, Random random, Function condition) { + public static Shrinkable generateUntil(RandomGenerator generator, Random random, Function condition) { return TestingSupportFacade.implementation.generateUntil(generator, random, condition); } From f9e59ebf69202e5c4c7d3c2884fb36846002feea Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Fri, 7 Jun 2024 15:23:49 +0300 Subject: [PATCH 3/5] style: remove excessive variable in BuilderCombinator.use --- .../src/main/kotlin/net/jqwik/kotlin/api/BuildersExtensions.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/BuildersExtensions.kt b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/BuildersExtensions.kt index 97cdfc055..a06674d57 100644 --- a/kotlin/src/main/kotlin/net/jqwik/kotlin/api/BuildersExtensions.kt +++ b/kotlin/src/main/kotlin/net/jqwik/kotlin/api/BuildersExtensions.kt @@ -11,6 +11,5 @@ import java.util.function.BiFunction @API(status = API.Status.EXPERIMENTAL, since = "1.6.0") fun BuilderCombinator.use(arbitrary: Arbitrary, combinator: (B, T) -> B): BuilderCombinator where B : Any { - val toFunction = BiFunction { b, t -> combinator(b, t) } - return this.use(arbitrary).`in`(toFunction) + return this.use(arbitrary).`in`(combinator) } From abe7b1e99f6656eb26cdeea864f90f03867e4313 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Fri, 7 Jun 2024 15:30:09 +0300 Subject: [PATCH 4/5] WIP: fix for javac8 --- .../shrinking/CombinedShrinkableTests.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/engine/src/test/java/net/jqwik/engine/properties/shrinking/CombinedShrinkableTests.java b/engine/src/test/java/net/jqwik/engine/properties/shrinking/CombinedShrinkableTests.java index a9575e9cc..acde0eab7 100644 --- a/engine/src/test/java/net/jqwik/engine/properties/shrinking/CombinedShrinkableTests.java +++ b/engine/src/test/java/net/jqwik/engine/properties/shrinking/CombinedShrinkableTests.java @@ -23,7 +23,7 @@ void creation() { Shrinkable three = new OneStepShrinkable(3); Shrinkable hello = Shrinkable.unshrinkable("hello"); Function, String> combinator = shrinkables -> { - int anInt = (int) shrinkables.get(0); + int anInt = (Integer) shrinkables.get(0); String aString = (String) shrinkables.get(1); return aString + anInt; }; @@ -57,8 +57,8 @@ void shrinkingToBottom() { Shrinkable three = new OneStepShrinkable(3); Shrinkable five = new OneStepShrinkable(5); Function, Tuple2> combinator = shrinkables -> { - int first = (int) shrinkables.get(0); - int second = (int) shrinkables.get(1); + int first = (Integer) shrinkables.get(0); + int second = (Integer) shrinkables.get(1); return Tuple.of(first, second); }; @@ -75,8 +75,8 @@ void shrinkToCondition() { Shrinkable three = new OneStepShrinkable(3); Shrinkable five = new OneStepShrinkable(5); Function, Tuple2> combinator = shrinkables -> { - int first = (int) shrinkables.get(0); - int second = (int) shrinkables.get(1); + int first = (Integer) shrinkables.get(0); + int second = (Integer) shrinkables.get(1); return Tuple.of(first, second); }; @@ -93,8 +93,8 @@ void shrinkingWithFilter() { Shrinkable three = new OneStepShrinkable(3); Shrinkable five = new OneStepShrinkable(5); Function, Tuple2> combinator = shrinkables -> { - int first = (int) shrinkables.get(0); - int second = (int) shrinkables.get(1); + int first = (Integer) shrinkables.get(0); + int second = (Integer) shrinkables.get(1); return Tuple.of(first, second); }; From 389a32858aa6aaec60ef29fa6a87bfda736acb2a Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Fri, 7 Jun 2024 16:30:25 +0300 Subject: [PATCH 5/5] fix: add extends @Nullable Object to class/interface declarations --- api/src/main/java/net/jqwik/api/ArbitrarySupplier.java | 2 +- api/src/main/java/net/jqwik/api/EdgeCases.java | 2 +- .../java/net/jqwik/api/arbitraries/TypeArbitrary.java | 2 +- .../java/net/jqwik/api/state/ActionChainArbitrary.java | 4 +++- .../main/java/net/jqwik/api/state/ChainArbitrary.java | 4 +++- .../main/java/net/jqwik/api/state/Transformation.java | 2 +- api/src/main/java/net/jqwik/api/state/Transformer.java | 2 +- .../main/java/net/jqwik/engine/ArbitraryDelegator.java | 4 +++- .../jqwik/engine/execution/lifecycle/ScopedStore.java | 3 ++- .../properties/arbitraries/ArbitraryCollect.java | 4 +++- .../engine/properties/arbitraries/ArbitraryFilter.java | 4 +++- .../properties/arbitraries/ChooseValueArbitrary.java | 4 +++- .../arbitraries/DefaultIteratorArbitrary.java | 4 +++- .../properties/arbitraries/DefaultSetArbitrary.java | 4 +++- .../properties/arbitraries/DefaultStreamArbitrary.java | 4 +++- .../arbitraries/DefaultTraverseArbitrary.java | 5 +++-- .../properties/arbitraries/DefaultTypeArbitrary.java | 3 ++- .../arbitraries/FromGeneratorWithSizeArbitrary.java | 4 +++- .../arbitraries/GenericEdgeCasesConfiguration.java | 4 +++- .../engine/properties/arbitraries/JustArbitrary.java | 2 +- .../engine/properties/arbitraries/LazyArbitrary.java | 6 ++++-- .../engine/properties/arbitraries/LazyOfArbitrary.java | 2 +- .../engine/properties/arbitraries/OneOfArbitrary.java | 4 +++- .../properties/arbitraries/RecursiveArbitrary.java | 4 +++- .../properties/arbitraries/ReportableStream.java | 2 +- .../properties/arbitraries/ShuffleArbitrary.java | 4 +++- .../arbitraries/combinations/CombineArbitrary.java | 4 +++- .../combinations/DefaultListCombinator.java | 4 ++-- .../exhaustive/CombinedExhaustiveGenerator.java | 4 +++- .../arbitraries/exhaustive/ExhaustiveGenerators.java | 2 +- .../exhaustive/FilteredExhaustiveGenerator.java | 4 +++- .../arbitraries/randomized/CollectGenerator.java | 4 +++- .../arbitraries/randomized/FilteredGenerator.java | 4 +++- .../arbitraries/randomized/FrequencyGenerator.java | 4 +++- .../randomized/IgnoreExceptionGenerator.java | 4 +++- .../randomized/InjectDuplicatesGenerator.java | 4 +++- .../arbitraries/randomized/WithEdgeCasesGenerator.java | 2 +- .../properties/shrinking/AbstractValueShrinkable.java | 10 +++++++--- .../properties/shrinking/ChooseValueShrinkable.java | 4 +++- .../engine/properties/shrinking/CollectShrinkable.java | 4 +++- .../properties/shrinking/CombinedShrinkable.java | 4 +++- .../properties/shrinking/FilteredShrinkable.java | 4 +++- .../shrinking/IgnoreExceptionShrinkable.java | 4 +++- .../engine/properties/shrinking/LazyOfShrinkable.java | 4 +++- .../engine/properties/shrinking/SampleShrinkable.java | 4 +++- .../engine/properties/shrinking/ShrinkableList.java | 4 +++- .../engine/properties/shrinking/ShrinkableSet.java | 2 +- .../engine/properties/shrinking/Unshrinkable.java | 4 +++- .../properties/state/DefaultActionChainArbitrary.java | 3 ++- .../engine/properties/state/DefaultChainArbitrary.java | 4 +++- .../jqwik/engine/properties/state/ShrinkableChain.java | 6 +++--- .../properties/stateful/ActionSequenceGenerator.java | 4 +++- .../stateful/DefaultActionSequenceArbitrary.java | 4 +++- .../properties/stateful/SequentialActionSequence.java | 5 +++-- .../properties/stateful/ShrinkableActionSequence.java | 6 ++++-- .../engine/support/ChooseRandomlyByFrequency.java | 4 +++- .../engine/support/combinatorics/CombinedIterator.java | 4 +++- .../engine/support/combinatorics/ConcatIterator.java | 8 +++++--- .../support/combinatorics/PermutationIterator.java | 8 +++++--- .../engine/support/combinatorics/SetIterator.java | 4 +++- 60 files changed, 164 insertions(+), 73 deletions(-) diff --git a/api/src/main/java/net/jqwik/api/ArbitrarySupplier.java b/api/src/main/java/net/jqwik/api/ArbitrarySupplier.java index 7a604414c..bb48ac91c 100644 --- a/api/src/main/java/net/jqwik/api/ArbitrarySupplier.java +++ b/api/src/main/java/net/jqwik/api/ArbitrarySupplier.java @@ -24,7 +24,7 @@ * @see From */ @API(status = MAINTAINED, since = "1.7.0") -public interface ArbitrarySupplier extends Supplier> { +public interface ArbitrarySupplier extends Supplier> { /** * Override this method if you need more information about the target type, diff --git a/api/src/main/java/net/jqwik/api/EdgeCases.java b/api/src/main/java/net/jqwik/api/EdgeCases.java index fab4c9a3f..592ecefd4 100644 --- a/api/src/main/java/net/jqwik/api/EdgeCases.java +++ b/api/src/main/java/net/jqwik/api/EdgeCases.java @@ -9,7 +9,7 @@ import static org.apiguardian.api.API.Status.*; @API(status = EXPERIMENTAL, since = "1.3.0") -public interface EdgeCases extends Iterable> { +public interface EdgeCases extends Iterable> { @API(status = INTERNAL) abstract class EdgeCasesFacade { diff --git a/api/src/main/java/net/jqwik/api/arbitraries/TypeArbitrary.java b/api/src/main/java/net/jqwik/api/arbitraries/TypeArbitrary.java index 57dcf14fa..0f74373ba 100644 --- a/api/src/main/java/net/jqwik/api/arbitraries/TypeArbitrary.java +++ b/api/src/main/java/net/jqwik/api/arbitraries/TypeArbitrary.java @@ -26,7 +26,7 @@ * @see net.jqwik.api.domains.DomainContext */ @API(status = MAINTAINED, since = "1.2") -public interface TypeArbitrary extends Arbitrary { +public interface TypeArbitrary extends Arbitrary { /** * Add public constructors of class {@code T} to be used diff --git a/api/src/main/java/net/jqwik/api/state/ActionChainArbitrary.java b/api/src/main/java/net/jqwik/api/state/ActionChainArbitrary.java index 336288452..e0b3e8e92 100644 --- a/api/src/main/java/net/jqwik/api/state/ActionChainArbitrary.java +++ b/api/src/main/java/net/jqwik/api/state/ActionChainArbitrary.java @@ -6,10 +6,12 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; @API(status = EXPERIMENTAL, since = "1.7.0") -public interface ActionChainArbitrary extends Arbitrary> { +public interface ActionChainArbitrary extends Arbitrary> { /** * Allow an additional action with default weight of 1. diff --git a/api/src/main/java/net/jqwik/api/state/ChainArbitrary.java b/api/src/main/java/net/jqwik/api/state/ChainArbitrary.java index 12d24ca2f..7fc39b28a 100644 --- a/api/src/main/java/net/jqwik/api/state/ChainArbitrary.java +++ b/api/src/main/java/net/jqwik/api/state/ChainArbitrary.java @@ -6,10 +6,12 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + import static org.apiguardian.api.API.Status.*; @API(status = EXPERIMENTAL, since = "1.7.0") -public interface ChainArbitrary extends Arbitrary> { +public interface ChainArbitrary extends Arbitrary> { /** * Allow an additional {@linkplain Transformation} on the generated chain. diff --git a/api/src/main/java/net/jqwik/api/state/Transformation.java b/api/src/main/java/net/jqwik/api/state/Transformation.java index d0efbd2db..b242d055b 100644 --- a/api/src/main/java/net/jqwik/api/state/Transformation.java +++ b/api/src/main/java/net/jqwik/api/state/Transformation.java @@ -24,7 +24,7 @@ */ @FunctionalInterface @API(status = EXPERIMENTAL, since = "1.7.0") -public interface Transformation extends Function, Arbitrary>> { +public interface Transformation extends Function, Arbitrary>> { Predicate NO_PRECONDITION = ignore -> false; diff --git a/api/src/main/java/net/jqwik/api/state/Transformer.java b/api/src/main/java/net/jqwik/api/state/Transformer.java index 05f6de95e..28090b49a 100644 --- a/api/src/main/java/net/jqwik/api/state/Transformer.java +++ b/api/src/main/java/net/jqwik/api/state/Transformer.java @@ -117,7 +117,7 @@ static Transformer noop() { * @param The type of the state to transform * @return a new instance of a transformer */ - static Transformer transform(String description, Function transform) { + static Transformer transform(String description, Function transform) { return new Transformer() { @Override public S apply(S s) { diff --git a/engine/src/main/java/net/jqwik/engine/ArbitraryDelegator.java b/engine/src/main/java/net/jqwik/engine/ArbitraryDelegator.java index 8f8e0c23b..4cbded6bf 100644 --- a/engine/src/main/java/net/jqwik/engine/ArbitraryDelegator.java +++ b/engine/src/main/java/net/jqwik/engine/ArbitraryDelegator.java @@ -3,7 +3,9 @@ import net.jqwik.api.*; import net.jqwik.api.arbitraries.*; -public class ArbitraryDelegator extends ArbitraryDecorator { +import org.jspecify.annotations.*; + +public class ArbitraryDelegator extends ArbitraryDecorator { private final Arbitrary delegate; diff --git a/engine/src/main/java/net/jqwik/engine/execution/lifecycle/ScopedStore.java b/engine/src/main/java/net/jqwik/engine/execution/lifecycle/ScopedStore.java index aeeb5e9a3..1d2c6e286 100644 --- a/engine/src/main/java/net/jqwik/engine/execution/lifecycle/ScopedStore.java +++ b/engine/src/main/java/net/jqwik/engine/execution/lifecycle/ScopedStore.java @@ -3,6 +3,7 @@ import java.util.function.*; import java.util.logging.*; +import org.jspecify.annotations.*; import org.junit.platform.engine.*; import net.jqwik.api.lifecycle.*; @@ -10,7 +11,7 @@ import static net.jqwik.engine.support.JqwikStringSupport.*; -public class ScopedStore implements Store { +public class ScopedStore implements Store { private static final Logger LOG = Logger.getLogger(ScopedStore.class.getName()); diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ArbitraryCollect.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ArbitraryCollect.java index 517c47a74..503aeb753 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ArbitraryCollect.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ArbitraryCollect.java @@ -6,7 +6,9 @@ import net.jqwik.api.*; import net.jqwik.api.support.*; -public class ArbitraryCollect implements Arbitrary> { +import org.jspecify.annotations.*; + +public class ArbitraryCollect implements Arbitrary> { private final Arbitrary elementArbitrary; private final Predicate> until; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ArbitraryFilter.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ArbitraryFilter.java index 4128cbf96..ad9566364 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ArbitraryFilter.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ArbitraryFilter.java @@ -7,7 +7,9 @@ import net.jqwik.api.support.*; import net.jqwik.engine.*; -public class ArbitraryFilter extends ArbitraryDelegator { +import org.jspecify.annotations.*; + +public class ArbitraryFilter extends ArbitraryDelegator { private final Predicate filterPredicate; private final int maxMisses; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ChooseValueArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ChooseValueArbitrary.java index 93cf0cf18..5a739a51d 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ChooseValueArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ChooseValueArbitrary.java @@ -5,7 +5,9 @@ import net.jqwik.engine.properties.arbitraries.exhaustive.*; import net.jqwik.engine.properties.arbitraries.randomized.*; -public class ChooseValueArbitrary extends UseGeneratorsArbitrary { +import org.jspecify.annotations.*; + +public class ChooseValueArbitrary extends UseGeneratorsArbitrary { private final int hashCode; private final List values; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultIteratorArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultIteratorArbitrary.java index cd14bc789..2a845a9c8 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultIteratorArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultIteratorArbitrary.java @@ -9,7 +9,9 @@ import net.jqwik.engine.properties.arbitraries.exhaustive.*; import net.jqwik.engine.properties.shrinking.*; -public class DefaultIteratorArbitrary extends MultivalueArbitraryBase> implements IteratorArbitrary { +import org.jspecify.annotations.*; + +public class DefaultIteratorArbitrary extends MultivalueArbitraryBase> implements IteratorArbitrary { public DefaultIteratorArbitrary(Arbitrary elementArbitrary) { super(elementArbitrary); diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultSetArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultSetArbitrary.java index b9138641f..f234b942f 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultSetArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultSetArbitrary.java @@ -12,7 +12,9 @@ import net.jqwik.engine.properties.arbitraries.randomized.*; import net.jqwik.engine.properties.shrinking.*; -public class DefaultSetArbitrary extends MultivalueArbitraryBase> implements SetArbitrary { +import org.jspecify.annotations.*; + +public class DefaultSetArbitrary extends MultivalueArbitraryBase> implements SetArbitrary { public DefaultSetArbitrary(Arbitrary elementArbitrary) { super(elementArbitrary); diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultStreamArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultStreamArbitrary.java index c706cdb5a..01aafc56c 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultStreamArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultStreamArbitrary.java @@ -10,7 +10,9 @@ import net.jqwik.engine.properties.arbitraries.exhaustive.*; import net.jqwik.engine.properties.shrinking.*; -public class DefaultStreamArbitrary extends MultivalueArbitraryBase> implements StreamArbitrary { +import org.jspecify.annotations.*; + +public class DefaultStreamArbitrary extends MultivalueArbitraryBase> implements StreamArbitrary { public DefaultStreamArbitrary(Arbitrary elementArbitrary) { super(elementArbitrary); diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultTraverseArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultTraverseArbitrary.java index 28b27ff8a..2ff0bd21f 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultTraverseArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultTraverseArbitrary.java @@ -5,6 +5,7 @@ import java.util.function.*; import java.util.stream.*; +import org.jspecify.annotations.*; import org.junit.platform.commons.support.*; import net.jqwik.api.*; @@ -17,7 +18,7 @@ import static net.jqwik.engine.support.JqwikReflectionSupport.*; -public class DefaultTraverseArbitrary extends ArbitraryDecorator implements TraverseArbitrary { +public class DefaultTraverseArbitrary extends ArbitraryDecorator implements TraverseArbitrary { private final Class targetType; private final Traverser traverser; @@ -189,7 +190,7 @@ private T generateNext(Object[] params, Combinator combinator) { @FunctionalInterface private interface Combinator { - Object combine(Object[] params) throws Throwable; + @Nullable Object combine(Object[] params) throws Throwable; } private static class GenerationError extends RuntimeException { diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultTypeArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultTypeArbitrary.java index 490966a8d..31c93e529 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultTypeArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/DefaultTypeArbitrary.java @@ -4,6 +4,7 @@ import java.util.*; import java.util.function.*; +import org.jspecify.annotations.*; import org.junit.platform.commons.support.*; import net.jqwik.api.*; @@ -12,7 +13,7 @@ import static org.junit.platform.commons.support.ModifierSupport.*; -public class DefaultTypeArbitrary extends ArbitraryDecorator implements TypeArbitrary { +public class DefaultTypeArbitrary extends ArbitraryDecorator implements TypeArbitrary { private final Class targetType; private final Set explicitCreators = new LinkedHashSet<>(); diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FromGeneratorWithSizeArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FromGeneratorWithSizeArbitrary.java index 38971e03b..300fa980e 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FromGeneratorWithSizeArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/FromGeneratorWithSizeArbitrary.java @@ -5,7 +5,9 @@ import net.jqwik.api.*; import net.jqwik.api.support.*; -public class FromGeneratorWithSizeArbitrary implements Arbitrary { +import org.jspecify.annotations.*; + +public class FromGeneratorWithSizeArbitrary implements Arbitrary { private final IntFunction> supplier; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/GenericEdgeCasesConfiguration.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/GenericEdgeCasesConfiguration.java index 8a9aa2acd..155e17a0b 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/GenericEdgeCasesConfiguration.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/GenericEdgeCasesConfiguration.java @@ -6,7 +6,9 @@ import net.jqwik.api.*; -public class GenericEdgeCasesConfiguration implements EdgeCases.Config { +import org.jspecify.annotations.*; + +public class GenericEdgeCasesConfiguration implements EdgeCases.Config { private boolean none; private final List> filters = new ArrayList<>(); private final List additionalEdgeCases = new ArrayList<>(); diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/JustArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/JustArbitrary.java index ce9c3b793..77c7722de 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/JustArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/JustArbitrary.java @@ -8,7 +8,7 @@ import org.jspecify.annotations.*; -public class JustArbitrary implements Arbitrary { +public class JustArbitrary implements Arbitrary { private final T value; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyArbitrary.java index 9da910f76..d950117a6 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyArbitrary.java @@ -7,10 +7,12 @@ import net.jqwik.api.configurators.*; import net.jqwik.api.providers.*; -public class LazyArbitrary implements Arbitrary, SelfConfiguringArbitrary { +import org.jspecify.annotations.*; + +public class LazyArbitrary implements Arbitrary, SelfConfiguringArbitrary { private final Supplier> arbitrarySupplier; private final List> configurations = new ArrayList<>(); - private Arbitrary arbitrary; + private @Nullable Arbitrary arbitrary; public LazyArbitrary(Supplier> arbitrarySupplier) { this.arbitrarySupplier = arbitrarySupplier; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyOfArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyOfArbitrary.java index 74878c7e9..e7447990e 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyOfArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/LazyOfArbitrary.java @@ -14,7 +14,7 @@ import org.jspecify.annotations.*; -public class LazyOfArbitrary implements Arbitrary { +public class LazyOfArbitrary implements Arbitrary { // Cached arbitraries only have to survive one property private static Store>> arbitrariesStore() { diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/OneOfArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/OneOfArbitrary.java index a928246f6..f8981024c 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/OneOfArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/OneOfArbitrary.java @@ -11,7 +11,9 @@ import net.jqwik.engine.properties.arbitraries.exhaustive.*; import net.jqwik.engine.properties.arbitraries.randomized.*; -public class OneOfArbitrary implements Arbitrary, SelfConfiguringArbitrary { +import org.jspecify.annotations.*; + +public class OneOfArbitrary implements Arbitrary, SelfConfiguringArbitrary { private final List> all = new ArrayList<>(); private final boolean isGeneratorMemoizable; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/RecursiveArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/RecursiveArbitrary.java index 1494c3b00..bb976eab5 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/RecursiveArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/RecursiveArbitrary.java @@ -6,7 +6,9 @@ import net.jqwik.api.*; import net.jqwik.api.support.*; -public class RecursiveArbitrary implements Arbitrary { +import org.jspecify.annotations.*; + +public class RecursiveArbitrary implements Arbitrary { private final Supplier> base; private final Function, ? extends Arbitrary> recur; private final int depth; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ReportableStream.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ReportableStream.java index ebc5c3795..f39d22213 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ReportableStream.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ReportableStream.java @@ -8,7 +8,7 @@ import org.jspecify.annotations.*; -public class ReportableStream implements Stream { +public class ReportableStream implements Stream { private final List values; private final Stream stream; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ShuffleArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ShuffleArbitrary.java index e9bf60a28..8d2833952 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ShuffleArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/ShuffleArbitrary.java @@ -6,7 +6,9 @@ import net.jqwik.engine.properties.arbitraries.exhaustive.*; import net.jqwik.engine.properties.arbitraries.randomized.*; -public class ShuffleArbitrary extends UseGeneratorsArbitrary> { +import org.jspecify.annotations.*; + +public class ShuffleArbitrary extends UseGeneratorsArbitrary> { private final List values; public ShuffleArbitrary(List values) { diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/CombineArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/CombineArbitrary.java index b6e052766..f1e9f1a02 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/CombineArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/CombineArbitrary.java @@ -10,7 +10,9 @@ import net.jqwik.engine.properties.arbitraries.exhaustive.*; import net.jqwik.engine.properties.shrinking.*; -public class CombineArbitrary implements Arbitrary { +import org.jspecify.annotations.*; + +public class CombineArbitrary implements Arbitrary { private final Function, ? extends R> combinator; private final List> arbitraries; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultListCombinator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultListCombinator.java index 5594cf0d7..fd81531a1 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultListCombinator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/combinations/DefaultListCombinator.java @@ -10,7 +10,7 @@ import static org.apiguardian.api.API.Status.*; -public class DefaultListCombinator implements Combinators.ListCombinator { +public class DefaultListCombinator implements Combinators.ListCombinator { protected final Arbitrary[] arbitraries; @@ -38,7 +38,7 @@ public Combinators.ListCombinator filter(Predicate> return params -> combinator.apply((List) params); } - private static class Filtered extends DefaultListCombinator { + private static class Filtered extends DefaultListCombinator { private final Predicate> filter; private Filtered(Arbitrary[] arbitraries, Predicate> filter) { diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/CombinedExhaustiveGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/CombinedExhaustiveGenerator.java index 8701d9226..69c44dac3 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/CombinedExhaustiveGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/CombinedExhaustiveGenerator.java @@ -7,7 +7,9 @@ import net.jqwik.api.*; import net.jqwik.engine.support.*; -class CombinedExhaustiveGenerator implements ExhaustiveGenerator { +import org.jspecify.annotations.*; + +class CombinedExhaustiveGenerator implements ExhaustiveGenerator { private final Long maxCount; private final List> arbitraries; private final Function, ? extends R> combinator; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/ExhaustiveGenerators.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/ExhaustiveGenerators.java index da0e60611..9724a3218 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/ExhaustiveGenerators.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/ExhaustiveGenerators.java @@ -108,7 +108,7 @@ public static Optional> strings( ); } - private static class SupplierIterator implements Iterator { + private static class SupplierIterator implements Iterator { private final Supplier supplier; private volatile boolean generated = false; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/FilteredExhaustiveGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/FilteredExhaustiveGenerator.java index 11442b458..aedb2f3f9 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/FilteredExhaustiveGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/exhaustive/FilteredExhaustiveGenerator.java @@ -5,7 +5,9 @@ import net.jqwik.api.*; -public class FilteredExhaustiveGenerator implements ExhaustiveGenerator { +import org.jspecify.annotations.*; + +public class FilteredExhaustiveGenerator implements ExhaustiveGenerator { private final ExhaustiveGenerator toFilter; private final Predicate filter; private int maxMisses; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/CollectGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/CollectGenerator.java index 7122e33c5..fb47f8a65 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/CollectGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/CollectGenerator.java @@ -6,7 +6,9 @@ import net.jqwik.api.*; import net.jqwik.engine.properties.shrinking.*; -public class CollectGenerator implements RandomGenerator> { +import org.jspecify.annotations.*; + +public class CollectGenerator implements RandomGenerator> { private final RandomGenerator elementGenerator; private final Predicate> until; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FilteredGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FilteredGenerator.java index a5f3c8c14..eea20c216 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FilteredGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FilteredGenerator.java @@ -6,7 +6,9 @@ import net.jqwik.api.*; import net.jqwik.engine.properties.shrinking.*; -public class FilteredGenerator implements RandomGenerator { +import org.jspecify.annotations.*; + +public class FilteredGenerator implements RandomGenerator { private final RandomGenerator toFilter; private final Predicate filterPredicate; private int maxMisses; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FrequencyGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FrequencyGenerator.java index cedb08da0..a2806616c 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FrequencyGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/FrequencyGenerator.java @@ -6,7 +6,9 @@ import net.jqwik.engine.properties.shrinking.*; import net.jqwik.engine.support.*; -class FrequencyGenerator extends ChooseRandomlyByFrequency implements RandomGenerator { +import org.jspecify.annotations.*; + +class FrequencyGenerator extends ChooseRandomlyByFrequency implements RandomGenerator { FrequencyGenerator(List> frequencies) { super(frequencies); diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/IgnoreExceptionGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/IgnoreExceptionGenerator.java index ad4b917ec..60df08e7c 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/IgnoreExceptionGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/IgnoreExceptionGenerator.java @@ -6,9 +6,11 @@ import net.jqwik.api.*; import net.jqwik.engine.properties.shrinking.*; +import org.jspecify.annotations.*; + import static net.jqwik.engine.support.JqwikExceptionSupport.*; -public class IgnoreExceptionGenerator implements RandomGenerator { +public class IgnoreExceptionGenerator implements RandomGenerator { private final RandomGenerator base; private final Class[] exceptionTypes; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/InjectDuplicatesGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/InjectDuplicatesGenerator.java index 764c144bb..7321590eb 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/InjectDuplicatesGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/InjectDuplicatesGenerator.java @@ -6,7 +6,9 @@ import net.jqwik.api.lifecycle.*; import net.jqwik.engine.*; -public class InjectDuplicatesGenerator implements RandomGenerator { +import org.jspecify.annotations.*; + +public class InjectDuplicatesGenerator implements RandomGenerator { private final RandomGenerator base; private final double duplicateProbability; diff --git a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/WithEdgeCasesGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/WithEdgeCasesGenerator.java index 6f20ad0a6..535c057ae 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/WithEdgeCasesGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/arbitraries/randomized/WithEdgeCasesGenerator.java @@ -8,7 +8,7 @@ import org.jspecify.annotations.*; -class WithEdgeCasesGenerator implements RandomGenerator { +class WithEdgeCasesGenerator implements RandomGenerator { private final RandomGenerator base; private final int baseToEdgeCaseRatio; diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/AbstractValueShrinkable.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/AbstractValueShrinkable.java index 2b4ee0ecc..521ae125d 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/AbstractValueShrinkable.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/AbstractValueShrinkable.java @@ -2,7 +2,11 @@ import net.jqwik.api.*; -public abstract class AbstractValueShrinkable implements Shrinkable { +import org.jspecify.annotations.*; + +import java.util.*; + +public abstract class AbstractValueShrinkable implements Shrinkable { private final T value; @@ -22,12 +26,12 @@ public boolean equals(Object o) { AbstractValueShrinkable that = (AbstractValueShrinkable) o; - return value.equals(that.value); + return Objects.equals(value, that.value); } @Override public int hashCode() { - return value.hashCode(); + return Objects.hash(value); } @Override diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/ChooseValueShrinkable.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/ChooseValueShrinkable.java index c3bf061a7..217a47f22 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/ChooseValueShrinkable.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/ChooseValueShrinkable.java @@ -5,7 +5,9 @@ import net.jqwik.api.*; -public class ChooseValueShrinkable extends AbstractValueShrinkable { +import org.jspecify.annotations.*; + +public class ChooseValueShrinkable extends AbstractValueShrinkable { private final List values; diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/CollectShrinkable.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/CollectShrinkable.java index 5268a4263..8d348efa7 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/CollectShrinkable.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/CollectShrinkable.java @@ -7,7 +7,9 @@ import net.jqwik.api.*; import net.jqwik.engine.support.*; -public class CollectShrinkable implements Shrinkable> { +import org.jspecify.annotations.*; + +public class CollectShrinkable implements Shrinkable> { private final List> elements; private final Predicate> until; diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/CombinedShrinkable.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/CombinedShrinkable.java index ab539f030..9a291bad6 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/CombinedShrinkable.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/CombinedShrinkable.java @@ -7,7 +7,9 @@ import net.jqwik.api.*; import net.jqwik.engine.support.*; -public class CombinedShrinkable implements Shrinkable { +import org.jspecify.annotations.*; + +public class CombinedShrinkable implements Shrinkable { private final List> parts; private final Function, ? extends T> combinator; diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/FilteredShrinkable.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/FilteredShrinkable.java index 0815b42a7..51bf3bed9 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/FilteredShrinkable.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/FilteredShrinkable.java @@ -8,7 +8,9 @@ import net.jqwik.api.*; import net.jqwik.engine.support.*; -public class FilteredShrinkable implements Shrinkable { +import org.jspecify.annotations.*; + +public class FilteredShrinkable implements Shrinkable { private static final int MAX_BASE_SHRINKS = 100; private final AtomicInteger countBaseShrinks = new AtomicInteger(0); diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/IgnoreExceptionShrinkable.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/IgnoreExceptionShrinkable.java index 866fa3d06..6fa4554fc 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/IgnoreExceptionShrinkable.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/IgnoreExceptionShrinkable.java @@ -4,9 +4,11 @@ import net.jqwik.api.*; +import org.jspecify.annotations.*; + import static net.jqwik.engine.support.JqwikExceptionSupport.*; -public class IgnoreExceptionShrinkable implements Shrinkable { +public class IgnoreExceptionShrinkable implements Shrinkable { private final Shrinkable shrinkable; private final Class[] exceptionTypes; diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/LazyOfShrinkable.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/LazyOfShrinkable.java index f4731ad73..497c11246 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/LazyOfShrinkable.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/LazyOfShrinkable.java @@ -6,7 +6,9 @@ import net.jqwik.api.*; -public class LazyOfShrinkable implements Shrinkable { +import org.jspecify.annotations.*; + +public class LazyOfShrinkable implements Shrinkable { public final Shrinkable current; public final int depth; public final Set> parts; diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/SampleShrinkable.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/SampleShrinkable.java index 2b16fe9de..a097af29a 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/SampleShrinkable.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/SampleShrinkable.java @@ -5,7 +5,9 @@ import net.jqwik.api.*; -public class SampleShrinkable extends AbstractValueShrinkable { +import org.jspecify.annotations.*; + +public class SampleShrinkable extends AbstractValueShrinkable { private final List samples; private final int index; diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkableList.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkableList.java index b2bbacb74..04d2317c4 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkableList.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkableList.java @@ -7,9 +7,11 @@ import net.jqwik.engine.properties.*; import net.jqwik.engine.support.*; +import org.jspecify.annotations.*; + import static net.jqwik.engine.properties.UniquenessChecker.*; -public class ShrinkableList extends ShrinkableContainer, E> { +public class ShrinkableList extends ShrinkableContainer, E> { // Only used in tests ShrinkableList(List> elements, int minSize, int maxSize) { diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkableSet.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkableSet.java index aaacd69b8..d47e6abeb 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkableSet.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/ShrinkableSet.java @@ -8,7 +8,7 @@ import net.jqwik.api.*; import net.jqwik.engine.properties.*; -public class ShrinkableSet extends ShrinkableContainer, E> { +public class ShrinkableSet extends ShrinkableContainer, E> { public ShrinkableSet( Collection> elements, diff --git a/engine/src/main/java/net/jqwik/engine/properties/shrinking/Unshrinkable.java b/engine/src/main/java/net/jqwik/engine/properties/shrinking/Unshrinkable.java index fb8644003..beabd71fd 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/shrinking/Unshrinkable.java +++ b/engine/src/main/java/net/jqwik/engine/properties/shrinking/Unshrinkable.java @@ -7,7 +7,9 @@ import net.jqwik.api.*; import net.jqwik.engine.support.*; -public class Unshrinkable implements Shrinkable { +import org.jspecify.annotations.*; + +public class Unshrinkable implements Shrinkable { private final ShrinkingDistance distance; private final Supplier valueSupplier; diff --git a/engine/src/main/java/net/jqwik/engine/properties/state/DefaultActionChainArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/state/DefaultActionChainArbitrary.java index 06b430c14..3d5052093 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/state/DefaultActionChainArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/state/DefaultActionChainArbitrary.java @@ -4,6 +4,7 @@ import java.util.*; import java.util.function.*; +import org.jspecify.annotations.*; import org.junit.platform.commons.support.*; import net.jqwik.api.*; @@ -11,7 +12,7 @@ import net.jqwik.api.state.*; import net.jqwik.engine.support.*; -public class DefaultActionChainArbitrary extends ArbitraryDecorator> implements ActionChainArbitrary { +public class DefaultActionChainArbitrary extends ArbitraryDecorator> implements ActionChainArbitrary { private ChainArbitrary chainArbitrary; diff --git a/engine/src/main/java/net/jqwik/engine/properties/state/DefaultChainArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/state/DefaultChainArbitrary.java index 5c15ae319..713529e79 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/state/DefaultChainArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/state/DefaultChainArbitrary.java @@ -8,7 +8,9 @@ import net.jqwik.engine.properties.arbitraries.*; import net.jqwik.engine.support.*; -public class DefaultChainArbitrary extends TypedCloneable implements ChainArbitrary { +import org.jspecify.annotations.*; + +public class DefaultChainArbitrary extends TypedCloneable implements ChainArbitrary { private int maxTransformations = Integer.MIN_VALUE; private Supplier> changeDetectorSupplier = ChangeDetector::alwaysTrue; diff --git a/engine/src/main/java/net/jqwik/engine/properties/state/ShrinkableChain.java b/engine/src/main/java/net/jqwik/engine/properties/state/ShrinkableChain.java index 3103e257a..10fa78042 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/state/ShrinkableChain.java +++ b/engine/src/main/java/net/jqwik/engine/properties/state/ShrinkableChain.java @@ -15,7 +15,7 @@ import net.jqwik.api.state.*; import net.jqwik.engine.*; -public class ShrinkableChain implements Shrinkable> { +public class ShrinkableChain implements Shrinkable> { public static final int MAX_TRANSFORMER_TRIES = 1000; private final long randomSeed; @@ -127,9 +127,9 @@ private class ChainIterator implements Iterator { private final Random random = SourceOfRandomness.newRandom(randomSeed); private int steps = 0; - private T current; + private @Nullable T current; private boolean initialSupplied = false; - private Transformer nextTransformer = null; + private @Nullable Transformer nextTransformer = null; private ChainIterator(T initial) { this.current = initial; diff --git a/engine/src/main/java/net/jqwik/engine/properties/stateful/ActionSequenceGenerator.java b/engine/src/main/java/net/jqwik/engine/properties/stateful/ActionSequenceGenerator.java index e36f79cc8..c451becf3 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/stateful/ActionSequenceGenerator.java +++ b/engine/src/main/java/net/jqwik/engine/properties/stateful/ActionSequenceGenerator.java @@ -5,7 +5,9 @@ import net.jqwik.api.*; import net.jqwik.api.stateful.*; -class ActionSequenceGenerator implements RandomGenerator> { +import org.jspecify.annotations.*; + +class ActionSequenceGenerator implements RandomGenerator> { private final int genSize; private final int maxSize; private final Arbitrary> actionArbitrary; diff --git a/engine/src/main/java/net/jqwik/engine/properties/stateful/DefaultActionSequenceArbitrary.java b/engine/src/main/java/net/jqwik/engine/properties/stateful/DefaultActionSequenceArbitrary.java index 3bda6b677..ad614037e 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/stateful/DefaultActionSequenceArbitrary.java +++ b/engine/src/main/java/net/jqwik/engine/properties/stateful/DefaultActionSequenceArbitrary.java @@ -4,7 +4,9 @@ import net.jqwik.api.stateful.*; import net.jqwik.engine.properties.arbitraries.*; -public class DefaultActionSequenceArbitrary extends TypedCloneable implements ActionSequenceArbitrary { +import org.jspecify.annotations.*; + +public class DefaultActionSequenceArbitrary extends TypedCloneable implements ActionSequenceArbitrary { private final Arbitrary> actionArbitrary; diff --git a/engine/src/main/java/net/jqwik/engine/properties/stateful/SequentialActionSequence.java b/engine/src/main/java/net/jqwik/engine/properties/stateful/SequentialActionSequence.java index 005d676bd..f6a2a7186 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/stateful/SequentialActionSequence.java +++ b/engine/src/main/java/net/jqwik/engine/properties/stateful/SequentialActionSequence.java @@ -4,6 +4,7 @@ import java.util.function.*; import java.util.stream.*; +import org.jspecify.annotations.*; import org.opentest4j.*; import net.jqwik.api.*; @@ -11,7 +12,7 @@ import net.jqwik.api.stateful.*; import net.jqwik.engine.support.*; -class SequentialActionSequence implements ActionSequence { +class SequentialActionSequence implements ActionSequence { protected ActionGenerator actionGenerator; protected int intendedSize; @@ -20,7 +21,7 @@ class SequentialActionSequence implements ActionSequence { private final List> peekers = new ArrayList<>(); protected RunState runState = RunState.NOT_RUN; - private M currentModel = null; + private @Nullable M currentModel = null; SequentialActionSequence(ActionGenerator actionGenerator, int intendedSize) { if (intendedSize < 1) { diff --git a/engine/src/main/java/net/jqwik/engine/properties/stateful/ShrinkableActionSequence.java b/engine/src/main/java/net/jqwik/engine/properties/stateful/ShrinkableActionSequence.java index 5c1735977..d6347a3f2 100644 --- a/engine/src/main/java/net/jqwik/engine/properties/stateful/ShrinkableActionSequence.java +++ b/engine/src/main/java/net/jqwik/engine/properties/stateful/ShrinkableActionSequence.java @@ -7,13 +7,15 @@ import net.jqwik.api.stateful.*; import net.jqwik.engine.support.*; -class ShrinkableActionSequence implements Shrinkable> { +import org.jspecify.annotations.*; + +class ShrinkableActionSequence implements Shrinkable> { private final ActionGenerator actionGenerator; private final int maxSize; private final ShrinkingDistance distance; - private SequentialActionSequence generatedSequence = null; + private @Nullable SequentialActionSequence generatedSequence = null; ShrinkableActionSequence(ActionGenerator actionGenerator, int maxSize, ShrinkingDistance distance) { this.actionGenerator = actionGenerator; diff --git a/engine/src/main/java/net/jqwik/engine/support/ChooseRandomlyByFrequency.java b/engine/src/main/java/net/jqwik/engine/support/ChooseRandomlyByFrequency.java index 1b1faf86e..6e44bfebb 100644 --- a/engine/src/main/java/net/jqwik/engine/support/ChooseRandomlyByFrequency.java +++ b/engine/src/main/java/net/jqwik/engine/support/ChooseRandomlyByFrequency.java @@ -5,7 +5,9 @@ import net.jqwik.api.*; -public class ChooseRandomlyByFrequency implements Function { +import org.jspecify.annotations.*; + +public class ChooseRandomlyByFrequency implements Function { private int[] upperBounds; private int size = 0; diff --git a/engine/src/main/java/net/jqwik/engine/support/combinatorics/CombinedIterator.java b/engine/src/main/java/net/jqwik/engine/support/combinatorics/CombinedIterator.java index a621463ef..af85f398f 100644 --- a/engine/src/main/java/net/jqwik/engine/support/combinatorics/CombinedIterator.java +++ b/engine/src/main/java/net/jqwik/engine/support/combinatorics/CombinedIterator.java @@ -1,9 +1,11 @@ package net.jqwik.engine.support.combinatorics; +import org.jspecify.annotations.*; + import java.util.*; import java.util.stream.*; -public class CombinedIterator implements Iterator> { +public class CombinedIterator implements Iterator> { private final List> iterables; private final List> iterators; private final List elements; diff --git a/engine/src/main/java/net/jqwik/engine/support/combinatorics/ConcatIterator.java b/engine/src/main/java/net/jqwik/engine/support/combinatorics/ConcatIterator.java index b7d742fa1..b30a0a79e 100644 --- a/engine/src/main/java/net/jqwik/engine/support/combinatorics/ConcatIterator.java +++ b/engine/src/main/java/net/jqwik/engine/support/combinatorics/ConcatIterator.java @@ -1,13 +1,15 @@ package net.jqwik.engine.support.combinatorics; +import org.jspecify.annotations.*; + import java.util.*; import java.util.concurrent.atomic.*; -public class ConcatIterator implements Iterator { +public class ConcatIterator implements Iterator { private final List> iterators; private final AtomicInteger position; - private Iterator next; + private @Nullable Iterator next; public ConcatIterator(List> iterators) { this.iterators = iterators; @@ -17,7 +19,7 @@ public ConcatIterator(List> iterators) { } } - private Iterator findNext() { + private @Nullable Iterator findNext() { while (!iterators.get(position.get()).hasNext()) { if (position.get() >= iterators.size() -1) return null; diff --git a/engine/src/main/java/net/jqwik/engine/support/combinatorics/PermutationIterator.java b/engine/src/main/java/net/jqwik/engine/support/combinatorics/PermutationIterator.java index 560979c3b..d874d8da0 100644 --- a/engine/src/main/java/net/jqwik/engine/support/combinatorics/PermutationIterator.java +++ b/engine/src/main/java/net/jqwik/engine/support/combinatorics/PermutationIterator.java @@ -1,12 +1,14 @@ package net.jqwik.engine.support.combinatorics; +import org.jspecify.annotations.*; + import java.util.*; // Taken and adapted from https://codereview.stackexchange.com/questions/119969/ -public class PermutationIterator implements Iterator> { +public class PermutationIterator implements Iterator> { private final List values = new ArrayList<>(); - private List next; - private int[] indices; + private @Nullable List next; + private int @Nullable [] indices; public PermutationIterator(List values) { this.values.addAll(values); diff --git a/engine/src/main/java/net/jqwik/engine/support/combinatorics/SetIterator.java b/engine/src/main/java/net/jqwik/engine/support/combinatorics/SetIterator.java index 3779206e4..f73410154 100644 --- a/engine/src/main/java/net/jqwik/engine/support/combinatorics/SetIterator.java +++ b/engine/src/main/java/net/jqwik/engine/support/combinatorics/SetIterator.java @@ -1,8 +1,10 @@ package net.jqwik.engine.support.combinatorics; +import org.jspecify.annotations.*; + import java.util.*; -public class SetIterator implements Iterator> { +public class SetIterator implements Iterator> { private final Iterator> combinedListIterator; private final Set> generatedSets = new LinkedHashSet<>();