Skip to content

Commit

Permalink
Loosen the restrictions in TruthSelfEquals to allow anything called `…
Browse files Browse the repository at this point in the history
…assertThat`, not just the Truth ones.

That way, we catch `ProtoTruth` too.

PiperOrigin-RevId: 579776612
  • Loading branch information
graememorgan authored and Error Prone Team committed Nov 8, 2023
1 parent dfba048 commit 123e584
Showing 1 changed file with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,17 @@ public final class TruthSelfEquals extends BugChecker implements MethodInvocatio

private static final Matcher<MethodInvocationTree> EQUALS_MATCHER =
allOf(
instanceMethod()
.onDescendantOf("com.google.common.truth.Subject")
.namedAnyOf("isEqualTo", "isSameInstanceAs")
.withParameters("java.lang.Object"),
instanceMethod().anyClass().namedAnyOf("isEqualTo", "isSameInstanceAs"),
TruthSelfEquals::receiverSameAsParentsArgument);

private static final Matcher<MethodInvocationTree> NOT_EQUALS_MATCHER =
allOf(
instanceMethod()
.onDescendantOf("com.google.common.truth.Subject")
.namedAnyOf("isNotEqualTo", "isNotSameInstanceAs")
.withParameters("java.lang.Object"),
instanceMethod().anyClass().namedAnyOf("isNotEqualTo", "isNotSameInstanceAs"),
TruthSelfEquals::receiverSameAsParentsArgument);

private static final Matcher<ExpressionTree> ASSERT_THAT =
anyOf(
staticMethod().onClass("com.google.common.truth.Truth").named("assertThat"),
staticMethod().anyClass().named("assertThat"),
instanceMethod().onDescendantOf("com.google.common.truth.TestVerb").named("that"),
instanceMethod()
.onDescendantOf("com.google.common.truth.StandardSubjectBuilder")
Expand Down

0 comments on commit 123e584

Please sign in to comment.