Skip to content

Instantly share code, notes, and snippets.

@mike-solomon
Created July 26, 2024 17:15
Show Gist options
  • Save mike-solomon/3b49a5d19c8824776bcc4ee871b87cdd to your computer and use it in GitHub Desktop.
Save mike-solomon/3b49a5d19c8824776bcc4ee871b87cdd to your computer and use it in GitHub Desktop.
package com.yourorg;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Preconditions;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.internal.lang.NonNullApi;
import org.openrewrite.java.JavaIsoVisitor;
import org.openrewrite.java.MethodMatcher;
import org.openrewrite.java.search.UsesMethod;
import org.openrewrite.java.tree.J;
import org.openrewrite.marker.SearchResult;
@NonNullApi
public class FindSysOutPrint extends Recipe {
@Override
public String getDisplayName() {
return "My recipe";
}
@Override
public String getDescription() {
return "This is a description of what the recipe does.";
}
@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
MethodMatcher matcher = new MethodMatcher("java.io.PrintStream#println(java.lang.String)");
return Preconditions.check(new UsesMethod<>(matcher), new JavaIsoVisitor<ExecutionContext>() {
@Override
public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {
if (matcher.matches(method)) {
// TODO do something other than just mark the method as found?
return SearchResult.found(method);
}
return super.visitMethodInvocation(method, ctx);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
OSZAR »