Skip to content

Commit

Permalink
Cleans up awkwardly auto-formatted code
Browse files Browse the repository at this point in the history
  • Loading branch information
jqno committed Jun 14, 2020
1 parent ad82e84 commit d698561
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ private <S> 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.
Expand All @@ -112,10 +112,10 @@ private <S> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ public class HierarchyChecker<T> implements Checker {
public HierarchyChecker(Configuration<T> 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."));
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public static <A, B, T> PrefabValueFactory<T> simple(

public static <A, T extends Collection<A>> PrefabValueFactory<T> collection(
Supplier<T> emptyFactory) {
return Factories.<A, T>simple(
Func1<A, T> f =
a -> {
T coll = emptyFactory.get();
coll.add(a);
return coll;
},
emptyFactory);
};
return Factories.<A, T>simple(f, emptyFactory);
}

public static <T, S> PrefabValueFactory<T> copy(Class<S> source, Function<S, T> copy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -115,13 +116,10 @@ public Tuple<T> createValues(
@SuppressWarnings("unchecked")
private static <T, S> PrefabValueFactory<T> fxCollection(
Class<S> source, String copyMethodName) {
return copy(
source,
a -> {
ConditionalInstantiator ci =
new ConditionalInstantiator(
JAVAFX_COLLECTIONS_PACKAGE + "FXCollections");
return ci.callFactory(copyMethodName, classes(source), objects(a));
});
Function<S, T> f =
a ->
new ConditionalInstantiator(JAVAFX_COLLECTIONS_PACKAGE + "FXCollections")
.callFactory(copyMethodName, classes(source), objects(a));
return copy(source, f);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit d698561

Please sign in to comment.