Skip to content

Commit

Permalink
Fix build, simplify some rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 committed Sep 2, 2023
1 parent a0262c7 commit 42d6707
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public final class RefasterParameterOrder extends BugChecker implements ClassTre
private static final Matcher<Tree> BEFORE_OR_AFTER_TEMPLATE_METHOD =
anyOf(BEFORE_TEMPLATE_METHOD, hasAnnotation(AfterTemplate.class));

/** Instantiates a new {@link RefasterParameterOrder} instance. */
public RefasterParameterOrder() {}

@Override
public Description matchClass(ClassTree tree, VisitorState state) {
ImmutableList<MethodTree> methods = getMethodsByPriority(tree, state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,23 +157,13 @@ Predicate<T> after() {
}

/** Avoid contrived ways of handling {@code null} values during equality testing. */
static final class EqualsLhsNullable<T, S> {
@BeforeTemplate
boolean before(S value2, T value1) {
return Optional.ofNullable(value1).equals(Optional.of(value2));
}

@AfterTemplate
boolean after(S value2, T value1) {
return value2.equals(value1);
}
}

/** Avoid contrived ways of handling {@code null} values during equality testing. */
static final class EqualsRhsNullable<T, S> {
static final class Equals<T, S> {
@BeforeTemplate
boolean before(T value1, S value2) {
return Optional.of(value1).equals(Optional.ofNullable(value2));
return Refaster.anyOf(
Optional.of(value1).equals(Optional.of(value2)),
Optional.of(value1).equals(Optional.ofNullable(value2)),
Optional.ofNullable(value2).equals(Optional.of(value1)));
}

@AfterTemplate
Expand All @@ -183,7 +173,7 @@ boolean after(T value1, S value2) {
}

/** Avoid contrived ways of handling {@code null} values during equality testing. */
static final class EqualsLhsAndRhsNullable<T, S> {
static final class ObjectsEquals<T, S> {
@BeforeTemplate
boolean before(T value1, S value2) {
return Optional.ofNullable(value1).equals(Optional.ofNullable(value2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,14 @@ Predicate<String> testPredicateLambda() {
return not(v -> v.isEmpty());
}

boolean testEqualsLhsNullable() {
return Optional.ofNullable("foo").equals(Optional.of("bar"));
}

boolean testEqualsRhsNullable() {
return Optional.of("foo").equals(Optional.ofNullable("bar"));
ImmutableSet<Boolean> testEquals() {
return ImmutableSet.of(
Optional.of("foo").equals(Optional.of("bar")),
Optional.of("baz").equals(Optional.ofNullable("qux")),
Optional.ofNullable("quux").equals(Optional.of("quuz")));
}

boolean testEqualsLhsAndRhsNullable() {
boolean testObjectsEquals() {
return Optional.ofNullable("foo").equals(Optional.ofNullable("bar"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,11 @@ Predicate<String> testPredicateLambda() {
return v -> !v.isEmpty();
}

boolean testEqualsLhsNullable() {
return "bar".equals("foo");
ImmutableSet<Boolean> testEquals() {
return ImmutableSet.of("foo".equals("bar"), "baz".equals("qux"), "quuz".equals("quux"));
}

boolean testEqualsRhsNullable() {
return "foo".equals("bar");
}

boolean testEqualsLhsAndRhsNullable() {
boolean testObjectsEquals() {
return Objects.equals("foo", "bar");
}
}

0 comments on commit 42d6707

Please sign in to comment.