Skip to content

Commit

Permalink
Use MethodAccess Trait to evaluate if argument is false
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Nov 28, 2024
1 parent 058a8c1 commit b5efd9a
Showing 1 changed file with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.openrewrite.*;
import org.openrewrite.java.*;
import org.openrewrite.java.search.UsesMethod;
import org.openrewrite.java.trait.Traits;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.Statement;
import org.openrewrite.java.tree.TypeUtils;
Expand Down Expand Up @@ -56,19 +57,13 @@ public String getDescription() {

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {

return Preconditions.check(
Preconditions.and(
new UsesMethod<>(MATCHER_STALE_CHECK_ENABLED),
new JavaIsoVisitor<ExecutionContext>() {
@Override
public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {
if (MATCHER_STALE_CHECK_ENABLED.matches(method) &&
J.Literal.isLiteralValue(method.getArguments().get(0), false)) {
return SearchResult.found(method);
}
return super.visitMethodInvocation(method, ctx);
}
}
Traits.methodAccess(MATCHER_STALE_CHECK_ENABLED).asVisitor(access ->
J.Literal.isLiteralValue(access.getTree().getArguments().get(0), false) ?
SearchResult.found(access.getTree()) : access.getTree())
), new MigrateRequestConfigVisitor());
}

Expand Down

0 comments on commit b5efd9a

Please sign in to comment.