From d698561e58fce0a498ccc9c43539046b5f9a6ddf Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Sun, 14 Jun 2020 12:09:23 +0200 Subject: [PATCH] Cleans up awkwardly auto-formatted code --- .../checkers/AbstractDelegationChecker.java | 12 +- .../internal/checkers/ExamplesChecker.java | 24 +-- .../internal/checkers/HierarchyChecker.java | 16 +- .../internal/checkers/SignatureChecker.java | 8 +- .../fieldchecks/MutableStateFieldCheck.java | 9 +- .../NullPointerExceptionFieldCheck.java | 24 +-- .../fieldchecks/ReflexivityFieldCheck.java | 6 +- .../fieldchecks/TransientFieldsCheck.java | 13 +- .../prefabvalues/factories/Factories.java | 6 +- .../JavaFxFactoryProvider.java | 14 +- .../internal/reflection/FieldAccessor.java | 11 +- .../annotations/AnnotationCacheBuilder.java | 139 +++++++----------- .../internal/util/Configuration.java | 20 +-- .../internal/util/Validations.java | 12 +- 14 files changed, 135 insertions(+), 179 deletions(-) diff --git a/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java b/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java index 25f9826c7..2f9217b6c 100644 --- a/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java +++ b/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java @@ -100,10 +100,10 @@ private void checkAbstractMethods( try { instance.equals(copy); } catch (AbstractMethodError e) { - fail( + Formatter f = buildAbstractDelegationErrorMessage( - instanceClass, prefabPossible, "equals", e.getMessage()), - e); + instanceClass, prefabPossible, "equals", e.getMessage()); + fail(f, e); } catch (Exception ignored) { // Skip. We only care about AbstractMethodError at this point; // other errors will be handled later. @@ -112,10 +112,10 @@ private void checkAbstractMethods( try { cachedHashCodeInitializer.getInitializedHashCode(instance); } catch (AbstractMethodError e) { - fail( + Formatter f = buildAbstractDelegationErrorMessage( - instanceClass, prefabPossible, "hashCode", e.getMessage()), - e); + instanceClass, prefabPossible, "hashCode", e.getMessage()); + fail(f, e); } catch (Exception ignored) { // Skip. We only care about AbstractMethodError at this point; // other errors will be handled later. diff --git a/src/main/java/nl/jqno/equalsverifier/internal/checkers/ExamplesChecker.java b/src/main/java/nl/jqno/equalsverifier/internal/checkers/ExamplesChecker.java index d21bb491e..dd2bc28e9 100644 --- a/src/main/java/nl/jqno/equalsverifier/internal/checkers/ExamplesChecker.java +++ b/src/main/java/nl/jqno/equalsverifier/internal/checkers/ExamplesChecker.java @@ -86,11 +86,11 @@ private void checkReflexivity(T reference) { reference, reference); } catch (ClassCastException e) { - fail( + Formatter f = Formatter.of( "Generics: ClassCastException was thrown. " - + "Consider using withGenericPrefabValues for the type that triggered the exception."), - e); + + "Consider using withGenericPrefabValues for the type that triggered the exception."); + fail(f, e); } } @@ -110,23 +110,23 @@ private void checkTypeCheck(T reference) { class SomethingElse {} SomethingElse somethingElse = new SomethingElse(); try { - assertFalse( + Formatter f = Formatter.of( - "Type-check: equals returns true for an unrelated type.\nAdd an instanceof or getClass() check."), - reference.equals(somethingElse)); + "Type-check: equals returns true for an unrelated type.\nAdd an instanceof or getClass() check."); + assertFalse(f, reference.equals(somethingElse)); } catch (AssertionException e) { throw e; } catch (ClassCastException e) { - fail( + Formatter f = Formatter.of( - "Type-check: equals throws ClassCastException.\nAdd an instanceof or getClass() check."), - e); + "Type-check: equals throws ClassCastException.\nAdd an instanceof or getClass() check."); + fail(f, e); } catch (Exception e) { - fail( + Formatter f = Formatter.of( "Type-check: equals throws %%.\nAdd an instanceof or getClass() check.", - e.getClass().getSimpleName()), - e); + e.getClass().getSimpleName()); + fail(f, e); } } diff --git a/src/main/java/nl/jqno/equalsverifier/internal/checkers/HierarchyChecker.java b/src/main/java/nl/jqno/equalsverifier/internal/checkers/HierarchyChecker.java index aa823c266..dd9bea7aa 100644 --- a/src/main/java/nl/jqno/equalsverifier/internal/checkers/HierarchyChecker.java +++ b/src/main/java/nl/jqno/equalsverifier/internal/checkers/HierarchyChecker.java @@ -26,8 +26,9 @@ public class HierarchyChecker implements Checker { public HierarchyChecker(Configuration config) { this.config = config; - if (config.getWarningsToSuppress().contains(Warning.STRICT_INHERITANCE) - && config.getRedefinedSubclass() != null) { + boolean nonStrict = config.getWarningsToSuppress().contains(Warning.STRICT_INHERITANCE); + boolean hasRedefinedSubclass = config.getRedefinedSubclass() != null; + if (nonStrict && hasRedefinedSubclass) { fail( Formatter.of( "withRedefinedSubclass and weakInheritanceCheck are mutually exclusive.")); @@ -174,13 +175,10 @@ private void checkRedefinedSubclass() { } private void checkFinalEqualsMethod() { - boolean ignore = - config.getWarningsToSuppress().contains(Warning.STRICT_INHERITANCE) - || config.getAnnotationCache() - .hasClassAnnotation(type, SupportedAnnotations.ENTITY) - || typeIsFinal - || redefinedSubclass != null; - if (ignore) { + boolean nonStrict = config.getWarningsToSuppress().contains(Warning.STRICT_INHERITANCE); + boolean isEntity = + config.getAnnotationCache().hasClassAnnotation(type, SupportedAnnotations.ENTITY); + if (nonStrict || isEntity || typeIsFinal || redefinedSubclass != null) { return; } diff --git a/src/main/java/nl/jqno/equalsverifier/internal/checkers/SignatureChecker.java b/src/main/java/nl/jqno/equalsverifier/internal/checkers/SignatureChecker.java index ea2845299..7812c2ddf 100644 --- a/src/main/java/nl/jqno/equalsverifier/internal/checkers/SignatureChecker.java +++ b/src/main/java/nl/jqno/equalsverifier/internal/checkers/SignatureChecker.java @@ -35,10 +35,10 @@ public void check() { } private void checkEqualsIsDefined() { - boolean fail = - !warningsToSuppress.contains(Warning.INHERITED_DIRECTLY_FROM_OBJECT) - && classAccessor.isEqualsInheritedFromObject(); - if (fail) { + boolean dontAllowDirectlyInherited = + !warningsToSuppress.contains(Warning.INHERITED_DIRECTLY_FROM_OBJECT); + boolean isDirectlyInherited = classAccessor.isEqualsInheritedFromObject(); + if (dontAllowDirectlyInherited && isDirectlyInherited) { fail( Formatter.of( "Equals is inherited directly from Object.\n" diff --git a/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/MutableStateFieldCheck.java b/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/MutableStateFieldCheck.java index 0b6ec556a..794900f08 100644 --- a/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/MutableStateFieldCheck.java +++ b/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/MutableStateFieldCheck.java @@ -36,11 +36,10 @@ public void execute(FieldAccessor referenceAccessor, FieldAccessor changedAccess boolean equalAfter = reference.equals(changed); if (equalBefore && !equalAfter && !referenceAccessor.fieldIsFinal()) { - fail( - Formatter.of( - "Mutability: equals depends on mutable field %%.\n" - + "Make the field final, suppress Warning.NONFINAL_FIELDS or use EqualsVerifier.simple()", - referenceAccessor.getFieldName())); + String message = + "Mutability: equals depends on mutable field %%.\n" + + "Make the field final, suppress Warning.NONFINAL_FIELDS or use EqualsVerifier.simple()"; + fail(Formatter.of(message, referenceAccessor.getFieldName())); } referenceAccessor.changeField(prefabValues, typeTag); diff --git a/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/NullPointerExceptionFieldCheck.java b/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/NullPointerExceptionFieldCheck.java index 9b75ea1ce..dd31f9114 100644 --- a/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/NullPointerExceptionFieldCheck.java +++ b/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/NullPointerExceptionFieldCheck.java @@ -68,35 +68,35 @@ private void handle(String testedMethodName, Field field, Runnable r) { } private void npeThrown(String method, Field field, NullPointerException e) { - fail( + Formatter f = Formatter.of( "Non-nullity: %% throws NullPointerException on field %%.", - method, field.getName()), - e); + method, field.getName()); + fail(f, e); } private void abstractMethodErrorThrown(String method, Field field, AbstractMethodError e) { - fail( + Formatter f = Formatter.of( "Abstract delegation: %% throws AbstractMethodError when field %% is null.\n" + "Suppress Warning.NULL_FIELDS to disable this check.", - method, field.getName()), - e); + method, field.getName()); + fail(f, e); } private void classCastExceptionThrown(Field field, ClassCastException e) { - fail( + Formatter f = Formatter.of( "Generics: ClassCastException was thrown. Consider using withGenericPrefabValues for %%.", - field.getType().getSimpleName()), - e); + field.getType().getSimpleName()); + fail(f, e); } private void exceptionThrown(String method, Field field, Exception e) { - fail( + Formatter f = Formatter.of( "%% throws %% when field %% is null.", - method, e.getClass().getSimpleName(), field.getName()), - e); + method, e.getClass().getSimpleName(), field.getName()); + fail(f, e); } } diff --git a/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ReflexivityFieldCheck.java b/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ReflexivityFieldCheck.java index f0092d3e8..3c430ed37 100644 --- a/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ReflexivityFieldCheck.java +++ b/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ReflexivityFieldCheck.java @@ -105,11 +105,11 @@ private void checkReflexivityFor( Object right = changedAccessor.getObject(); if (warningsToSuppress.contains(Warning.IDENTICAL_COPY)) { - assertFalse( + Formatter f = Formatter.of( "Unnecessary suppression: %%. Two identical copies are equal.", - Warning.IDENTICAL_COPY.toString()), - left.equals(right)); + Warning.IDENTICAL_COPY.toString()); + assertFalse(f, left.equals(right)); } else { Formatter f = Formatter.of( diff --git a/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransientFieldsCheck.java b/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransientFieldsCheck.java index f833415a8..3abf2ecda 100644 --- a/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransientFieldsCheck.java +++ b/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransientFieldsCheck.java @@ -29,13 +29,12 @@ public void execute(FieldAccessor referenceAccessor, FieldAccessor changedAccess changedAccessor.changeField(prefabValues, typeTag); boolean equalsChanged = !reference.equals(changed); - boolean fieldIsTransient = - referenceAccessor.fieldIsTransient() - || annotationCache.hasFieldAnnotation( - typeTag.getType(), - referenceAccessor.getFieldName(), - SupportedAnnotations.TRANSIENT); - + boolean hasAnnotation = + annotationCache.hasFieldAnnotation( + typeTag.getType(), + referenceAccessor.getFieldName(), + SupportedAnnotations.TRANSIENT); + boolean fieldIsTransient = referenceAccessor.fieldIsTransient() || hasAnnotation; if (equalsChanged && fieldIsTransient) { fail( Formatter.of( diff --git a/src/main/java/nl/jqno/equalsverifier/internal/prefabvalues/factories/Factories.java b/src/main/java/nl/jqno/equalsverifier/internal/prefabvalues/factories/Factories.java index 46fb39d83..3023d81b3 100644 --- a/src/main/java/nl/jqno/equalsverifier/internal/prefabvalues/factories/Factories.java +++ b/src/main/java/nl/jqno/equalsverifier/internal/prefabvalues/factories/Factories.java @@ -28,13 +28,13 @@ public static PrefabValueFactory simple( public static > PrefabValueFactory collection( Supplier emptyFactory) { - return Factories.simple( + Func1 f = a -> { T coll = emptyFactory.get(); coll.add(a); return coll; - }, - emptyFactory); + }; + return Factories.simple(f, emptyFactory); } public static PrefabValueFactory copy(Class source, Function copy) { diff --git a/src/main/java/nl/jqno/equalsverifier/internal/prefabvalues/factoryproviders/JavaFxFactoryProvider.java b/src/main/java/nl/jqno/equalsverifier/internal/prefabvalues/factoryproviders/JavaFxFactoryProvider.java index 17ce52df2..645e526bd 100644 --- a/src/main/java/nl/jqno/equalsverifier/internal/prefabvalues/factoryproviders/JavaFxFactoryProvider.java +++ b/src/main/java/nl/jqno/equalsverifier/internal/prefabvalues/factoryproviders/JavaFxFactoryProvider.java @@ -7,6 +7,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.function.Function; import nl.jqno.equalsverifier.internal.prefabvalues.FactoryCache; import nl.jqno.equalsverifier.internal.prefabvalues.PrefabValues; import nl.jqno.equalsverifier.internal.prefabvalues.Tuple; @@ -115,13 +116,10 @@ public Tuple createValues( @SuppressWarnings("unchecked") private static PrefabValueFactory fxCollection( Class source, String copyMethodName) { - return copy( - source, - a -> { - ConditionalInstantiator ci = - new ConditionalInstantiator( - JAVAFX_COLLECTIONS_PACKAGE + "FXCollections"); - return ci.callFactory(copyMethodName, classes(source), objects(a)); - }); + Function f = + a -> + new ConditionalInstantiator(JAVAFX_COLLECTIONS_PACKAGE + "FXCollections") + .callFactory(copyMethodName, classes(source), objects(a)); + return copy(source, f); } } diff --git a/src/main/java/nl/jqno/equalsverifier/internal/reflection/FieldAccessor.java b/src/main/java/nl/jqno/equalsverifier/internal/reflection/FieldAccessor.java index 24ef39545..57cbfff40 100644 --- a/src/main/java/nl/jqno/equalsverifier/internal/reflection/FieldAccessor.java +++ b/src/main/java/nl/jqno/equalsverifier/internal/reflection/FieldAccessor.java @@ -167,14 +167,13 @@ public void copyTo(Object to) { * @throws ReflectionException If the operation fails. */ public void changeField(PrefabValues prefabValues, TypeTag enclosingType) { - modify( + FieldModifier fm = () -> { - Object newValue = - prefabValues.giveOther( - TypeTag.of(field, enclosingType), field.get(object)); + TypeTag tag = TypeTag.of(field, enclosingType); + Object newValue = prefabValues.giveOther(tag, field.get(object)); field.set(object, newValue); - }, - false); + }; + modify(fm, false); } private void modify(FieldModifier modifier, boolean includeStatic) { diff --git a/src/main/java/nl/jqno/equalsverifier/internal/reflection/annotations/AnnotationCacheBuilder.java b/src/main/java/nl/jqno/equalsverifier/internal/reflection/annotations/AnnotationCacheBuilder.java index 3dd3cfb4f..1fa2ba9c0 100644 --- a/src/main/java/nl/jqno/equalsverifier/internal/reflection/annotations/AnnotationCacheBuilder.java +++ b/src/main/java/nl/jqno/equalsverifier/internal/reflection/annotations/AnnotationCacheBuilder.java @@ -8,6 +8,9 @@ import java.util.Set; import java.util.function.Consumer; import net.bytebuddy.description.annotation.AnnotationDescription; +import net.bytebuddy.description.field.FieldDescription; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.description.method.MethodList; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.pool.TypePool; import nl.jqno.equalsverifier.internal.reflection.SuperclassIterable; @@ -51,12 +54,10 @@ private void visitType( } private void visitSuperclasses(Class type, AnnotationCache cache, TypePool pool) { - SuperclassIterable.of(type) - .forEach( - c -> { - TypeDescription typeDescription = pool.describe(c.getName()).resolve(); - visitType(setOf(type, c), cache, typeDescription, true); - }); + for (Class c : SuperclassIterable.of(type)) { + TypeDescription typeDescription = pool.describe(c.getName()).resolve(); + visitType(setOf(type, c), cache, typeDescription, true); + } } private void visitOuterClasses(Class type, AnnotationCache cache, TypePool pool) { @@ -101,66 +102,36 @@ private void visitFields( AnnotationCache cache, TypeDescription typeDescription, boolean inheriting) { - typeDescription - .getDeclaredFields() - .forEach( - f -> { - Consumer addToCache = - a -> - types.forEach( - t -> - cache.addFieldAnnotation( - t, f.getName(), a)); - - // Regular field annotations - f.getDeclaredAnnotations() - .forEach( - a -> - cacheSupportedAnnotations( - a, - types, - cache, - addToCache, - inheriting)); - - // Type-use annotations - f.getType() - .getDeclaredAnnotations() - .forEach( - a -> - cacheSupportedAnnotations( - a, - types, - cache, - addToCache, - inheriting)); - }); - typeDescription - .getDeclaredMethods() - .filter(m -> m.getName().startsWith("get") && m.getName().length() > 3) - .forEach( - m -> { - String methodName = m.getName(); - String correspondingFieldName = - Character.toLowerCase(methodName.charAt(3)) - + methodName.substring(4); - Consumer addToCache = - a -> - types.forEach( - t -> - cache.addFieldAnnotation( - t, correspondingFieldName, a)); - - m.getDeclaredAnnotations() - .forEach( - a -> - cacheSupportedAnnotations( - a, - types, - cache, - addToCache, - inheriting)); - }); + for (FieldDescription.InDefinedShape f : typeDescription.getDeclaredFields()) { + Consumer addToCache = + a -> types.forEach(t -> cache.addFieldAnnotation(t, f.getName(), a)); + + // Regular field annotations + for (AnnotationDescription a : f.getDeclaredAnnotations()) { + cacheSupportedAnnotations(a, types, cache, addToCache, inheriting); + } + + // Type-use annotations + for (AnnotationDescription a : f.getType().getDeclaredAnnotations()) { + cacheSupportedAnnotations(a, types, cache, addToCache, inheriting); + } + } + + MethodList methods = + typeDescription + .getDeclaredMethods() + .filter(m -> m.getName().startsWith("get") && m.getName().length() > 3); + for (MethodDescription.InDefinedShape m : methods) { + String methodName = m.getName(); + String correspondingFieldName = + Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4); + Consumer addToCache = + a -> types.forEach(t -> cache.addFieldAnnotation(t, correspondingFieldName, a)); + + for (AnnotationDescription a : m.getDeclaredAnnotations()) { + cacheSupportedAnnotations(a, types, cache, addToCache, inheriting); + } + } } private void cacheSupportedAnnotations( @@ -187,26 +158,22 @@ private void cacheSupportedAnnotations( private AnnotationProperties buildAnnotationProperties(AnnotationDescription annotation) { AnnotationProperties props = new AnnotationProperties(annotation.getAnnotationType().getCanonicalName()); - annotation - .getAnnotationType() - .getDeclaredMethods() - .forEach( - m -> { - Object val = annotation.getValue(m).resolve(); - if (val.getClass().isArray() - && !val.getClass().getComponentType().isPrimitive()) { - Object[] array = (Object[]) val; - Set values = new HashSet<>(); - for (Object obj : array) { - if (obj instanceof TypeDescription) { - values.add(((TypeDescription) obj).getName()); - } else { - values.add(obj.toString()); - } - } - props.putArrayValues(m.getName(), values); - } - }); + for (MethodDescription.InDefinedShape m : + annotation.getAnnotationType().getDeclaredMethods()) { + Object val = annotation.getValue(m).resolve(); + if (val.getClass().isArray() && !val.getClass().getComponentType().isPrimitive()) { + Object[] array = (Object[]) val; + Set values = new HashSet<>(); + for (Object obj : array) { + if (obj instanceof TypeDescription) { + values.add(((TypeDescription) obj).getName()); + } else { + values.add(obj.toString()); + } + } + props.putArrayValues(m.getName(), values); + } + } return props; } diff --git a/src/main/java/nl/jqno/equalsverifier/internal/util/Configuration.java b/src/main/java/nl/jqno/equalsverifier/internal/util/Configuration.java index 0755c2e70..5aa0f8ae0 100644 --- a/src/main/java/nl/jqno/equalsverifier/internal/util/Configuration.java +++ b/src/main/java/nl/jqno/equalsverifier/internal/util/Configuration.java @@ -1,6 +1,7 @@ package nl.jqno.equalsverifier.internal.util; import java.util.*; +import java.util.function.BiFunction; import java.util.stream.Collectors; import nl.jqno.equalsverifier.Warning; import nl.jqno.equalsverifier.internal.prefabvalues.FactoryCache; @@ -8,6 +9,7 @@ import nl.jqno.equalsverifier.internal.prefabvalues.PrefabValues; import nl.jqno.equalsverifier.internal.prefabvalues.TypeTag; import nl.jqno.equalsverifier.internal.reflection.ClassAccessor; +import nl.jqno.equalsverifier.internal.reflection.annotations.Annotation; import nl.jqno.equalsverifier.internal.reflection.annotations.AnnotationCache; import nl.jqno.equalsverifier.internal.reflection.annotations.AnnotationCacheBuilder; import nl.jqno.equalsverifier.internal.reflection.annotations.SupportedAnnotations; @@ -129,29 +131,23 @@ private static Set determineIgnoredFields( Set includedFields, Set actualFields) { + BiFunction fieldHas = + (f, a) -> annotationCache.hasFieldAnnotation(type, f, a); + if (annotationCache.hasClassAnnotation(type, SupportedAnnotations.NATURALID)) { return actualFields.stream() - .filter( - f -> - !annotationCache.hasFieldAnnotation( - type, f, SupportedAnnotations.NATURALID)) + .filter(f -> !fieldHas.apply(f, SupportedAnnotations.NATURALID)) .collect(Collectors.toSet()); } if (annotationCache.hasClassAnnotation(type, SupportedAnnotations.ID)) { if (warningsToSuppress.contains(Warning.SURROGATE_KEY)) { return actualFields.stream() - .filter( - f -> - !annotationCache.hasFieldAnnotation( - type, f, SupportedAnnotations.ID)) + .filter(f -> !fieldHas.apply(f, SupportedAnnotations.ID)) .collect(Collectors.toSet()); } else { Set ignored = actualFields.stream() - .filter( - f -> - annotationCache.hasFieldAnnotation( - type, f, SupportedAnnotations.ID)) + .filter(f -> fieldHas.apply(f, SupportedAnnotations.ID)) .collect(Collectors.toSet()); ignored.addAll( determineAnnotationlessIgnoredFields( diff --git a/src/main/java/nl/jqno/equalsverifier/internal/util/Validations.java b/src/main/java/nl/jqno/equalsverifier/internal/util/Validations.java index 952db5f75..2337d7988 100644 --- a/src/main/java/nl/jqno/equalsverifier/internal/util/Validations.java +++ b/src/main/java/nl/jqno/equalsverifier/internal/util/Validations.java @@ -71,14 +71,14 @@ public static void validateGenericPrefabValues( validateNotNull(type, "type is null."); int n = type.getTypeParameters().length; - validate( - n != arity, + String message = "number of generic type parameters doesn't match:\n " + type.getName() + " has " + n + "\n Factory has " - + arity); + + arity; + validate(n != arity, message); } public static void validateWarningsAndFields( @@ -169,12 +169,12 @@ public static void validatePackageContainsClasses(String packageName, List> types, List> knownTypes) { List> unknownTypes = types.stream().filter(t -> !knownTypes.contains(t)).collect(Collectors.toList()); - validate( - !unknownTypes.isEmpty(), + String message = "Unknown class(es) found: " + unknownTypes.stream() .map(t -> t.getCanonicalName()) - .collect(Collectors.joining(", "))); + .collect(Collectors.joining(", ")); + validate(!unknownTypes.isEmpty(), message); } public static void validateNotNull(Object object, String errormessage) {