Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public final class PreferAssertj extends BugChecker implements BugChecker.Method
"junit.framework.TestCase",
"junit.framework.Assert");

// Must match everything otherwise matched by this check, used to avoid
// additional checks for each method invocation.
private static final Matcher<ExpressionTree> FAST_CHECK = MethodMatchers.staticMethod()
.onClassAny(LEGACY_ASSERT_CLASSES);

private static final Matcher<ExpressionTree> ASSERT_TRUE =
MethodMatchers.staticMethod()
.onClassAny(LEGACY_ASSERT_CLASSES)
Expand Down Expand Up @@ -223,6 +228,11 @@ public final class PreferAssertj extends BugChecker implements BugChecker.Method
@Override
@SuppressWarnings({"CyclomaticComplexity", "MethodLength"})
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
// We check a lot of methods, the fast check allows us to quickly rule out most invocations
// without individually checking each of the more specific patterns.
if (!FAST_CHECK.matches(tree, state)) {
return Description.NO_MATCH;
}
if (ASSERT_TRUE.matches(tree, state)) {
return withAssertThat(tree, state, 0, (assertThat, fix) -> fix.replace(tree, assertThat + ".isTrue()"));
}
Expand Down
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-875.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Improve performannce of error prone PreferAssertj check
links:
- https://github.com/palantir/gradle-baseline/pull/875