Skip to content

Commit

Permalink
Add precondition for better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
sambsnyd committed Jul 11, 2023
1 parent fae9ab1 commit 92576cc
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@

import lombok.EqualsAndHashCode;
import lombok.Value;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Option;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.*;
import org.openrewrite.internal.StringUtils;
import org.openrewrite.java.ChangeMethodName;
import org.openrewrite.java.JavaIsoVisitor;
import org.openrewrite.java.MethodMatcher;
import org.openrewrite.java.search.UsesMethod;
import org.openrewrite.java.tree.Expression;
import org.openrewrite.java.tree.J;

Expand Down Expand Up @@ -73,8 +71,8 @@ public enum Level {
@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
String methodPattern = "org.slf4j.Logger " + from.name().toLowerCase() + "(..)";
MethodMatcher logMatcher = new MethodMatcher(methodPattern);
return new JavaIsoVisitor<ExecutionContext>() {
return Preconditions.check(new UsesMethod<>(methodPattern), new JavaIsoVisitor<ExecutionContext>() {
final MethodMatcher logMatcher = new MethodMatcher(methodPattern);
@Override
public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {
J.MethodInvocation m = super.visitMethodInvocation(method, ctx);
Expand All @@ -101,6 +99,6 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
.visitNonNull(m, ctx);
return m;
}
};
});
}
}

0 comments on commit 92576cc

Please sign in to comment.